use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserWindowingSpec.WindowFunctionSpec in project flink by apache.
the class HiveParserSemanticAnalyzer method doPhase1GetAggregationsFromSelect.
private LinkedHashMap<String, HiveParserASTNode> doPhase1GetAggregationsFromSelect(HiveParserASTNode selExpr, HiveParserQB qb, String dest) throws SemanticException {
// Iterate over the selects search for aggregation Trees.
// Use String as keys to eliminate duplicate trees.
LinkedHashMap<String, HiveParserASTNode> aggregationTrees = new LinkedHashMap<>();
List<HiveParserASTNode> wdwFns = new ArrayList<>();
for (int i = 0; i < selExpr.getChildCount(); ++i) {
HiveParserASTNode function = (HiveParserASTNode) selExpr.getChild(i);
if (function.getType() == HiveASTParser.TOK_SELEXPR || function.getType() == HiveASTParser.TOK_SUBQUERY_EXPR) {
function = (HiveParserASTNode) function.getChild(0);
}
doPhase1GetAllAggregations(function, aggregationTrees, wdwFns);
}
// window based aggregations are handled differently
for (HiveParserASTNode wdwFn : wdwFns) {
HiveParserWindowingSpec spec = qb.getWindowingSpec(dest);
if (spec == null) {
queryProperties.setHasWindowing(true);
spec = new HiveParserWindowingSpec();
qb.addDestToWindowingSpec(dest, spec);
}
HashMap<String, HiveParserASTNode> wExprsInDest = qb.getParseInfo().getWindowingExprsForClause(dest);
int wColIdx = spec.getWindowExpressions() == null ? 0 : spec.getWindowExpressions().size();
WindowFunctionSpec wFnSpec = processWindowFunction(wdwFn, (HiveParserASTNode) wdwFn.getChild(wdwFn.getChildCount() - 1));
// HiveParserWindowingSpec.
if (wExprsInDest != null && wExprsInDest.containsKey(wFnSpec.getExpression().toStringTree())) {
continue;
}
wFnSpec.setAlias(wFnSpec.getName() + "_window_" + wColIdx);
spec.addWindowFunction(wFnSpec);
qb.getParseInfo().addWindowingExprToClause(dest, wFnSpec.getExpression());
}
return aggregationTrees;
}
Aggregations