Search in sources :

Example 21 with QueryDef

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

the class InputTranslation method translate.

/*
	 * <ol>
	 * <li> Get the <code>TableFunctionResolver</code> for this Function from the FunctionRegistry.
	 * <li> Create the TableFuncDef object.
	 * <li> Get the InputInfo for the input to this function.
	 * <li> Translate the Arguments to this Function in the Context of the InputInfo.
	 * <li> ask the  TableFunctionResolver to create a TableFunctionEvaluator based on the Args passed in.
	 * <li> ask the TableFunctionEvaluator to setup the Map-side ObjectInspector. Gives a chance to functions that 
	 * reshape the Input before it is partitioned to define the Shape after raw data is transformed.
	 * <li> Setup the Window Definition for this Function. The Window Definition is resolved wrt to the InputDef's
	 * Shape or the MapOI, for Functions that reshape the raw input.
	 * <li> ask the TableFunctionEvaluator to setup the Output ObjectInspector for this Function.
	 * <li> setup a Serde for the Output partition based on the OutputOI. 
	 * </ol> 
	 */
private static TableFuncDef translate(QueryDef qDef, TableFuncSpec tSpec, QueryInputDef inputDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    TableFunctionResolver tFn = FunctionRegistry.getTableFunctionResolver(tSpec.getName());
    if (tFn == null) {
        throw new WindowingException(sprintf("Unknown Table Function %s", tSpec.getName()));
    }
    TableFuncDef tDef = new TableFuncDef();
    tDef.setSpec(tSpec);
    tDef.setInput(inputDef);
    InputInfo iInfo = tInfo.getInputInfo(inputDef);
    /*
		 * translate args
		 */
    ArrayList<ASTNode> args = tSpec.getArgs();
    if (args != null) {
        for (ASTNode expr : args) {
            ArgDef argDef = translateTableFunctionArg(qDef, tDef, iInfo, expr);
            tDef.addArg(argDef);
        }
    }
    tFn.initialize(qDef, tDef);
    TableFunctionEvaluator tEval = tFn.getEvaluator();
    tDef.setFunction(tEval);
    tFn.setupRawInputOI();
    tDef.setWindow(WindowSpecTranslation.translateWindow(qDef, tDef));
    tFn.setupOutputOI();
    TranslateUtils.setupSerdeAndOI(tDef, inputDef, tInfo, tEval);
    return tDef;
}
Also used : TableFunctionResolver(com.sap.hadoop.windowing.functions2.TableFunctionResolver) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator) WindowingException(com.sap.hadoop.windowing.WindowingException) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ArgDef(com.sap.hadoop.windowing.query2.definition.ArgDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Example 22 with QueryDef

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

the class InputTranslation method translate.

public static void translate(QueryDef qDef) throws WindowingException {
    QuerySpec spec = qDef.getSpec();
    /*
		 * validate that input chain ends in a Hive Query or TAble.
		 */
    if (!spec.getInput().sourcedFromHive()) {
        throw new WindowingException("Translation not supported for HdfsLocation based queries");
    }
    EnsureTableFunctionInQuery.execute(qDef);
    SlidePartitionAndOrderSpecs.execute(qDef);
    TranslateInputSpecs.execute(qDef);
}
Also used : WindowingException(com.sap.hadoop.windowing.WindowingException) HiveQuerySpec(com.sap.hadoop.windowing.query2.specification.HiveQuerySpec) QuerySpec(com.sap.hadoop.windowing.query2.specification.QuerySpec)

Example 23 with QueryDef

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

the class OutputTranslation method translateSelectExpr.

public static ColumnDef translateSelectExpr(QueryDef qDef, InputInfo iInfo, int colIdx, String alias, ASTNode expr) throws WindowingException {
    ColumnDef cDef = new ColumnDef((ColumnSpec) null);
    ExprNodeDesc exprNode = TranslateUtils.buildExprNode(expr, iInfo.getTypeCheckCtx());
    ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(qDef.getTranslationInfo(), exprNode);
    ObjectInspector oi = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
    cDef.setExpression(expr);
    cDef.setExprNode(exprNode);
    cDef.setExprEvaluator(exprEval);
    cDef.setOI(oi);
    cDef.setAlias(getAlias(alias, expr, colIdx));
    return cDef;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 24 with QueryDef

use of com.sap.hadoop.windowing.query2.definition.QueryDef 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)

Example 25 with QueryDef

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

the class LocalExecutorTests method testAddInOrder.

@Test
public void testAddInOrder() 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'");
    OrderDef oDef = qDef.getInput().getWindow().getOrderDef();
    assert oDef != null;
    assert oDef.getSpec().getColumns().get(0).getColumnName() == "p_mfgr";
}
Also used : OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef) QueryDef(com.sap.hadoop.windowing.query2.definition.QueryDef) Test(org.junit.Test) LocalExecutorTest(com.sap.hadoop.windowing.testutils.LocalExecutorTest)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)15 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)7 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)7 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)7 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)6 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)6 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)5 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)4 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)4 LocalExecutorTest (com.sap.hadoop.windowing.testutils.LocalExecutorTest)4 Test (org.junit.Test)4 HiveQueryDef (com.sap.hadoop.windowing.query2.definition.HiveQueryDef)3 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)3 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)3 ArrayList (java.util.ArrayList)3