Search in sources :

Example 1 with TableFuncDef

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

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()));
    }
}
Also used : WindowDef(com.sap.hadoop.windowing.query2.definition.WindowDef) PartitionDef(com.sap.hadoop.windowing.query2.definition.PartitionDef) WindowingException(com.sap.hadoop.windowing.WindowingException) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef)

Example 3 with TableFuncDef

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

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()));
}
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 5 with TableFuncDef

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

Aggregations

TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)9 WindowingException (com.sap.hadoop.windowing.WindowingException)6 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)6 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)5 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)4 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)2 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)2 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)2 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)2 Order (com.sap.hadoop.metadata.Order)1 TableFunctionResolver (com.sap.hadoop.windowing.functions2.TableFunctionResolver)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 HiveTableDef (com.sap.hadoop.windowing.query2.definition.HiveTableDef)1 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)1 WindowFunctionDef (com.sap.hadoop.windowing.query2.definition.WindowFunctionDef)1 HiveTableSpec (com.sap.hadoop.windowing.query2.specification.HiveTableSpec)1 TableFuncSpec (com.sap.hadoop.windowing.query2.specification.TableFuncSpec)1