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