use of com.sap.hadoop.windowing.query2.specification.OrderSpec in project SQLWindowing by hbutani.
the class WindowSpecTranslation method translateWindowSpecOnInput.
/*
* <ol>
* <li> If wSpec points to a source WindowSpec. Validate that it is valid. If it hasn't been already translated then translate it.
* <li> Start with an empty WdwDef or a cloned WdwDef from the source WdwDef.
* <li> translate the PartitionSpec if it exists. Replace the existing PDef with this; also remove the OrderDef.
* <li> translate the OrderSpec if it exists. Replace existing OrderDef with this.
* <li> add in Partition Columns if not in OrderDef already.
* <li> translate the WindowSpec if it exists. Replace existing WdwDef with it.
* <li> If name is non-null add this def to TranslationInfo::nameToWdwDef map.
* </ol>
*/
static WindowDef translateWindowSpecOnInput(QueryDef qDef, WindowSpec wSpec, InputInfo iInfo, String inputDesc) throws WindowingException {
QuerySpec qSpec = qDef.getSpec();
WindowDef wDef;
fillInWindowSpec(qSpec, wSpec.getSourceId(), wSpec);
wDef = new WindowDef(wSpec);
PartitionSpec pSpec = wSpec.getPartition();
OrderSpec oSpec = wSpec.getOrder();
WindowFrameSpec wFrameSpec = wSpec.getWindow();
PartitionDef pDef = translatePartition(qDef, iInfo, pSpec);
OrderDef oDef = translateOrder(qDef, inputDesc, iInfo, oSpec, pDef);
WindowFrameDef wdwDef = translateWindowFrame(qDef, wFrameSpec, iInfo);
wDef.setPartDef(pDef);
wDef.setOrderDef(oDef);
wDef.setWindow(wdwDef);
return wDef;
}
use of com.sap.hadoop.windowing.query2.specification.OrderSpec 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;
}
Aggregations