use of org.apache.hadoop.hive.ql.exec.WindowFunctionInfo in project flink by apache.
the class HiveParserWindowingSpec method effectiveWindowFrame.
private void effectiveWindowFrame(WindowFunctionSpec wFn) throws SemanticException {
WindowSpec wdwSpec = wFn.getWindowSpec();
WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName());
boolean supportsWindowing = wFnInfo == null || wFnInfo.isSupportsWindow();
WindowFrameSpec wFrame = wdwSpec.getWindowFrame();
OrderSpec orderSpec = wdwSpec.getOrder();
if (wFrame == null) {
if (!supportsWindowing) {
if (wFn.getName().toLowerCase().equals(FunctionRegistry.LAST_VALUE_FUNC_NAME) && orderSpec != null) {
/*
* last_value: when an Sort Key is specified, then last_value should return the
* last value among rows with the same Sort Key value.
*/
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.CURRENT), new BoundarySpec(Direction.FOLLOWING, 0));
} else {
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.FOLLOWING, BoundarySpec.UNBOUNDED_AMOUNT));
}
} else {
if (orderSpec == null) {
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.FOLLOWING, BoundarySpec.UNBOUNDED_AMOUNT));
} else {
wFrame = new WindowFrameSpec(WindowType.RANGE, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.CURRENT));
}
}
wdwSpec.setWindowFrame(wFrame);
} else if (wFrame.getEnd() == null) {
wFrame.setEnd(new BoundarySpec(Direction.CURRENT));
}
}
use of org.apache.hadoop.hive.ql.exec.WindowFunctionInfo in project hive by apache.
the class WindowingTableFunction method initializeWindowingFunctionInfoHelpers.
private void initializeWindowingFunctionInfoHelpers() throws SemanticException {
// to the object during the map/reduce tasks.
if (windowingFunctionHelpers != null) {
return;
}
windowingFunctionHelpers = new HashMap<String, WindowingFunctionInfoHelper>();
WindowTableFunctionDef tabDef = (WindowTableFunctionDef) getTableDef();
for (int i = 0; i < tabDef.getWindowFunctions().size(); i++) {
WindowFunctionDef wFn = tabDef.getWindowFunctions().get(i);
WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName());
boolean supportsWindow = wFnInfo.isSupportsWindow();
windowingFunctionHelpers.put(wFn.getName(), new WindowingFunctionInfoHelper(supportsWindow));
}
}
use of org.apache.hadoop.hive.ql.exec.WindowFunctionInfo in project hive by apache.
the class SemanticAnalyzer method processWindowFunction.
private WindowFunctionSpec processWindowFunction(ASTNode node, ASTNode wsNode) throws SemanticException {
WindowFunctionSpec wfSpec = new WindowFunctionSpec();
switch(node.getType()) {
case HiveParser.TOK_FUNCTIONSTAR:
wfSpec.setStar(true);
break;
case HiveParser.TOK_FUNCTIONDI:
wfSpec.setDistinct(true);
break;
}
wfSpec.setExpression(node);
ASTNode nameNode = (ASTNode) node.getChild(0);
wfSpec.setName(nameNode.getText());
for (int i = 1; i < node.getChildCount() - 1; i++) {
ASTNode child = (ASTNode) node.getChild(i);
wfSpec.addArg(child);
}
if (wsNode != null) {
WindowFunctionInfo functionInfo = FunctionRegistry.getWindowFunctionInfo(wfSpec.name);
if (functionInfo == null) {
throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(wfSpec.name));
}
wfSpec.setRespectNulls(processRespectIgnoreNulls(functionInfo, wsNode));
wfSpec.setWindowSpec(processWindowSpec(wsNode));
}
return wfSpec;
}
use of org.apache.hadoop.hive.ql.exec.WindowFunctionInfo in project hive by apache.
the class WindowingSpec method effectiveWindowFrame.
/*
* - A Window Frame that has only the start boundary, then it is interpreted as:
* BETWEEN <start boundary> AND CURRENT ROW
* - A Window Specification with an Order Specification and no Window Frame is
* interpreted as: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
* - A Window Specification with no Order and no Window Frame is interpreted as:
* ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
*/
private void effectiveWindowFrame(WindowFunctionSpec wFn) throws SemanticException {
WindowSpec wdwSpec = wFn.getWindowSpec();
WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName());
boolean supportsWindowing = wFnInfo == null ? true : wFnInfo.isSupportsWindow();
WindowFrameSpec wFrame = wdwSpec.getWindowFrame();
OrderSpec orderSpec = wdwSpec.getOrder();
if (wFrame == null) {
if (!supportsWindowing) {
if (wFn.getName().toLowerCase().equals(FunctionRegistry.LAST_VALUE_FUNC_NAME) && orderSpec != null) {
/*
* last_value: when an Sort Key is specified, then last_value should return the
* last value among rows with the same Sort Key value.
*/
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.CURRENT), new BoundarySpec(Direction.FOLLOWING, 0));
} else {
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.FOLLOWING, BoundarySpec.UNBOUNDED_AMOUNT));
}
} else {
if (orderSpec == null) {
wFrame = new WindowFrameSpec(WindowType.ROWS, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.FOLLOWING, BoundarySpec.UNBOUNDED_AMOUNT));
} else {
wFrame = new WindowFrameSpec(WindowType.RANGE, new BoundarySpec(Direction.PRECEDING, BoundarySpec.UNBOUNDED_AMOUNT), new BoundarySpec(Direction.CURRENT));
}
}
wdwSpec.setWindowFrame(wFrame);
} else if (wFrame.getEnd() == null) {
wFrame.setEnd(new BoundarySpec(Direction.CURRENT));
}
}
use of org.apache.hadoop.hive.ql.exec.WindowFunctionInfo in project hive by apache.
the class PTFTranslator method translate.
private WindowFunctionDef translate(WindowTableFunctionDef wdwTFnDef, WindowFunctionSpec spec) throws SemanticException {
WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(spec.getName());
if (wFnInfo == null) {
throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(spec.getName()));
}
WindowFunctionDef def = new WindowFunctionDef();
def.setName(spec.getName());
def.setAlias(spec.getAlias());
def.setDistinct(spec.isDistinct());
def.setExpressionTreeString(spec.getExpression().toStringTree());
def.setStar(spec.isStar());
def.setPivotResult(wFnInfo.isPivotResult());
def.setRespectNulls(spec.isRespectNulls());
ShapeDetails inpShape = wdwTFnDef.getRawInputShape();
/*
* translate args
*/
ArrayList<ASTNode> args = spec.getArgs();
if (args != null) {
for (ASTNode expr : args) {
PTFExpressionDef argDef = null;
try {
argDef = buildExpressionDef(inpShape, expr);
} catch (HiveException he) {
throw new SemanticException(he);
}
def.addArg(argDef);
}
}
if (FunctionRegistry.isRankingFunction(spec.getName())) {
setupRankingArgs(wdwTFnDef, def, spec);
}
WindowSpec wdwSpec = spec.getWindowSpec();
if (wdwSpec != null) {
String desc = spec.toString();
WindowFrameDef wdwFrame = translate(spec.getName(), inpShape, wdwSpec);
if (!wFnInfo.isSupportsWindow()) {
BoundarySpec start = wdwSpec.getWindowFrame().getStart();
if (start.getAmt() != BoundarySpec.UNBOUNDED_AMOUNT) {
throw new SemanticException(String.format("Expecting left window frame boundary for " + "function %s to be unbounded. Found : %d", desc, start.getAmt()));
}
BoundarySpec end = wdwSpec.getWindowFrame().getEnd();
if (end.getAmt() != BoundarySpec.UNBOUNDED_AMOUNT) {
throw new SemanticException(String.format("Expecting right window frame boundary for " + "function %s to be unbounded. Found : %d", desc, start.getAmt()));
}
}
def.setWindowFrame(wdwFrame);
}
try {
setupWdwFnEvaluator(def);
} catch (HiveException he) {
throw new SemanticException(he);
}
return def;
}
Aggregations