use of com.sap.hadoop.windowing.query2.definition.QueryDef 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.QueryDef 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;
}
use of com.sap.hadoop.windowing.query2.definition.QueryDef in project SQLWindowing by hbutani.
the class WindowSpecTranslation method translateBoundary.
static BoundaryDef translateBoundary(QueryDef qDef, BoundarySpec bndSpec, InputInfo iInfo) throws WindowingException {
if (bndSpec instanceof ValueBoundarySpec) {
ValueBoundarySpec vBndSpec = (ValueBoundarySpec) bndSpec;
ValueBoundaryDef vbDef = new ValueBoundaryDef(vBndSpec);
TranslateUtils.validateNoLeadLagInValueBoundarySpec(vBndSpec.getExpression());
ExprNodeDesc exprNode = TranslateUtils.buildExprNode(vBndSpec.getExpression(), iInfo.getTypeCheckCtx());
vbDef.setExprNode(exprNode);
ExprNodeEvaluator exprEval = WindowingExprNodeEvaluatorFactory.get(qDef.getTranslationInfo(), exprNode);
ObjectInspector OI = TranslateUtils.initExprNodeEvaluator(qDef, exprNode, exprEval, iInfo);
TranslateUtils.validateValueBoundaryExprType(OI);
vbDef.setExprEvaluator(exprEval);
vbDef.setOI(OI);
return vbDef;
} else if (bndSpec instanceof RangeBoundarySpec) {
RangeBoundarySpec rBndSpec = (RangeBoundarySpec) bndSpec;
RangeBoundaryDef rbDef = new RangeBoundaryDef(rBndSpec);
return rbDef;
} else if (bndSpec instanceof CurrentRowSpec) {
CurrentRowSpec cBndSpec = (CurrentRowSpec) bndSpec;
CurrentRowDef cbDef = new CurrentRowDef(cBndSpec);
return cbDef;
}
throw new WindowingException("Unknown Boundary: " + bndSpec);
}
use of com.sap.hadoop.windowing.query2.definition.QueryDef in project SQLWindowing by hbutani.
the class InputTranslation method translate.
private static HiveQueryDef translate(QueryDef qDef, HiveQuerySpec spec) throws WindowingException {
HiveQueryDef def = new HiveQueryDef();
HiveQueryExecutor hiveQryExec = qDef.getTranslationInfo().getHiveQueryExecutor();
Hive hive = qDef.getTranslationInfo().getHive();
String tableName = hiveQryExec.createTableAsQuery(spec.getHiveQuery());
HiveTableSpec tSpec = new HiveTableSpec();
tSpec.setDbName(hive.getCurrentDatabase());
tSpec.setTableName(tableName);
tSpec.setPartition(spec.getPartition());
tSpec.setOrder(spec.getOrder());
def = (HiveQueryDef) InputTranslation.translate(qDef, tSpec, (HiveTableDef) def);
return def;
}
use of com.sap.hadoop.windowing.query2.definition.QueryDef in project SQLWindowing by hbutani.
the class InputTranslation method getTableAlias.
private static String getTableAlias(QueryDef qDef, int inputNum, QueryInputDef inputDef) throws WindowingException {
if (inputDef instanceof HiveTableDef) {
HiveTableDef hTbldef = (HiveTableDef) inputDef;
String db = ((HiveTableSpec) hTbldef.getSpec()).getDbName();
String tableName = ((HiveTableSpec) hTbldef.getSpec()).getTableName();
return db + "." + tableName;
} else if (inputDef instanceof TableFuncDef) {
return "ptf_" + inputNum;
}
throw new WindowingException(sprintf("Internal Error: attempt to translate %s", inputDef.getSpec()));
}
Aggregations