@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new OutputNode(getId(), Iterables.getOnlyElement(newChildren), columnNames, outputs); } }
private PlanNode createOutputPlan(RelationPlan plan, Analysis analysis) { ImmutableList.Builder<Symbol> outputs = ImmutableList.builder(); ImmutableList.Builder<String> names = ImmutableList.builder(); int columnNumber = 0; RelationType outputDescriptor = analysis.getOutputDescriptor(); for (Field field : outputDescriptor.getVisibleFields()) { String name = field.getName().orElse("_col" + columnNumber); names.add(name); int fieldIndex = outputDescriptor.indexOf(field); Symbol symbol = plan.getSymbol(fieldIndex); outputs.add(symbol); columnNumber++; } return new OutputNode(idAllocator.getNextId(), plan.getRoot(), names.build(), outputs.build()); }
public PlanNode planStatement(Analysis analysis, Statement statement) { if (statement instanceof CreateTableAsSelect && analysis.isCreateTableAsSelectNoOp()) { checkState(analysis.getCreateTableDestination().isPresent(), "Table destination is missing"); Symbol symbol = symbolAllocator.newSymbol("rows", BIGINT); PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(symbol), ImmutableList.of(ImmutableList.of(new LongLiteral("0")))); return new OutputNode(idAllocator.getNextId(), source, ImmutableList.of("rows"), ImmutableList.of(symbol)); } return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis); }
public OutputNode output(List<String> columnNames, List<Symbol> outputs, PlanNode source) { return new OutputNode( idAllocator.getNextId(), source, columnNames, outputs); }
protected OutputNode build() { return new OutputNode(idAllocator.getNextId(), source, columnNames, outputs); } }
@Override public PlanNode visitOutput(OutputNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); List<Symbol> canonical = Lists.transform(node.getOutputSymbols(), this::canonicalize); return new OutputNode(node.getId(), source, node.getColumnNames(), canonical); }
@Override public PlanNode visitOutput(OutputNode node, RewriteContext<Set<Symbol>> context) { Set<Symbol> expectedInputs = ImmutableSet.copyOf(node.getOutputSymbols()); PlanNode source = context.rewrite(node.getSource(), expectedInputs); return new OutputNode(node.getId(), source, node.getColumnNames(), node.getOutputSymbols()); }
@Test(expectedExceptions = IllegalStateException.class) public void testValidateFailed() { // random plan with 2 output nodes PlanNode root = new OutputNode(idAllocator.getNextId(), new ExplainAnalyzeNode(idAllocator.getNextId(), new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode( idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of() ), ImmutableList.of(), ImmutableList.of() ), new Symbol("a"), false), ImmutableList.of(), ImmutableList.of()); new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP); } }
@Test public void testValidateSuccessful() { // random seemingly valid plan PlanNode root = new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode( idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of() ), ImmutableList.of(), ImmutableList.of()); new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP); }
@Override public PlanNode visitOutput(OutputNode node, List<PlanNode> newChildren) { return new OutputNode(node.getId(), Iterables.getOnlyElement(newChildren), node.getColumnNames(), node.getOutputSymbols()); }
private PlanNode createOutputPlan(RelationPlan plan, Analysis analysis) { ImmutableList.Builder<Symbol> outputs = ImmutableList.builder(); ImmutableList.Builder<String> names = ImmutableList.builder(); int columnNumber = 0; RelationType outputDescriptor = analysis.getOutputDescriptor(); for (Field field : outputDescriptor.getVisibleFields()) { String name = field.getName().orElse("_col" + columnNumber); names.add(name); int fieldIndex = outputDescriptor.indexOf(field); Symbol symbol = plan.getSymbol(fieldIndex); outputs.add(symbol); columnNumber++; } return new OutputNode(idAllocator.getNextId(), plan.getRoot(), names.build(), outputs.build()); }
@Override public PlanNode visitOutput(OutputNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); List<Symbol> canonical = Lists.transform(node.getOutputSymbols(), this::canonicalize); return new OutputNode(node.getId(), source, node.getColumnNames(), canonical); }
@Override public PlanNode visitOutput(OutputNode node, RewriteContext<Set<Symbol>> context) { Set<Symbol> expectedInputs = ImmutableSet.copyOf(node.getOutputSymbols()); PlanNode source = context.rewrite(node.getSource(), expectedInputs); return new OutputNode(node.getId(), source, node.getColumnNames(), node.getOutputSymbols()); }
List<Expression> emptyRow = ImmutableList.of(); PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow)); root = new OutputNode(idAllocator.getNextId(), source, ImmutableList.of(), ImmutableList.of());