use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec in project SQLWindowing by hbutani.
the class WindowSpecTranslation method translateWindowFrame.
static WindowFrameDef translateWindowFrame(QueryDef qDef, WindowFrameSpec wfSpec, InputInfo iInfo) throws WindowingException {
if (wfSpec == null) {
return null;
}
BoundarySpec s = wfSpec.getStart();
BoundarySpec e = wfSpec.getEnd();
WindowFrameDef wfDef = new WindowFrameDef(wfSpec);
wfDef.setStart(translateBoundary(qDef, s, iInfo));
wfDef.setEnd(translateBoundary(qDef, e, iInfo));
int cmp = s.compareTo(e);
if (cmp > 0) {
throw new WindowingException(sprintf("Window range invalid, start boundary is greater than end boundary: %s", wfSpec));
}
return wfDef;
}
use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec 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.BoundarySpec in project SQLWindowing by hbutani.
the class QSpecBuilder2 method window_value_expression.
// $ANTLR end rowsboundary
// $ANTLR start window_value_expression
// QSpecBuilder2.g:199:1: window_value_expression returns [WindowFrameSpec wf] : ^( WINDOWVALUES s= valuesboundary e= valuesboundary ) ;
public final WindowFrameSpec window_value_expression() throws RecognitionException {
WindowFrameSpec wf = null;
BoundarySpec s = null;
BoundarySpec e = null;
try {
// QSpecBuilder2.g:199:54: ( ^( WINDOWVALUES s= valuesboundary e= valuesboundary ) )
// QSpecBuilder2.g:200:2: ^( WINDOWVALUES s= valuesboundary e= valuesboundary )
{
match(input, WINDOWVALUES, FOLLOW_WINDOWVALUES_in_window_value_expression939);
if (failed)
return wf;
match(input, Token.DOWN, null);
if (failed)
return wf;
pushFollow(FOLLOW_valuesboundary_in_window_value_expression943);
s = valuesboundary();
_fsp--;
if (failed)
return wf;
pushFollow(FOLLOW_valuesboundary_in_window_value_expression947);
e = valuesboundary();
_fsp--;
if (failed)
return wf;
match(input, Token.UP, null);
if (failed)
return wf;
if (backtracking == 0) {
wf = new WindowFrameSpec(s, e);
}
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
} finally {
}
return wf;
}
use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec 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;
}
use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec in project SQLWindowing by hbutani.
the class QSpecBuilder2 method window_range_expression.
// $ANTLR end window_frame
// $ANTLR start window_range_expression
// QSpecBuilder2.g:182:1: window_range_expression returns [WindowFrameSpec wf] : ^( WINDOWRANGE s= rowsboundary e= rowsboundary ) ;
public final WindowFrameSpec window_range_expression() throws RecognitionException {
WindowFrameSpec wf = null;
BoundarySpec s = null;
BoundarySpec e = null;
try {
// QSpecBuilder2.g:182:54: ( ^( WINDOWRANGE s= rowsboundary e= rowsboundary ) )
// QSpecBuilder2.g:183:2: ^( WINDOWRANGE s= rowsboundary e= rowsboundary )
{
match(input, WINDOWRANGE, FOLLOW_WINDOWRANGE_in_window_range_expression835);
if (failed)
return wf;
match(input, Token.DOWN, null);
if (failed)
return wf;
pushFollow(FOLLOW_rowsboundary_in_window_range_expression839);
s = rowsboundary();
_fsp--;
if (failed)
return wf;
pushFollow(FOLLOW_rowsboundary_in_window_range_expression843);
e = rowsboundary();
_fsp--;
if (failed)
return wf;
match(input, Token.UP, null);
if (failed)
return wf;
if (backtracking == 0) {
wf = new WindowFrameSpec(s, e);
}
}
} catch (RecognitionException re) {
reportError(re);
recover(input, re);
} finally {
}
return wf;
}
Aggregations