use of com.sap.hadoop.windowing.query2.definition.WindowDef in project SQLWindowing by hbutani.
the class WindowSpecTranslation method translateWindow.
/*
* compute the Description to use for the Input.
* get the inputInfo for the input: if the function has a MapPhase use the Map Inputfo.
* invoke translateWindowSpecOnInput on WdwSpec of TblFunc
* If TableFunc is the FunctionRegistry.WINDOWING_TABLE_FUNCTION:
* -
*/
static WindowDef translateWindow(QueryDef qDef, TableFuncDef tFnDef) throws WindowingException {
QueryTranslationInfo tInfo = qDef.getTranslationInfo();
TableFuncSpec tFnSpec = tFnDef.getTableFuncSpec();
/*
* for now the Language only allows explicit specification of Partition & Order clauses.
* Easy to allow references to a Global Window Spec.
*/
WindowSpec wSpec = new WindowSpec();
wSpec.setPartition(tFnSpec.getPartition());
wSpec.setOrder(tFnSpec.getOrder());
QueryInputDef iDef = tFnDef.getInput();
if (wSpec.getPartition() == null) {
return null;
}
String desc = getInputDescription(qDef, tFnDef);
TableFunctionEvaluator tFn = tFnDef.getFunction();
InputInfo iInfo = null;
if (tFn.isTransformsRawInput()) {
iInfo = tInfo.getMapInputInfo(tFnDef);
} else {
iInfo = tInfo.getInputInfo(iDef);
}
return translateWindowSpecOnInput(qDef, wSpec, iInfo, desc);
}
use of com.sap.hadoop.windowing.query2.definition.WindowDef 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.definition.WindowDef in project SQLWindowing by hbutani.
the class WindowFunctionTranslation method validateWindowDefForWFn.
public static void validateWindowDefForWFn(TableFuncDef tFnDef, WindowFunctionDef wFnDef) throws WindowingException {
WindowDef tWindow = tFnDef.getWindow();
WindowDef fWindow = wFnDef.getWindow();
PartitionDef tPart = tWindow == null ? null : tWindow.getPartDef();
PartitionDef fPart = fWindow == null ? null : fWindow.getPartDef();
if (!TranslateUtils.isCompatible(tPart, fPart)) {
throw new WindowingException(sprintf("Window Function '%s' has an incompatible partition clause", wFnDef.getSpec()));
}
OrderDef tOrder = tWindow == null ? null : tWindow.getOrderDef();
OrderDef fOrder = fWindow == null ? null : fWindow.getOrderDef();
if (!TranslateUtils.isCompatible(tOrder, fOrder)) {
throw new WindowingException(sprintf("Window Function '%s' has an incompatible order clause", wFnDef.getSpec()));
}
}
use of com.sap.hadoop.windowing.query2.definition.WindowDef 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.definition.WindowDef 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);
}
Aggregations