Search in sources :

Example 1 with OutputNode

use of io.prestosql.sql.planner.plan.OutputNode in project hetu-core by openlookeng.

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@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);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 2 with OutputNode

use of io.prestosql.sql.planner.plan.OutputNode in project hetu-core by openlookeng.

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@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);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) ExplainAnalyzeNode(io.prestosql.sql.planner.plan.ExplainAnalyzeNode) Symbol(io.prestosql.spi.plan.Symbol) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 3 with OutputNode

use of io.prestosql.sql.planner.plan.OutputNode in project hetu-core by openlookeng.

the class SqlQueryExecution method handleCrossRegionDynamicFilter.

private void handleCrossRegionDynamicFilter(PlanRoot plan) {
    if (!isCrossRegionDynamicFilterEnabled(getSession()) || plan == null) {
        return;
    }
    StateStore stateStore = stateStoreProvider.getStateStore();
    if (stateStore == null) {
        return;
    }
    String queryId = getSession().getQueryId().getId();
    log.debug("queryId=%s begin to find columnToColumnMapping.", queryId);
    PlanNode outputNode = plan.getRoot().getFragment().getRoot();
    Map<String, Set<String>> columnToSymbolMapping = new HashMap<>();
    if (outputNode != null && outputNode instanceof OutputNode) {
        List<String> queryColumnNames = ((OutputNode) outputNode).getColumnNames();
        List<Symbol> outputSymbols = outputNode.getOutputSymbols();
        Map<String, Set<String>> tmpMapping = new HashMap<>(outputSymbols.size());
        for (Symbol symbol : outputNode.getOutputSymbols()) {
            Set<String> sets = new HashSet();
            sets.add(symbol.getName());
            tmpMapping.put(symbol.getName(), sets);
        }
        for (PlanFragment fragment : plan.getRoot().getAllFragments()) {
            if ("0".equals(fragment.getId().toString())) {
                continue;
            }
            PlanNode sourceNode = fragment.getRoot();
            findMappingFromPlan(tmpMapping, sourceNode);
        }
        for (int i = 0; i < outputSymbols.size(); i++) {
            columnToSymbolMapping.put(queryColumnNames.get(i), tmpMapping.get(outputSymbols.get(i).getName()));
        }
    }
    // save mapping into stateStore
    StateMap<String, Object> mappingStateMap = (StateMap<String, Object>) stateStore.getOrCreateStateCollection(CROSS_REGION_DYNAMIC_FILTERS, StateCollection.Type.MAP);
    mappingStateMap.put(queryId + QUERY_COLUMN_NAME_TO_SYMBOL_MAPPING, columnToSymbolMapping);
    log.debug("queryId=%s, add columnToSymbolMapping into hazelcast success.", queryId + QUERY_COLUMN_NAME_TO_SYMBOL_MAPPING);
}
Also used : OutputNode(io.prestosql.sql.planner.plan.OutputNode) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) StateMap(io.prestosql.spi.statestore.StateMap) StateStore(io.prestosql.spi.statestore.StateStore) PlanFragment(io.prestosql.sql.planner.PlanFragment) PlanNode(io.prestosql.spi.plan.PlanNode) HashSet(java.util.HashSet)

Example 4 with OutputNode

use of io.prestosql.sql.planner.plan.OutputNode in project hetu-core by openlookeng.

the class LogicalPlanner method planStatement.

public PlanNode planStatement(Analysis analysis, Statement statement) {
    if ((statement instanceof CreateTableAsSelect) && analysis.isCreateTableAsSelectNoOp()) {
        checkState(analysis.getCreateTableDestination().isPresent(), "Table destination is missing");
        Symbol symbol = planSymbolAllocator.newSymbol("rows", BIGINT);
        PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(symbol), ImmutableList.of(ImmutableList.of(new ConstantExpression(0L, BIGINT))));
        return new OutputNode(idAllocator.getNextId(), source, ImmutableList.of("rows"), ImmutableList.of(symbol));
    }
    return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) OutputNode(io.prestosql.sql.planner.plan.OutputNode) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) ConstantExpression(io.prestosql.spi.relation.ConstantExpression)

Example 5 with OutputNode

use of io.prestosql.sql.planner.plan.OutputNode in project hetu-core by openlookeng.

the class LogicalPlanner method createOutputPlan.

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());
}
Also used : Field(io.prestosql.sql.analyzer.Field) OutputNode(io.prestosql.sql.planner.plan.OutputNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) RelationType(io.prestosql.sql.analyzer.RelationType)

Aggregations

OutputNode (io.prestosql.sql.planner.plan.OutputNode)6 PlanNode (io.prestosql.spi.plan.PlanNode)4 Symbol (io.prestosql.spi.plan.Symbol)4 ValuesNode (io.prestosql.spi.plan.ValuesNode)3 ProjectNode (io.prestosql.spi.plan.ProjectNode)2 Test (org.testng.annotations.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 PlanNodeStatsEstimate (io.prestosql.cost.PlanNodeStatsEstimate)1 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)1 StateMap (io.prestosql.spi.statestore.StateMap)1 StateStore (io.prestosql.spi.statestore.StateStore)1 Field (io.prestosql.sql.analyzer.Field)1 RelationType (io.prestosql.sql.analyzer.RelationType)1 Plan (io.prestosql.sql.planner.Plan)1 PlanFragment (io.prestosql.sql.planner.PlanFragment)1 ExplainAnalyzeNode (io.prestosql.sql.planner.plan.ExplainAnalyzeNode)1 CreateTableAsSelect (io.prestosql.sql.tree.CreateTableAsSelect)1 HashMap (java.util.HashMap)1