use of com.sap.hadoop.windowing.query2.definition.TableFuncDef 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.TableFuncDef in project SQLWindowing by hbutani.
the class WindowFunctionTranslation method validateWindowDefForWFn.
public static void validateWindowDefForWFn(TableFuncDef tFnDef, WindowFunctionDef wFnDef) throws WindowingException {
WindowDef tWindow = tFnDef.getWindow();
WindowDef fWindow = wFnDef.getWindow();
PartitionDef tPart = tWindow == null ? null : tWindow.getPartDef();
PartitionDef fPart = fWindow == null ? null : fWindow.getPartDef();
if (!TranslateUtils.isCompatible(tPart, fPart)) {
throw new WindowingException(sprintf("Window Function '%s' has an incompatible partition clause", wFnDef.getSpec()));
}
OrderDef tOrder = tWindow == null ? null : tWindow.getOrderDef();
OrderDef fOrder = fWindow == null ? null : fWindow.getOrderDef();
if (!TranslateUtils.isCompatible(tOrder, fOrder)) {
throw new WindowingException(sprintf("Window Function '%s' has an incompatible order clause", wFnDef.getSpec()));
}
}
use of com.sap.hadoop.windowing.query2.definition.TableFuncDef 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());
}
}
use of com.sap.hadoop.windowing.query2.definition.TableFuncDef 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.TableFuncDef 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);
}
Aggregations