Search in sources :

Example 1 with BoundarySpec

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

the class SemanticAnalyzer method processBoundary.

private BoundarySpec processBoundary(int frameType, ASTNode node) throws SemanticException {
    BoundarySpec bs = new BoundarySpec();
    int type = node.getType();
    boolean hasAmt = true;
    switch(type) {
        case HiveParser.KW_PRECEDING:
            bs.setDirection(Direction.PRECEDING);
            break;
        case HiveParser.KW_FOLLOWING:
            bs.setDirection(Direction.FOLLOWING);
            break;
        case HiveParser.KW_CURRENT:
            bs.setDirection(Direction.CURRENT);
            hasAmt = false;
            break;
    }
    if (hasAmt) {
        ASTNode amtNode = (ASTNode) node.getChild(0);
        if (amtNode.getType() == HiveParser.KW_UNBOUNDED) {
            bs.setAmt(BoundarySpec.UNBOUNDED_AMOUNT);
        } else {
            int amt = Integer.parseInt(amtNode.getText());
            if (amt <= 0) {
                throw new SemanticException("Window Frame Boundary Amount must be a positive integer, provided amount is: " + amt);
            }
            bs.setAmt(amt);
        }
    }
    return bs;
}
Also used : BoundarySpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec) 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) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)

Example 2 with BoundarySpec

use of org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec 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 3 with BoundarySpec

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

the class SemanticAnalyzer method processBoundary.

private BoundarySpec processBoundary(ASTNode node) throws SemanticException {
    BoundarySpec bs = new BoundarySpec();
    int type = node.getType();
    boolean hasAmt = true;
    switch(type) {
        case HiveParser.KW_PRECEDING:
            bs.setDirection(Direction.PRECEDING);
            break;
        case HiveParser.KW_FOLLOWING:
            bs.setDirection(Direction.FOLLOWING);
            break;
        case HiveParser.KW_CURRENT:
            bs.setDirection(Direction.CURRENT);
            hasAmt = false;
            break;
        default:
    }
    if (hasAmt) {
        ASTNode amtNode = (ASTNode) node.getChild(0);
        if (amtNode.getType() == HiveParser.KW_UNBOUNDED) {
            bs.setAmt(BoundarySpec.UNBOUNDED_AMOUNT);
        } else {
            int amt = Integer.parseInt(amtNode.getText());
            if (amt < 0) {
                throw new SemanticException("Window Frame Boundary Amount must be a non-negative integer, provided amount is: " + amt);
            } else if (amt == 0) {
                // Convert 0 PRECEDING/FOLLOWING to CURRENT ROW
                LOG.info("Converting 0 {} to CURRENT ROW", bs.getDirection());
                bs.setDirection(Direction.CURRENT);
                hasAmt = false;
            } else {
                bs.setAmt(amt);
            }
        }
    }
    return bs;
}
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) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)

Example 4 with BoundarySpec

use of org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec 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 5 with BoundarySpec

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

the class ExprNodeConverter method getWindowBound.

private BoundarySpec getWindowBound(RexWindowBound wb) {
    BoundarySpec boundarySpec;
    if (wb.isCurrentRow()) {
        boundarySpec = new BoundarySpec(Direction.CURRENT);
    } else {
        final Direction direction;
        final int amt;
        if (wb.isPreceding()) {
            direction = Direction.PRECEDING;
        } else {
            direction = Direction.FOLLOWING;
        }
        if (wb.isUnbounded()) {
            amt = BoundarySpec.UNBOUNDED_AMOUNT;
        } else {
            amt = RexLiteral.intValue(wb.getOffset());
        }
        boundarySpec = new BoundarySpec(direction, amt);
    }
    return boundarySpec;
}
Also used : BoundarySpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec) Direction(org.apache.hadoop.hive.ql.parse.WindowingSpec.Direction)

Aggregations

BoundarySpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec)7 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)3 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)3 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)3 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)3 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)3 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)2 WindowFrameSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowFrameSpec)2 WindowFrameDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef)2 RexWindowBound (org.apache.calcite.rex.RexWindowBound)1 WindowFunctionInfo (org.apache.hadoop.hive.ql.exec.WindowFunctionInfo)1 CheckConstraint (org.apache.hadoop.hive.ql.metadata.CheckConstraint)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)1 Direction (org.apache.hadoop.hive.ql.parse.WindowingSpec.Direction)1 WindowSpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.WindowSpec)1 BoundaryDef (org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef)1 PTFExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef)1 ShapeDetails (org.apache.hadoop.hive.ql.plan.ptf.ShapeDetails)1 WindowFunctionDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFunctionDef)1