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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations