use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.
the class TestDetermineJoinDistributionType method testGetSourceTablesSizeInBytes.
@Test
public void testGetSourceTablesSizeInBytes() {
PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), tester.getMetadata(), tester.getSession());
Symbol symbol = planBuilder.symbol("col");
Symbol sourceSymbol1 = planBuilder.symbol("source1");
Symbol sourceSymbol2 = planBuilder.symbol("soruce2");
// missing source stats
assertEquals(getSourceTablesSizeInBytes(planBuilder.values(symbol), noLookup(), node -> PlanNodeStatsEstimate.unknown(), planBuilder.getTypes()), NaN);
// two source plan nodes
PlanNodeStatsEstimate sourceStatsEstimate1 = PlanNodeStatsEstimate.builder().setOutputRowCount(10).build();
PlanNodeStatsEstimate sourceStatsEstimate2 = PlanNodeStatsEstimate.builder().setOutputRowCount(20).build();
assertEquals(getSourceTablesSizeInBytes(planBuilder.union(ImmutableListMultimap.<Symbol, Symbol>builder().put(symbol, sourceSymbol1).put(symbol, sourceSymbol2).build(), ImmutableList.of(planBuilder.tableScan(ImmutableList.of(sourceSymbol1), ImmutableMap.of(sourceSymbol1, new TestingColumnHandle("col"))), planBuilder.values(new PlanNodeId("valuesNode"), sourceSymbol2))), noLookup(), node -> {
if (node instanceof TableScanNode) {
return sourceStatsEstimate1;
}
if (node instanceof ValuesNode) {
return sourceStatsEstimate2;
}
return PlanNodeStatsEstimate.unknown();
}, planBuilder.getTypes()), 270.0);
// join node
assertEquals(getSourceTablesSizeInBytes(planBuilder.join(INNER, planBuilder.values(sourceSymbol1), planBuilder.values(sourceSymbol2)), noLookup(), node -> sourceStatsEstimate1, planBuilder.getTypes()), NaN);
}
use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.
the class ValuesMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
ValuesNode valuesNode = (ValuesNode) node;
if (expectedRows.isPresent()) {
if (expectedRows.get().size() != valuesNode.getRowCount()) {
return NO_MATCH;
}
if (outputSymbolAliases.size() > 0) {
if (!expectedRows.equals(valuesNode.getRows())) {
return NO_MATCH;
}
}
}
return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())).build());
}
use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.
the class TestRuleIndex method testWithPlanNodeHierarchy.
@Test
public void testWithPlanNodeHierarchy() {
Rule<?> projectRule1 = new NoOpRule<>(Pattern.typeOf(ProjectNode.class));
Rule<?> projectRule2 = new NoOpRule<>(Pattern.typeOf(ProjectNode.class));
Rule<?> filterRule = new NoOpRule<>(Pattern.typeOf(FilterNode.class));
Rule<?> anyRule = new NoOpRule<>(Pattern.any());
RuleIndex ruleIndex = RuleIndex.builder().register(projectRule1).register(projectRule2).register(filterRule).register(anyRule).build();
ProjectNode projectNode = planBuilder.project(Assignments.of(), planBuilder.values());
FilterNode filterNode = planBuilder.filter(BooleanLiteral.TRUE_LITERAL, planBuilder.values());
ValuesNode valuesNode = planBuilder.values();
assertEquals(ruleIndex.getCandidates(projectNode).collect(toSet()), ImmutableSet.of(projectRule1, projectRule2, anyRule));
assertEquals(ruleIndex.getCandidates(filterNode).collect(toSet()), ImmutableSet.of(filterRule, anyRule));
assertEquals(ruleIndex.getCandidates(valuesNode).collect(toSet()), ImmutableSet.of(anyRule));
}
use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.
the class RemoveEmptyExceptBranches method apply.
@Override
public Result apply(ExceptNode node, Captures captures, Context context) {
if (isEmpty(node.getSources().get(0), context.getLookup())) {
return Result.ofPlanNode(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
}
boolean hasEmptyBranches = node.getSources().stream().skip(// first source is the set we're excluding rows from, so ignore it
1).anyMatch(source -> isEmpty(source, context.getLookup()));
if (!hasEmptyBranches) {
return Result.empty();
}
ImmutableList.Builder<PlanNode> newSourcesBuilder = ImmutableList.builder();
ImmutableListMultimap.Builder<Symbol, Symbol> outputsToInputsBuilder = ImmutableListMultimap.builder();
for (int i = 0; i < node.getSources().size(); i++) {
PlanNode source = node.getSources().get(i);
if (i == 0 || !isEmpty(source, context.getLookup())) {
newSourcesBuilder.add(source);
for (Symbol column : node.getOutputSymbols()) {
outputsToInputsBuilder.put(column, node.getSymbolMapping().get(column).get(i));
}
}
}
List<PlanNode> newSources = newSourcesBuilder.build();
ListMultimap<Symbol, Symbol> outputsToInputs = outputsToInputsBuilder.build();
if (newSources.size() == 1) {
Assignments.Builder assignments = Assignments.builder();
outputsToInputs.entries().stream().forEach(entry -> assignments.put(entry.getKey(), entry.getValue().toSymbolReference()));
if (node.isDistinct()) {
return Result.ofPlanNode(new AggregationNode(node.getId(), new ProjectNode(context.getIdAllocator().getNextId(), newSources.get(0), assignments.build()), ImmutableMap.of(), singleGroupingSet(node.getOutputSymbols()), ImmutableList.of(), Step.SINGLE, Optional.empty(), Optional.empty()));
}
return Result.ofPlanNode(new ProjectNode(node.getId(), newSources.get(0), assignments.build()));
}
return Result.ofPlanNode(new ExceptNode(node.getId(), newSources, outputsToInputs, node.getOutputSymbols(), node.isDistinct()));
}
use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.
the class RemoveEmptyTableExecute method apply.
@Override
public Result apply(TableFinishNode finishNode, Captures captures, Context context) {
Optional<PlanNode> finishSource = getSingleSourceSkipExchange(finishNode, context.getLookup());
if (finishSource.isEmpty() || !(finishSource.get() instanceof TableExecuteNode)) {
return Result.empty();
}
Optional<PlanNode> tableExecuteSource = getSingleSourceSkipExchange(finishSource.get(), context.getLookup());
if (tableExecuteSource.isEmpty() || !(tableExecuteSource.get() instanceof ValuesNode)) {
return Result.empty();
}
ValuesNode valuesNode = (ValuesNode) tableExecuteSource.get();
verify(valuesNode.getRowCount() == 0, "Unexpected non-empty Values as source of TableExecuteNode");
return Result.ofPlanNode(new ValuesNode(finishNode.getId(), finishNode.getOutputSymbols(), ImmutableList.of(new Row(ImmutableList.of(new NullLiteral())))));
}
Aggregations