use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec 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.ValueBoundarySpec in project SQLWindowing by hbutani.
the class QSpecBuilder2 method valuesboundary.
// $ANTLR end window_value_expression
// $ANTLR start valuesboundary
// QSpecBuilder2.g:203:1: valuesboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( LESS e= expression n= Number ) | ^( MORE e= expression n= Number ) );
public final BoundarySpec valuesboundary() throws RecognitionException {
BoundarySpec bs = null;
CommonTree n = null;
CommonTree e = null;
try {
// QSpecBuilder2.g:203:42: ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( LESS e= expression n= Number ) | ^( MORE e= expression n= Number ) )
int alt38 = 5;
switch(input.LA(1)) {
case PRECEDING:
{
alt38 = 1;
}
break;
case FOLLOWING:
{
alt38 = 2;
}
break;
case CURRENT:
{
alt38 = 3;
}
break;
case LESS:
{
alt38 = 4;
}
break;
case MORE:
{
alt38 = 5;
}
break;
default:
if (backtracking > 0) {
failed = true;
return bs;
}
NoViableAltException nvae = new NoViableAltException("203:1: valuesboundary returns [BoundarySpec bs] : ( ^( PRECEDING UNBOUNDED ) | ^( FOLLOWING UNBOUNDED ) | CURRENT | ^( LESS e= expression n= Number ) | ^( MORE e= expression n= Number ) );", 38, 0, input);
throw nvae;
}
switch(alt38) {
case 1:
// QSpecBuilder2.g:204:3: ^( PRECEDING UNBOUNDED )
{
match(input, PRECEDING, FOLLOW_PRECEDING_in_valuesboundary966);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
match(input, UNBOUNDED, FOLLOW_UNBOUNDED_in_valuesboundary968);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
bs = new ValueBoundarySpec(Direction.PRECEDING, null, BoundarySpec.UNBOUNDED_AMOUNT);
}
}
break;
case 2:
// QSpecBuilder2.g:205:3: ^( FOLLOWING UNBOUNDED )
{
match(input, FOLLOWING, FOLLOW_FOLLOWING_in_valuesboundary979);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
match(input, UNBOUNDED, FOLLOW_UNBOUNDED_in_valuesboundary981);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
bs = new ValueBoundarySpec(Direction.FOLLOWING, null, BoundarySpec.UNBOUNDED_AMOUNT);
}
}
break;
case 3:
// QSpecBuilder2.g:206:3: CURRENT
{
match(input, CURRENT, FOLLOW_CURRENT_in_valuesboundary990);
if (failed)
return bs;
if (backtracking == 0) {
bs = new CurrentRowSpec();
}
}
break;
case 4:
// QSpecBuilder2.g:207:3: ^( LESS e= expression n= Number )
{
match(input, LESS, FOLLOW_LESS_in_valuesboundary999);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
pushFollow(FOLLOW_expression_in_valuesboundary1003);
e = expression();
_fsp--;
if (failed)
return bs;
n = (CommonTree) input.LT(1);
match(input, Number, FOLLOW_Number_in_valuesboundary1007);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
bs = new ValueBoundarySpec(Direction.PRECEDING, e, Integer.parseInt(n.getText()));
}
}
break;
case 5:
// QSpecBuilder2.g:208:3: ^( MORE e= expression n= Number )
{
match(input, MORE, FOLLOW_MORE_in_valuesboundary1017);
if (failed)
return bs;
match(input, Token.DOWN, null);
if (failed)
return bs;
pushFollow(FOLLOW_expression_in_valuesboundary1021);
e = expression();
_fsp--;
if (failed)
return bs;
n = (CommonTree) input.LT(1);
match(input, Number, FOLLOW_Number_in_valuesboundary1025);
if (failed)
return bs;
match(input, Token.UP, null);
if (failed)
return bs;
if (backtracking == 0) {
bs = new ValueBoundarySpec(Direction.PRECEDING, e, Integer.parseInt(n.getText()));
}
}
break;
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
} finally {
}
return bs;
}
Aggregations