Move MaterializedViewQueryOptimizer logic to inner class
@@ -132,7 +132,7 @@ public class MaterializedViewQueryOptimizer
MaterializedViewInformationExtractor materializedViewInformationExtractor = new MaterializedViewInformationExtractor();
materializedViewInformationExtractor.process(materializedViewQuery);
materializedViewInfo = materializedViewInformationExtractor.getMaterializedViewInfo();
- return process(node);
+ return new QuerySpecificationRewriter().process(node);
}
catch (Exception ex) {
logger.warn("Failed to rewrite query with materialized view with following exception: %s", ex.getMessage());
@@ -140,6 +140,9 @@ public class MaterializedViewQueryOptimizer
}
}
+ private class QuerySpecificationRewriter
+ extends AstVisitor<Node, Void>
+ {
@Override
protected Node visitNode(Node node, Void context)
{
@@ -436,18 +439,19 @@ public class MaterializedViewQueryOptimizer
// It must be 1) be selected in the materialized view and 2) not present in GROUP BY node of the materialized view
return groupByOfMaterializedView.contains(expression) || !materializedViewInfo.getBaseToViewColumnMap().containsKey(expression);
}
+
/**
* This is special-cased for now as COUNT is the only non-associative
* function supported by materialized view rewrites. In the future, we will want to
* support more non-associative functions and explore more
* extensible options.
- *
+ * <p>
* Functions in optimized materialized view queries are by default expanded to
* func(column_derived_from_func_in_mv). This only works for associative
* functions. Count is non-associative: COUNT(x \ union y) != COUNT(Count(x), COUNT(y)).
* Rather, COUNT(x \ union y) == SUM(COUNT(x), COUNT(y). This is what we do here.
- * */
- private static FunctionCall rewriteCountAsSum(FunctionCall node, Expression derivedColumnName)
+ */
+ private FunctionCall rewriteCountAsSum(FunctionCall node, Expression derivedColumnName)
{
if (!node.getName().equals(COUNT)) {
throw new SemanticException(NOT_SUPPORTED, node, "Provided function was not COUNT");
@@ -486,3 +490,4 @@ public class MaterializedViewQueryOptimizer
session);
}
}
+}
