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;
}
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()));
}
}
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());
}
}
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);
}
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;
}
Aggregations