Search in sources :

Example 1 with QueryInputDef

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

the class WindowFunctionTranslation method setupRankingArgs.

static void setupRankingArgs(QueryDef qDef, TableFuncDef windowTableFnDef, WindowFunctionDef wFnDef, WindowFunctionSpec wSpec) throws WindowingException {
    if (wSpec.getArgs().size() > 0) {
        throw new WindowingException("Ranking Functions can take no arguments");
    }
    QueryInputDef inpDef = windowTableFnDef.getInput();
    InputInfo inpInfo = qDef.getTranslationInfo().getInputInfo(inpDef);
    OrderDef oDef = getTableFuncOrderDef(windowTableFnDef);
    ArrayList<OrderColumnDef> oCols = oDef.getColumns();
    for (OrderColumnDef oCol : oCols) {
        wFnDef.addArg(TranslateUtils.buildArgDef(qDef, inpInfo, oCol.getExpression()));
    }
}
Also used : InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) WindowingException(com.sap.hadoop.windowing.WindowingException) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef)

Example 2 with QueryInputDef

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

the class InputTranslation method getTableAlias.

private static String getTableAlias(QueryDef qDef, int inputNum, QueryInputDef inputDef) throws WindowingException {
    if (inputDef instanceof HiveTableDef) {
        HiveTableDef hTbldef = (HiveTableDef) inputDef;
        String db = ((HiveTableSpec) hTbldef.getSpec()).getDbName();
        String tableName = ((HiveTableSpec) hTbldef.getSpec()).getTableName();
        return db + "." + tableName;
    } else if (inputDef instanceof TableFuncDef) {
        return "ptf_" + inputNum;
    }
    throw new WindowingException(sprintf("Internal Error: attempt to translate %s", inputDef.getSpec()));
}
Also used : WindowingException(com.sap.hadoop.windowing.WindowingException) HiveTableSpec(com.sap.hadoop.windowing.query2.specification.HiveTableSpec) HiveTableDef(com.sap.hadoop.windowing.query2.definition.HiveTableDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Example 3 with QueryInputDef

use of com.sap.hadoop.windowing.query2.definition.QueryInputDef 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 4 with QueryInputDef

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

the class Executor method executeChain.

/**
 * For all the table functions to be applied to the input
 * hive table or query, push them on a stack.
 * For each table function popped out of the stack,
 * execute the function on the input partition
 * and return an output partition.
 * @param qDef
 * @param part
 * @return
 * @throws WindowingException
 */
public static Partition executeChain(QueryDef qDef, Partition part) throws WindowingException {
    Stack<TableFuncDef> fnDefs = new Stack<TableFuncDef>();
    QueryInputDef iDef = qDef.getInput();
    while (true) {
        if (iDef instanceof TableFuncDef) {
            fnDefs.push((TableFuncDef) iDef);
            iDef = ((TableFuncDef) iDef).getInput();
        } else {
            break;
        }
    }
    TableFuncDef currFnDef;
    while (!fnDefs.isEmpty()) {
        currFnDef = fnDefs.pop();
        part = currFnDef.getFunction().execute(part);
    }
    return part;
}
Also used : QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef) Stack(java.util.Stack)

Example 5 with QueryInputDef

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

the class RuntimeUtils method getFirstTableFunction.

/**
 * Iterate the list of the query input definitions in reverse order
 * Return the first table function definition in the chain.
 * This table function is the first one to be executed on the
 * input hive table.
 * @param qDef
 * @return
 */
public static TableFuncDef getFirstTableFunction(QueryDef qDef) {
    TableFuncDef tabDef = null;
    Iterator<QueryInputDef> it = TranslateUtils.iterateInputDefs(qDef, true);
    while (it.hasNext()) {
        QueryInputDef qIn = it.next();
        if (qIn instanceof TableFuncDef) {
            tabDef = (TableFuncDef) qIn;
            break;
        }
    }
    return tabDef;
}
Also used : QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef)

Aggregations

QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)6 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)6 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)5 WindowingException (com.sap.hadoop.windowing.WindowingException)4 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)3 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)3 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)2 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)2 Order (com.sap.hadoop.metadata.Order)1 TableFunctionResolver (com.sap.hadoop.windowing.functions2.TableFunctionResolver)1 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)1 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)1 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)1 SelectDef (com.sap.hadoop.windowing.query2.definition.SelectDef)1 WhereDef (com.sap.hadoop.windowing.query2.definition.WhereDef)1 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)1 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)1 SelectSpec (com.sap.hadoop.windowing.query2.specification.SelectSpec)1 TableFuncSpec (com.sap.hadoop.windowing.query2.specification.TableFuncSpec)1 WindowSpec (com.sap.hadoop.windowing.query2.specification.WindowSpec)1