Search in sources :

Example 1 with OrderColumnSpec

use of com.sap.hadoop.windowing.query2.specification.OrderColumnSpec 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 OrderColumnSpec

use of com.sap.hadoop.windowing.query2.specification.OrderColumnSpec 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

OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)2 WindowingException (com.sap.hadoop.windowing.WindowingException)1 ColumnDef (com.sap.hadoop.windowing.query2.definition.ColumnDef)1 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)1 OrderColumnSpec (com.sap.hadoop.windowing.query2.specification.OrderColumnSpec)1 ArrayList (java.util.ArrayList)1