use of io.prestosql.spi.plan.WindowNode in project hetu-core by openlookeng.
the class WindowFunctionMatcher method getAssignedSymbol.
@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
Optional<Symbol> result = Optional.empty();
if (!(node instanceof WindowNode)) {
return result;
}
WindowNode windowNode = (WindowNode) node;
FunctionCall expectedCall = callMaker.getExpectedValue(symbolAliases);
Optional<WindowNode.Frame> expectedFrame = frameMaker.map(maker -> maker.getExpectedValue(symbolAliases));
for (Map.Entry<Symbol, Function> assignment : windowNode.getWindowFunctions().entrySet()) {
Function function = assignment.getValue();
boolean signatureMatches = functionHandle.map(assignment.getValue().getFunctionHandle()::equals).orElse(true);
if (signatureMatches && windowFunctionMatches(function, expectedCall, expectedFrame, metadata)) {
checkState(!result.isPresent(), "Ambiguous function calls in %s", windowNode);
result = Optional.of(assignment.getKey());
}
}
return result;
}
use of io.prestosql.spi.plan.WindowNode in project hetu-core by openlookeng.
the class TestTypeValidator method testValidWindow.
@Test
public void testValidWindow() {
Symbol windowSymbol = planSymbolAllocator.newSymbol("sum", DOUBLE);
FunctionHandle functionHandle = FUNCTION_MANAGER.lookupFunction("sum", fromTypes(DOUBLE));
WindowNode.Frame frame = new WindowNode.Frame(WindowFrameType.RANGE, FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), FrameBoundType.UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
WindowNode.Function function = new WindowNode.Function(call("sum", functionHandle, DOUBLE, ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnC, DOUBLE))), ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnC, DOUBLE)), frame);
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
assertTypesValid(node);
}
use of io.prestosql.spi.plan.WindowNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testWindow.
@Test
public void testWindow() {
PlanNode node = new WindowNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new WindowNode.Specification(ImmutableList.of(A), Optional.of(new OrderingScheme(ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)))), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0);
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Pass through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
use of io.prestosql.spi.plan.WindowNode in project hetu-core by openlookeng.
the class ImplementLimitWithTies method apply.
@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
PlanNode child = captures.get(CHILD);
Symbol rankSymbol = context.getSymbolAllocator().newSymbol("rank_num", BIGINT);
WindowNode.Frame frame = new WindowNode.Frame(WindowFrameType.RANGE, FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), FrameBoundType.CURRENT_ROW, Optional.empty(), Optional.empty(), Optional.empty());
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
WindowNode.Function rankFunction = new WindowNode.Function(call(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "rank").toString(), functionHandle, BIGINT), ImmutableList.of(), frame);
WindowNode windowNode = new WindowNode(context.getIdAllocator().getNextId(), child, new WindowNode.Specification(ImmutableList.of(), parent.getTiesResolvingScheme()), ImmutableMap.of(rankSymbol, rankFunction), Optional.empty(), ImmutableSet.of(), 0);
FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), windowNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN_OR_EQUAL, toSymbolReference(rankSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
return Result.ofPlanNode(projectNode);
}
use of io.prestosql.spi.plan.WindowNode in project hetu-core by openlookeng.
the class PruneWindowColumns method pushDownProjectOff.
@Override
protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, WindowNode windowNode, Set<Symbol> referencedOutputs) {
Map<Symbol, WindowNode.Function> referencedFunctions = Maps.filterKeys(windowNode.getWindowFunctions(), referencedOutputs::contains);
if (referencedFunctions.isEmpty()) {
return Optional.of(windowNode.getSource());
}
ImmutableSet.Builder<Symbol> referencedInputs = ImmutableSet.<Symbol>builder().addAll(windowNode.getSource().getOutputSymbols().stream().filter(referencedOutputs::contains).iterator()).addAll(windowNode.getPartitionBy());
windowNode.getOrderingScheme().ifPresent(orderingScheme -> orderingScheme.getOrderBy().forEach(referencedInputs::add));
windowNode.getHashSymbol().ifPresent(referencedInputs::add);
for (WindowNode.Function windowFunction : referencedFunctions.values()) {
referencedInputs.addAll(SymbolsExtractor.extractUnique(windowFunction));
}
PlanNode prunedWindowNode = new WindowNode(windowNode.getId(), restrictOutputs(idAllocator, windowNode.getSource(), referencedInputs.build(), false, null).orElse(windowNode.getSource()), windowNode.getSpecification(), referencedFunctions, windowNode.getHashSymbol(), windowNode.getPrePartitionedInputs(), windowNode.getPreSortedOrderPrefix());
if (prunedWindowNode.getOutputSymbols().size() == windowNode.getOutputSymbols().size()) {
// Neither function pruning nor input pruning was successful.
return Optional.empty();
}
return Optional.of(prunedWindowNode);
}
Aggregations