Search in sources :

Example 6 with InputInfo

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

the class WindowSpecTranslation method translateWindowFrame.

static WindowFrameDef translateWindowFrame(QueryDef qDef, WindowFrameSpec wfSpec, InputInfo iInfo) throws WindowingException {
    if (wfSpec == null) {
        return null;
    }
    BoundarySpec s = wfSpec.getStart();
    BoundarySpec e = wfSpec.getEnd();
    WindowFrameDef wfDef = new WindowFrameDef(wfSpec);
    wfDef.setStart(translateBoundary(qDef, s, iInfo));
    wfDef.setEnd(translateBoundary(qDef, e, iInfo));
    int cmp = s.compareTo(e);
    if (cmp > 0) {
        throw new WindowingException(sprintf("Window range invalid, start boundary is greater than end boundary: %s", wfSpec));
    }
    return wfDef;
}
Also used : WindowFrameDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef) WindowingException(com.sap.hadoop.windowing.WindowingException) ValueBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.ValueBoundarySpec) RangeBoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec) BoundarySpec(com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.BoundarySpec)

Example 7 with InputInfo

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

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

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

the class WindowFunctionTranslation method translateWindowSpec.

public static WindowDef translateWindowSpec(QueryDef qDef, InputInfo iInfo, WindowFunctionSpec wFnSpec) throws WindowingException {
    WindowSpec wSpec = wFnSpec.getWindowSpec();
    if (wSpec == null)
        return null;
    WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFnSpec.getName());
    String desc = wFnSpec.toString();
    if (wSpec != null && !wFnInfo.isSupportsWindow()) {
        throw new WindowingException(sprintf("Function %s doesn't support windowing", desc));
    }
    return WindowSpecTranslation.translateWindowSpecOnInput(qDef, wSpec, iInfo, desc);
}
Also used : WindowFunctionInfo(com.sap.hadoop.windowing.functions2.FunctionRegistry.WindowFunctionInfo) WindowingException(com.sap.hadoop.windowing.WindowingException) WindowSpec(com.sap.hadoop.windowing.query2.specification.WindowSpec)

Example 10 with InputInfo

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

the class WindowSpecTranslation method translateOrder.

static OrderDef translateOrder(QueryDef qDef, String inputDesc, InputInfo iInfo, OrderSpec spec, PartitionDef pDef) throws WindowingException {
    if (spec == null || spec.getColumns() == null || spec.getColumns().size() == 0) {
        if (pDef == null)
            return null;
        return new OrderDef(pDef);
    }
    if (pDef == null) {
        throw new WindowingException(sprintf("Input %s cannot have an Order spec w/o a Partition spec", inputDesc));
    }
    OrderDef oDef = new OrderDef(spec);
    for (OrderColumnSpec colSpec : spec.getColumns()) {
        OrderColumnDef cDef = translateOrderColumn(qDef, iInfo, colSpec);
        oDef.addColumn(cDef);
    }
    /*
		 * either all partition columns must be in Order list or none must be specified.
		 * If none are specified then add them all.
		 */
    int numOfPartColumns = 0;
    List<OrderColumnDef> orderCols = oDef.getColumns();
    List<ColumnDef> partCols = pDef.getColumns();
    int chkSize = partCols.size();
    chkSize = chkSize > orderCols.size() ? orderCols.size() : chkSize;
    for (int i = 0; i < chkSize; i++) {
        if (orderCols.get(i).getSpec().getColumnName().equals(partCols.get(i).getSpec().getColumnName())) {
            numOfPartColumns++;
        } else
            break;
    }
    if (numOfPartColumns != 0 && numOfPartColumns != partCols.size()) {
        throw new WindowingException(sprintf("For Input %s:n all partition columns must be in order clause or none should be specified", inputDesc));
    }
    ArrayList<OrderColumnDef> combinedOrderCols = new ArrayList<OrderColumnDef>();
    if (numOfPartColumns == 0) {
        for (ColumnDef cDef : partCols) {
            OrderColumnDef ocDef = new OrderColumnDef(cDef);
            combinedOrderCols.add(ocDef);
        }
        combinedOrderCols.addAll(orderCols);
        oDef.setColumns(combinedOrderCols);
    }
    return oDef;
}
Also used : OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) OrderColumnSpec(com.sap.hadoop.windowing.query2.specification.OrderColumnSpec) WindowingException(com.sap.hadoop.windowing.WindowingException) ArrayList(java.util.ArrayList) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)8 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)8 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)6 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)6 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)4 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)4 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)3 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)3 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)3 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)2 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)2 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)2 WindowFrameDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef)2 OrderColumnSpec (com.sap.hadoop.windowing.query2.specification.OrderColumnSpec)2 QuerySpec (com.sap.hadoop.windowing.query2.specification.QuerySpec)2 RangeBoundarySpec (com.sap.hadoop.windowing.query2.specification.WindowFrameSpec.RangeBoundarySpec)2