Search in sources :

Example 6 with WindowFunctionSpec

use of org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFunctionSpec in project hive by apache.

the class SemanticAnalyzer method doPhase1GetAggregationsFromSelect.

private LinkedHashMap<String, ASTNode> doPhase1GetAggregationsFromSelect(ASTNode selExpr, QB qb, String dest) throws SemanticException {
    // Iterate over the selects search for aggregation Trees.
    // Use String as keys to eliminate duplicate trees.
    LinkedHashMap<String, ASTNode> aggregationTrees = new LinkedHashMap<String, ASTNode>();
    List<ASTNode> wdwFns = new ArrayList<ASTNode>();
    for (int i = 0; i < selExpr.getChildCount(); ++i) {
        ASTNode function = (ASTNode) selExpr.getChild(i);
        if (function.getType() == HiveParser.TOK_SELEXPR || function.getType() == HiveParser.TOK_SUBQUERY_EXPR) {
            function = (ASTNode) function.getChild(0);
        }
        doPhase1GetAllAggregations(function, aggregationTrees, wdwFns, null);
    }
    // window based aggregations are handled differently
    for (ASTNode wdwFn : wdwFns) {
        WindowingSpec spec = qb.getWindowingSpec(dest);
        if (spec == null) {
            queryProperties.setHasWindowing(true);
            spec = new WindowingSpec();
            qb.addDestToWindowingSpec(dest, spec);
        }
        HashMap<String, ASTNode> wExprsInDest = qb.getParseInfo().getWindowingExprsForClause(dest);
        int wColIdx = spec.getWindowExpressions() == null ? 0 : spec.getWindowExpressions().size();
        WindowFunctionSpec wFnSpec = processWindowFunction(wdwFn, (ASTNode) wdwFn.getChild(wdwFn.getChildCount() - 1));
        // If this is a duplicate invocation of a function; don't add to WindowingSpec.
        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.hadoop.hive.ql.parse.WindowingSpec.WindowFunctionSpec) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) CheckConstraint(org.apache.hadoop.hive.ql.metadata.CheckConstraint) NotNullConstraint(org.apache.hadoop.hive.ql.metadata.NotNullConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) DefaultConstraint(org.apache.hadoop.hive.ql.metadata.DefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

WindowFunctionSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFunctionSpec)6 ArrayList (java.util.ArrayList)3 PartitioningSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec)3 LinkedHashMap (java.util.LinkedHashMap)2 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)2 CheckConstraint (org.apache.hadoop.hive.ql.metadata.CheckConstraint)2 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)2 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)2 WindowExpressionSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowExpressionSpec)2 WindowSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowSpec)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 RexWindow (org.apache.calcite.rex.RexWindow)1 DateString (org.apache.calcite.util.DateString)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1