Search in sources :

Example 1 with WindowFunctionSpec

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;
}
Also used : ArrayList(java.util.ArrayList) WindowFunctionSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserWindowingSpec.WindowFunctionSpec) HiveParserBaseSemanticAnalyzer.unescapeSQLString(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unescapeSQLString) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 HiveParserBaseSemanticAnalyzer.unescapeSQLString (org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unescapeSQLString)1 WindowFunctionSpec (org.apache.flink.table.planner.delegation.hive.copy.HiveParserWindowingSpec.WindowFunctionSpec)1