Search in sources :

Example 1 with WindowFrameSpec

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

the class SemanticAnalyzer method processWindowFrame.

private WindowFrameSpec processWindowFrame(ASTNode node) throws SemanticException {
    int type = node.getType();
    BoundarySpec end = null;
    /*
     * A WindowFrame may contain just the Start Boundary or in the
     * between style of expressing a WindowFrame both boundaries
     * are specified.
     */
    BoundarySpec start = processBoundary((ASTNode) node.getChild(0));
    if (node.getChildCount() > 1) {
        end = processBoundary((ASTNode) node.getChild(1));
    }
    // Note: TOK_WINDOWVALUES means RANGE type, TOK_WINDOWRANGE means ROWS type
    return new WindowFrameSpec(type == HiveParser.TOK_WINDOWVALUES ? WindowType.RANGE : WindowType.ROWS, start, end);
}
Also used : BoundarySpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) 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) WindowFrameSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)

Example 2 with WindowFrameSpec

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

the class ExprNodeConverter method visitOver.

@Override
public ExprNodeDesc visitOver(RexOver over) {
    if (!deep) {
        return null;
    }
    final RexWindow window = over.getWindow();
    final WindowSpec windowSpec = new WindowSpec();
    final PartitioningSpec partitioningSpec = getPSpec(window);
    windowSpec.setPartitioning(partitioningSpec);
    final WindowFrameSpec windowFrameSpec = getWindowRange(window);
    windowSpec.setWindowFrame(windowFrameSpec);
    WindowFunctionSpec wfs = new WindowFunctionSpec();
    wfs.setWindowSpec(windowSpec);
    final Schema schema = new Schema(tabAlias, inputRowType.getFieldList());
    final ASTNode wUDAFAst = new ASTConverter.RexVisitor(schema).visitOver(over);
    wfs.setExpression(wUDAFAst);
    ASTNode nameNode = (ASTNode) wUDAFAst.getChild(0);
    wfs.setName(nameNode.getText());
    for (int i = 1; i < wUDAFAst.getChildCount() - 1; i++) {
        ASTNode child = (ASTNode) wUDAFAst.getChild(i);
        wfs.addArg(child);
    }
    if (wUDAFAst.getText().equals("TOK_FUNCTIONSTAR")) {
        wfs.setStar(true);
    }
    String columnAlias = getWindowColumnAlias();
    wfs.setAlias(columnAlias);
    this.windowFunctionSpecs.add(wfs);
    return new ExprNodeColumnDesc(TypeConverter.convert(over.getType()), columnAlias, tabAlias, false);
}
Also used : RexVisitor(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.RexVisitor) Schema(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.Schema) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) WindowFunctionSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFunctionSpec) RexWindow(org.apache.calcite.rex.RexWindow) DateString(org.apache.calcite.util.DateString) ByteString(org.apache.calcite.avatica.util.ByteString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString) NlsString(org.apache.calcite.util.NlsString) WindowSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowSpec) PartitioningSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec) WindowFrameSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)

Example 3 with WindowFrameSpec

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

the class ExprNodeConverter method getWindowRange.

private WindowFrameSpec getWindowRange(RexWindow window) {
    // NOTE: in Hive AST Rows->Range(Physical) & Range -> Values (logical)
    BoundarySpec start = null;
    RexWindowBound lb = window.getLowerBound();
    if (lb != null) {
        start = getWindowBound(lb);
    }
    BoundarySpec end = null;
    RexWindowBound ub = window.getUpperBound();
    if (ub != null) {
        end = getWindowBound(ub);
    }
    return new WindowFrameSpec(window.isRows() ? WindowType.ROWS : WindowType.RANGE, start, end);
}
Also used : RexWindowBound(org.apache.calcite.rex.RexWindowBound) BoundarySpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec) WindowFrameSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)

Example 4 with WindowFrameSpec

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

the class SemanticAnalyzer method processWindowSpec.

private WindowSpec processWindowSpec(ASTNode node) throws SemanticException {
    boolean hasSrcId = false, hasPartSpec = false, hasWF = false;
    int srcIdIdx = -1, partIdx = -1, wfIdx = -1;
    for (int i = 0; i < node.getChildCount(); i++) {
        int type = node.getChild(i).getType();
        switch(type) {
            case HiveParser.Identifier:
                hasSrcId = true;
                srcIdIdx = i;
                break;
            case HiveParser.TOK_PARTITIONINGSPEC:
                hasPartSpec = true;
                partIdx = i;
                break;
            case HiveParser.TOK_WINDOWRANGE:
            case HiveParser.TOK_WINDOWVALUES:
                hasWF = true;
                wfIdx = i;
                break;
        }
    }
    WindowSpec ws = new WindowSpec();
    if (hasSrcId) {
        ASTNode nameNode = (ASTNode) node.getChild(srcIdIdx);
        ws.setSourceId(nameNode.getText());
    }
    if (hasPartSpec) {
        ASTNode partNode = (ASTNode) node.getChild(partIdx);
        PartitioningSpec partitioning = processPTFPartitionSpec(partNode);
        ws.setPartitioning(partitioning);
    }
    if (hasWF) {
        ASTNode wfNode = (ASTNode) node.getChild(wfIdx);
        WindowFrameSpec wfSpec = processWindowFrame(wfNode);
        ws.setWindowFrame(wfSpec);
    }
    return ws;
}
Also used : SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) 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) WindowSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowSpec) PartitioningSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec) WindowFrameSpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)

Aggregations

WindowFrameSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)4 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 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)2 PartitioningSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec)2 BoundarySpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec)2 WindowSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowSpec)2 ByteString (org.apache.calcite.avatica.util.ByteString)1 RexWindow (org.apache.calcite.rex.RexWindow)1 RexWindowBound (org.apache.calcite.rex.RexWindowBound)1 DateString (org.apache.calcite.util.DateString)1 NlsString (org.apache.calcite.util.NlsString)1 TimeString (org.apache.calcite.util.TimeString)1 TimestampString (org.apache.calcite.util.TimestampString)1 RexVisitor (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.RexVisitor)1 Schema (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.Schema)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 WindowFunctionSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFunctionSpec)1