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()));
}
}
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()));
}
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);
}
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;
}
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;
}
Aggregations