Search in sources :

Example 1 with OrderColumnDef

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

the class WindowSpecTranslation method translateOrderColumn.

static OrderColumnDef translateOrderColumn(QueryDef qDef, InputInfo iInfo, OrderColumnSpec oSpec) throws WindowingException {
    OrderColumnDef ocDef = new OrderColumnDef(oSpec);
    translateColumn(qDef, ocDef, iInfo, oSpec);
    TranslateUtils.validateComparable(ocDef.getOI(), sprintf("Partition Column %s is not comparable", oSpec));
    return ocDef;
}
Also used : OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef)

Example 2 with OrderColumnDef

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

use of com.sap.hadoop.windowing.query2.definition.OrderColumnDef 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)

Example 4 with OrderColumnDef

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

the class QueryDefWalker method walk.

/**
	 * Visit the partition columns and order columns 
	 * Visit the window frame definitions
	 * @param window
	 * @throws WindowingException
	 */
protected void walk(WindowDef window) throws WindowingException {
    if (window == null)
        return;
    PartitionDef pDef = window.getPartDef();
    if (pDef != null) {
        ArrayList<ColumnDef> cols = pDef.getColumns();
        for (ColumnDef col : cols) {
            visitor.visit(col);
        }
        visitor.visit(pDef);
    }
    OrderDef oDef = window.getOrderDef();
    if (oDef != null) {
        ArrayList<OrderColumnDef> ocols = oDef.getColumns();
        for (OrderColumnDef ocol : ocols) {
            visitor.visit(ocol);
        }
        visitor.visit(oDef);
    }
    WindowFrameDef wFrmDef = window.getWindow();
    if (wFrmDef != null) {
        walk(wFrmDef.getStart());
        walk(wFrmDef.getEnd());
        visitor.visit(wFrmDef);
    }
    visitor.visit(window);
}
Also used : OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) WindowFrameDef(com.sap.hadoop.windowing.query2.definition.WindowFrameDef) PartitionDef(com.sap.hadoop.windowing.query2.definition.PartitionDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef)

Example 5 with OrderColumnDef

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

the class MRUtils method initialize.

/**
	 * Construct the data structures containing ExprNodeDesc for partition
	 * columns and order columns. Use the input definition to construct the list
	 * of output columns for the ReduceSinkOperator
	 * 
	 * @throws WindowingException
	 */
public void initialize() throws WindowingException {
    TableFuncDef tabDef = RuntimeUtils.getFirstTableFunction(qdef);
    hiveTableDef = tabDef.getHiveTableDef();
    InputInfo inputInfo;
    ArrayList<ColumnDef> partColList = tabDef.getWindow().getPartDef().getColumns();
    TableFunctionEvaluator tEval = tabDef.getFunction();
    /*
		 * If the query has a map phase, the inputInfo is retrieved from the map
		 * output info of the table function definition. This is constructed
		 * using the map output oi of the table function definition. If the
		 * query does not have a map phase, the inputInfo is retrieved from the
		 * QueryInputDef (either HiveTableDef or HiveQueryDef) of the query.
		 */
    if (tEval.isTransformsRawInput()) {
        inputInfo = qdef.getTranslationInfo().getMapInputInfo(tabDef);
    } else {
        inputInfo = qdef.getTranslationInfo().getInputInfo(hiveTableDef);
    }
    for (ColumnDef colDef : partColList) {
        partCols.add(colDef.getExprNode());
    }
    ArrayList<OrderColumnDef> orderColList = tabDef.getWindow().getOrderDef().getColumns();
    for (OrderColumnDef colDef : orderColList) {
        Order order = colDef.getOrder();
        if (order.name().equals("ASC")) {
            orderString.append('+');
        } else {
            orderString.append('-');
        }
        orderCols.add(colDef.getExprNode());
        outputColumnNames.add(colDef.getAlias());
    }
    RowResolver rr = inputInfo.getRowResolver();
    ArrayList<ColumnInfo> colInfoList = rr.getColumnInfos();
    for (ColumnInfo colInfo : colInfoList) {
        String internalName = colInfo.getInternalName();
        TypeInfo type = colInfo.getType();
        valueCols.add(TranslateUtils.getExprDesc(internalName, type));
        outputColumnNames.add(internalName);
    }
}
Also used : Order(com.sap.hadoop.metadata.Order) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnDef(com.sap.hadoop.windowing.query2.definition.ColumnDef) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) RowResolver(org.apache.hadoop.hive.ql.parse.RowResolver) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) TableFuncDef(com.sap.hadoop.windowing.query2.definition.TableFuncDef) InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) TableFunctionEvaluator(com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)

Aggregations

OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)5 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)3 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)3 WindowingException (com.sap.hadoop.windowing.WindowingException)2 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)2 Order (com.sap.hadoop.metadata.Order)1 TableFunctionEvaluator (com.sap.hadoop.windowing.functions2.TableFunctionEvaluator)1 PartitionDef (com.sap.hadoop.windowing.query2.definition.PartitionDef)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 TableFuncDef (com.sap.hadoop.windowing.query2.definition.TableFuncDef)1 WindowFrameDef (com.sap.hadoop.windowing.query2.definition.WindowFrameDef)1 OrderColumnSpec (com.sap.hadoop.windowing.query2.specification.OrderColumnSpec)1 ArrayList (java.util.ArrayList)1 ColumnInfo (org.apache.hadoop.hive.ql.exec.ColumnInfo)1 RowResolver (org.apache.hadoop.hive.ql.parse.RowResolver)1 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)1