Search in sources :

Example 11 with InputInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo 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 12 with InputInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo 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 13 with InputInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo 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 14 with InputInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo in project SQLWindowing by hbutani.

the class MRUtils method initialize.

/**
	 * Construct the data structures containing ExprNodeDesc for partition
	 * columns and order columns. Use the input definition to construct the list
	 * of output columns for the ReduceSinkOperator
	 * 
	 * @throws WindowingException
	 */
public void initialize() throws WindowingException {
    TableFuncDef tabDef = RuntimeUtils.getFirstTableFunction(qdef);
    hiveTableDef = tabDef.getHiveTableDef();
    InputInfo inputInfo;
    ArrayList<ColumnDef> partColList = tabDef.getWindow().getPartDef().getColumns();
    TableFunctionEvaluator tEval = tabDef.getFunction();
    /*
		 * If the query has a map phase, the inputInfo is retrieved from the map
		 * output info of the table function definition. This is constructed
		 * using the map output oi of the table function definition. If the
		 * query does not have a map phase, the inputInfo is retrieved from the
		 * QueryInputDef (either HiveTableDef or HiveQueryDef) of the query.
		 */
    if (tEval.isTransformsRawInput()) {
        inputInfo = qdef.getTranslationInfo().getMapInputInfo(tabDef);
    } else {
        inputInfo = qdef.getTranslationInfo().getInputInfo(hiveTableDef);
    }
    for (ColumnDef colDef : partColList) {
        partCols.add(colDef.getExprNode());
    }
    ArrayList<OrderColumnDef> orderColList = tabDef.getWindow().getOrderDef().getColumns();
    for (OrderColumnDef colDef : orderColList) {
        Order order = colDef.getOrder();
        if (order.name().equals("ASC")) {
            orderString.append('+');
        } else {
            orderString.append('-');
        }
        orderCols.add(colDef.getExprNode());
        outputColumnNames.add(colDef.getAlias());
    }
    RowResolver rr = inputInfo.getRowResolver();
    ArrayList<ColumnInfo> colInfoList = rr.getColumnInfos();
    for (ColumnInfo colInfo : colInfoList) {
        String internalName = colInfo.getInternalName();
        TypeInfo type = colInfo.getType();
        valueCols.add(TranslateUtils.getExprDesc(internalName, type));
        outputColumnNames.add(internalName);
    }
}
Also used : Order(com.sap.hadoop.metadata.Order) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)

Example 15 with InputInfo

use of com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo in project SQLWindowing by hbutani.

the class OutputTranslation method translateSelectExprs.

public static void translateSelectExprs(QueryDef qDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    QueryInputDef iDef = qDef.getInput();
    InputInfo iInfo = tInfo.getInputInfo(iDef);
    SelectDef selectDef = qDef.getSelectList();
    SelectSpec selectSpec = qDef.getSpec().getSelectList();
    Iterator<Object> selectExprsAndAliases = selectSpec.getColumnListAndAlias();
    int i = 0;
    ColumnDef cDef = null;
    while (selectExprsAndAliases.hasNext()) {
        Object[] o = (Object[]) selectExprsAndAliases.next();
        boolean isWnFn = ((Boolean) o[0]).booleanValue();
        if (isWnFn) {
            cDef = translateWindowFnAlias(qDef, iInfo, i++, (String) o[1]);
        } else {
            cDef = translateSelectExpr(qDef, iInfo, i++, (String) o[1], (ASTNode) o[2]);
        }
        selectDef.addColumn(cDef);
    }
    TranslateUtils.setupSelectOI(selectDef);
}
Also used : SelectDef(com.sap.hadoop.windowing.query2.definition.SelectDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) SelectSpec(com.sap.hadoop.windowing.query2.specification.SelectSpec) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)8 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)8 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)6 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)6 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)3 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)3 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)3 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)2 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)2 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)2 WindowFrameDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef)2 OrderColumnSpec (com.sap.hadoop.windowing.query2.specification.OrderColumnSpec)2 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)2 RangeBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)2