Search in sources :

Example 1 with WindowFrameSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec 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;
}
Also used : WindowFrameDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef) WindowingException(com.sap.hadoop.windowing.WindowingException) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec) BoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec)

Example 2 with WindowFrameSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec 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;
}
Also used : BoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)

Example 3 with WindowFrameSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec in project SQLWindowing by hbutani.

the class WindowSpecTranslation method translateWindowSpecOnInput.

/*
	 * <ol>
	 * <li> If wSpec points to a source WindowSpec. Validate that it is valid. If it hasn't been already translated then translate it.
	 * <li> Start with an empty WdwDef or a cloned WdwDef from the source WdwDef.
	 * <li> translate the PartitionSpec if it exists. Replace the existing PDef with this; also remove the OrderDef.
	 * <li> translate the OrderSpec if it exists. Replace existing OrderDef with this.
	 * <li> add in Partition Columns if not in OrderDef already.
	 * <li> translate the WindowSpec if it exists. Replace existing WdwDef with it.
	 * <li> If name is non-null add this def to TranslationInfo::nameToWdwDef map.
	 * </ol>
	 */
static WindowDef translateWindowSpecOnInput(QueryDef qDef, WindowSpec wSpec, InputInfo iInfo, String inputDesc) throws WindowingException {
    QuerySpec qSpec = qDef.getSpec();
    WindowDef wDef;
    fillInWindowSpec(qSpec, wSpec.getSourceId(), wSpec);
    wDef = new WindowDef(wSpec);
    PartitionSpec pSpec = wSpec.getPartition();
    OrderSpec oSpec = wSpec.getOrder();
    WindowFrameSpec wFrameSpec = wSpec.getWindow();
    PartitionDef pDef = translatePartition(qDef, iInfo, pSpec);
    OrderDef oDef = translateOrder(qDef, inputDesc, iInfo, oSpec, pDef);
    WindowFrameDef wdwDef = translateWindowFrame(qDef, wFrameSpec, iInfo);
    wDef.setPartDef(pDef);
    wDef.setOrderDef(oDef);
    wDef.setWindow(wdwDef);
    return wDef;
}
Also used : OrderSpec(com.sap.hadoop.windowing.query2.specification.OrderSpec) WindowFrameDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef) WindowDef(com.sap.hadoop.windowing.query2.definition.WindowDef) PartitionDef(com.sap.hadoop.windowing.query2.definition.PartitionDef) QuerySpec(com.sap.hadoop.windowing.query2.specification.QuerySpec) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef) PartitionSpec(com.sap.hadoop.windowing.query2.specification.PartitionSpec) WindowFrameSpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec)

Example 4 with WindowFrameSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFrameSpec 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;
}
Also used : BoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)

Aggregations

BoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec)3 RangeBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)3 ValueBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec)3 WindowFrameDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)1 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)1 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)1 OrderSpec (com.sap.hadoop.windowing.query2.specification.OrderSpec)1 PartitionSpec (com.sap.hadoop.windowing.query2.specification.PartitionSpec)1 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)1 WindowFrameSpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec)1