use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec in project SQLWindowing by hbutani.
the class WindowSpecTranslation method translateBoundary.
static BoundaryDef translateBoundary(QueryDef qDef, BoundarySpec bndSpec, InputInfo iInfo) throws WindowingException {
if (bndSpec instanceof ValueBoundarySpec) {
ValueBoundarySpec vBndSpec = (ValueBoundarySpec) bndSpec;
ValueBoundaryDef vbDef = new ValueBoundaryDef(vBndSpec);
TranslateUtils.validateNoLeadLagInValueBoundarySpec(vBndSpec.getExpression());
ExprNodeDesc exprNode = TranslateUtils.buildExprNode(vBndSpec.getExpression(), iInfo.getTypeCheckCtx());
vbDef.setExprNode(exprNode);
ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(qDef.getTranslationInfo(), exprNode);
ObjectInspector OI = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
TranslateUtils.validateValueBoundaryExprType(OI);
vbDef.setExprEvaluator(exprEval);
vbDef.setOI(OI);
return vbDef;
} else if (bndSpec instanceof RangeBoundarySpec) {
RangeBoundarySpec rBndSpec = (RangeBoundarySpec) bndSpec;
RangeBoundaryDef rbDef = new RangeBoundaryDef(rBndSpec);
return rbDef;
} else if (bndSpec instanceof CurrentRowSpec) {
CurrentRowSpec cBndSpec = (CurrentRowSpec) bndSpec;
CurrentRowDef cbDef = new CurrentRowDef(cBndSpec);
return cbDef;
}
throw new WindowingException("Unknown Boundary: " + bndSpec);
}
use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec in project SQLWindowing by hbutani.
the class QSpecBuilder2 method rowsboundary.
// $ANTLR end window_range_expression
// $ANTLR start rowsboundary
// QSpecBuilder2.g:186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );
public final BoundarySpec rowsboundary() throws RecognitionException {
BoundarySpec bs = null;
CommonTree n = null;
RangeBoundarySpec rbs = new RangeBoundarySpec();
bs = rbs;
try {
// QSpecBuilder2.g:191:3: ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) )
int alt37 = 5;
switch(input.LA(1)) {
case PRECEDING:
{
int LA37_1 = input.LA(2);
if ((LA37_1 == DOWN)) {
int LA37_4 = input.LA(3);
if ((LA37_4 == Number)) {
alt37 = 4;
} else if ((LA37_4 == UNBOUNDED)) {
alt37 = 1;
} else {
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );", 37, 4, input);
throw nvae;
}
} else {
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );", 37, 1, input);
throw nvae;
}
}
break;
case FOLLOWING:
{
int LA37_2 = input.LA(2);
if ((LA37_2 == DOWN)) {
int LA37_5 = input.LA(3);
if ((LA37_5 == Number)) {
alt37 = 5;
} else if ((LA37_5 == UNBOUNDED)) {
alt37 = 2;
} else {
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );", 37, 5, input);
throw nvae;
}
} else {
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );", 37, 2, input);
throw nvae;
}
}
break;
case CURRENT:
{
alt37 = 3;
}
break;
default:
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("186:1: rowsboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( PRECEDING n= Number ) | ^( FOLLOWING n= Number ) );", 37, 0, input);
throw nvae;
}
switch(alt37) {
case 1:
// QSpecBuilder2.g:192:3: ^( PRECEDING UNBOUNDED )
{
match(input, PRECEDING, FOLLOW_PRECEDING_in_rowsboundary870);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
match(input, UNBOUNDED, FOLLOW_UNBOUNDED_in_rowsboundary872);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
rbs.setDirection(Direction.PRECEDING);
rbs.setAmt(BoundarySpec.UNBOUNDED_AMOUNT);
}
}
break;
case 2:
// QSpecBuilder2.g:193:3: ^( FOLLOWING UNBOUNDED )
{
match(input, FOLLOWING, FOLLOW_FOLLOWING_in_rowsboundary883);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
match(input, UNBOUNDED, FOLLOW_UNBOUNDED_in_rowsboundary885);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
rbs.setDirection(Direction.FOLLOWING);
rbs.setAmt(BoundarySpec.UNBOUNDED_AMOUNT);
}
}
break;
case 3:
// QSpecBuilder2.g:194:3: CURRENT
{
match(input, CURRENT, FOLLOW_CURRENT_in_rowsboundary894);
if (failed)
return bs;
if (backtracking == 0) {
bs = new CurrentRowSpec();
}
}
break;
case 4:
// QSpecBuilder2.g:195:3: ^( PRECEDING n= Number )
{
match(input, PRECEDING, FOLLOW_PRECEDING_in_rowsboundary903);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
n = (CommonTree) input.LT(1);
match(input, Number, FOLLOW_Number_in_rowsboundary907);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
rbs.setDirection(Direction.PRECEDING);
rbs.setAmt(Integer.parseInt(n.getText()));
}
}
break;
case 5:
// QSpecBuilder2.g:196:3: ^( FOLLOWING n= Number )
{
match(input, FOLLOWING, FOLLOW_FOLLOWING_in_rowsboundary917);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
n = (CommonTree) input.LT(1);
match(input, Number, FOLLOW_Number_in_rowsboundary921);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
rbs.setDirection(Direction.FOLLOWING);
rbs.setAmt(Integer.parseInt(n.getText()));
}
}
break;
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
} finally {
}
return bs;
}
Aggregations