Search in sources :

Example 1 with QueryTranslationInfo

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

the class RuntimeUtils method connectLeadLagFunctionsToPartition.

public static void connectLeadLagFunctionsToPartition(QueryDef qDef, PartitionIterator<Object> pItr) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    List<ExprNodeGenericFuncDesc> llFnDescs = tInfo.getLLInfo().getLeadLagExprs();
    if (llFnDescs == null)
        return;
    for (ExprNodeGenericFuncDesc llFnDesc : llFnDescs) {
        GenericUDFLeadLag llFn = (GenericUDFLeadLag) llFnDesc.getGenericUDF();
        llFn.setpItr(pItr);
    }
}
Also used : GenericUDFLeadLag(com.sap.hadoop.windowing.functions2.GenericUDFLeadLag) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) QueryTranslationInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo)

Example 2 with QueryTranslationInfo

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

the class Translator method translate.

public QueryDef translate(QuerySpec qSpec, WindowingShell wShell) throws WindowingException {
    // clone the cfg
    HiveConf qCfg = new HiveConf(wShell.getCfg());
    QueryDef qry = new QueryDef();
    qry.setSpec(qSpec);
    QueryTranslationInfo transInfo = new QueryTranslationInfo();
    transInfo.setHiveCfg(qCfg);
    transInfo.setWshell(wShell);
    try {
        transInfo.setHive(Hive.get(qCfg));
        transInfo.setHiveMSClient(HiveUtils.getClient(qCfg));
    } catch (HiveException he) {
        throw new WindowingException(he);
    }
    qry.setTranslationInfo(transInfo);
    InputTranslation.translate(qry);
    WhereTranslation.translate(qry);
    OutputTranslation.translate(qry);
    return qry;
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) WindowingException(com.sap.hadoop.windowing.WindowingException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) QueryDef(com.sap.hadoop.windowing.query2.definition.QueryDef)

Example 3 with QueryTranslationInfo

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

the class WindowFunctionTranslation method addInputColumnsToList.

public static void addInputColumnsToList(QueryDef qDef, TableFuncDef windowTableFnDef, ArrayList<String> fieldNames, ArrayList<ObjectInspector> fieldOIs) {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    InputInfo iInfo = tInfo.getInputInfo(windowTableFnDef.getInput());
    StructObjectInspector OI = (StructObjectInspector) iInfo.getOI();
    for (StructField f : OI.getAllStructFieldRefs()) {
        fieldNames.add(f.getFieldName());
        fieldOIs.add(f.getFieldObjectInspector());
    }
}
Also used : InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 4 with QueryTranslationInfo

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

the class WindowSpecTranslation method translateWindow.

/*
	 * compute the Description to use for the Input.
	 * get the inputInfo for the input: if the function has a MapPhase use the Map Inputfo. 
	 * invoke translateWindowSpecOnInput on WdwSpec of TblFunc
	 * If TableFunc is the FunctionRegistry.WINDOWING_TABLE_FUNCTION:
	 * - 
	 */
static WindowDef translateWindow(QueryDef qDef, TableFuncDef tFnDef) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    TableFuncSpec tFnSpec = tFnDef.getTableFuncSpec();
    /*
		 * for now the Language only allows explicit specification of Partition & Order clauses.
		 * Easy to allow references to a Global Window Spec.
		 */
    WindowSpec wSpec = new WindowSpec();
    wSpec.setPartition(tFnSpec.getPartition());
    wSpec.setOrder(tFnSpec.getOrder());
    QueryInputDef iDef = tFnDef.getInput();
    if (wSpec.getPartition() == null) {
        return null;
    }
    String desc = getInputDescription(qDef, tFnDef);
    TableFunctionEvaluator tFn = tFnDef.getFunction();
    InputInfo iInfo = null;
    if (tFn.isTransformsRawInput()) {
        iInfo = tInfo.getMapInputInfo(tFnDef);
    } else {
        iInfo = tInfo.getInputInfo(iDef);
    }
    return translateWindowSpecOnInput(qDef, wSpec, iInfo, desc);
}
Also used : TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) TableFuncSpec(com.sap.hadoop.windowing.query2.specification.TableFuncSpec) WindowSpec(com.sap.hadoop.windowing.query2.specification.WindowSpec)

Example 5 with QueryTranslationInfo

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

Aggregations

InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)6 WindowingException (com.sap.hadoop.windowing.WindowingException)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)3 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)2 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)2 QueryTranslationInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo)2 GenericUDFLeadLag (com.sap.hadoop.windowing.functions2.GenericUDFLeadLag)1 TableFunctionResolver (com.sap.hadoop.windowing.functions2.TableFunctionResolver)1 WindowingInput (com.sap.hadoop.windowing.io.WindowingInput)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 QueryDef (com.sap.hadoop.windowing.query2.definition.QueryDef)1 QueryOutputDef (com.sap.hadoop.windowing.query2.definition.QueryOutputDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)1 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)1 WindowFunctionDef (com.sap.hadoop.windowing.query2.definition.WindowFunctionDef)1 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)1 QueryOutputSpec (com.sap.hadoop.windowing.query2.specification.QueryOutputSpec)1