Search in sources :

Example 1 with RangeBoundaryDef

use of com.sap.hadoop.windowing.query2.definition.WindowFrameDef.RangeBoundaryDef 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);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) WindowingException(com.sap.hadoop.windowing.WindowingException) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) CurrentRowSpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.CurrentRowSpec) ValueBoundaryDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef.ValueBoundaryDef) RangeBoundaryDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef.RangeBoundaryDef) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec) CurrentRowDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef.CurrentRowDef)

Example 2 with RangeBoundaryDef

use of com.sap.hadoop.windowing.query2.definition.WindowFrameDef.RangeBoundaryDef in project SQLWindowing by hbutani.

the class LocalExecutorTests method testWindowClause.

@Test
public void testWindowClause() throws WindowingException {
    QueryDef qDef = wshell.translate("select  p_mfgr,p_name, p_size, " + "sum(p_size) over w1 as s, " + " denserank() as dr " + " from part_demo " + " partition by p_mfgr" + " window w1 as rows between 2 preceding and 2 following" + " into path='/tmp/wout2'" + " serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'" + " with serdeproperties('field.delim'=',')" + " format 'org.apache.hadoop.mapred.TextOutputFormat'");
    RangeBoundaryDef rBdef = (RangeBoundaryDef) qDef.getSelectList().getWindowFuncs().get(0).getWindow().getWindow().getStart();
    assert rBdef.getAmt() == 2;
    rBdef = (RangeBoundaryDef) qDef.getSelectList().getWindowFuncs().get(0).getWindow().getWindow().getEnd();
    assert rBdef.getAmt() == 2;
}
Also used : QueryDef(com.sap.hadoop.windowing.query2.definition.QueryDef) RangeBoundaryDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef.RangeBoundaryDef) Test(org.junit.Test) LocalExecutorTest(com.sap.hadoop.windowing.testutils.LocalExecutorTest)

Aggregations

RangeBoundaryDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef.RangeBoundaryDef)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)1 CurrentRowDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef.CurrentRowDef)1 ValueBoundaryDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef.ValueBoundaryDef)1 CurrentRowSpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.CurrentRowSpec)1 RangeBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)1 ValueBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec)1 LocalExecutorTest (com.sap.hadoop.windowing.testutils.LocalExecutorTest)1 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 Test (org.junit.Test)1