Search in sources :

Example 1 with TableExecuteNode

use of io.trino.sql.planner.plan.TableExecuteNode 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())))));
}
Also used : TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNode(io.trino.sql.planner.plan.PlanNode) Row(io.trino.sql.tree.Row) NullLiteral(io.trino.sql.tree.NullLiteral)

Example 2 with TableExecuteNode

use of io.trino.sql.planner.plan.TableExecuteNode in project trino by trinodb.

the class TableExecuteMatcher 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());
    TableExecuteNode tableExecuteNode = (TableExecuteNode) node;
    if (!tableExecuteNode.getColumnNames().equals(columnNames)) {
        return NO_MATCH;
    }
    if (!columns.stream().map(symbol -> Symbol.from(symbolAliases.get(symbol))).collect(toImmutableList()).equals(tableExecuteNode.getColumns())) {
        return NO_MATCH;
    }
    return match();
}
Also used : TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) Symbol(io.trino.sql.planner.Symbol) TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) List(java.util.List) MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Metadata(io.trino.metadata.Metadata) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.trino.cost.StatsProvider) Session(io.trino.Session) PlanNode(io.trino.sql.planner.plan.PlanNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Preconditions.checkState(com.google.common.base.Preconditions.checkState)

Example 3 with TableExecuteNode

use of io.trino.sql.planner.plan.TableExecuteNode in project trino by trinodb.

the class LogicalPlanner method createTableExecutePlan.

private RelationPlan createTableExecutePlan(Analysis analysis, TableExecute statement) {
    Table table = statement.getTable();
    TableHandle tableHandle = analysis.getTableHandle(table);
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, table.getName());
    TableExecuteHandle executeHandle = analysis.getTableExecuteHandle().orElseThrow();
    RelationPlan tableScanPlan = createRelationPlan(analysis, table);
    PlanBuilder sourcePlanBuilder = newPlanBuilder(tableScanPlan, analysis, ImmutableMap.of(), ImmutableMap.of());
    if (statement.getWhere().isPresent()) {
        SubqueryPlanner subqueryPlanner = new SubqueryPlanner(analysis, symbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, symbolAllocator), plannerContext, typeCoercion, Optional.empty(), session, ImmutableMap.of());
        Expression whereExpression = statement.getWhere().get();
        sourcePlanBuilder = subqueryPlanner.handleSubqueries(sourcePlanBuilder, whereExpression, analysis.getSubqueries(statement));
        sourcePlanBuilder = sourcePlanBuilder.withNewRoot(new FilterNode(idAllocator.getNextId(), sourcePlanBuilder.getRoot(), sourcePlanBuilder.rewrite(whereExpression)));
    }
    PlanNode sourcePlanRoot = sourcePlanBuilder.getRoot();
    TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
    List<String> columnNames = tableMetadata.getColumns().stream().filter(// todo this filter is redundant
    column -> !column.isHidden()).map(ColumnMetadata::getName).collect(toImmutableList());
    TableWriterNode.TableExecuteTarget tableExecuteTarget = new TableWriterNode.TableExecuteTarget(executeHandle, Optional.empty(), tableName.asSchemaTableName());
    Optional<TableLayout> layout = metadata.getLayoutForTableExecute(session, executeHandle);
    List<Symbol> symbols = visibleFields(tableScanPlan);
    // todo extract common method to be used here and in createTableWriterPlan()
    Optional<PartitioningScheme> partitioningScheme = Optional.empty();
    Optional<PartitioningScheme> preferredPartitioningScheme = Optional.empty();
    if (layout.isPresent()) {
        List<Symbol> partitionFunctionArguments = new ArrayList<>();
        layout.get().getPartitionColumns().stream().mapToInt(columnNames::indexOf).mapToObj(symbols::get).forEach(partitionFunctionArguments::add);
        List<Symbol> outputLayout = new ArrayList<>(symbols);
        Optional<PartitioningHandle> partitioningHandle = layout.get().getPartitioning();
        if (partitioningHandle.isPresent()) {
            partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(partitioningHandle.get(), partitionFunctionArguments), outputLayout));
        } else {
            // empty connector partitioning handle means evenly partitioning on partitioning columns
            preferredPartitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, partitionFunctionArguments), outputLayout));
        }
    }
    verify(columnNames.size() == symbols.size(), "columnNames.size() != symbols.size(): %s and %s", columnNames, symbols);
    TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), new TableExecuteNode(idAllocator.getNextId(), sourcePlanRoot, tableExecuteTarget, symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY), symbols, columnNames, partitioningScheme, preferredPartitioningScheme), tableExecuteTarget, symbolAllocator.newSymbol("rows", BIGINT), Optional.empty(), Optional.empty());
    return new RelationPlan(commitNode, analysis.getRootScope(), commitNode.getOutputSymbols(), Optional.empty());
}
Also used : TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) FilterNode(io.trino.sql.planner.plan.FilterNode) ArrayList(java.util.ArrayList) TableExecuteHandle(io.trino.metadata.TableExecuteHandle) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder) PlanNode(io.trino.sql.planner.plan.PlanNode) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) TableLayout(io.trino.metadata.TableLayout) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) TableMetadata(io.trino.metadata.TableMetadata) Table(io.trino.sql.tree.Table) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) TableHandle(io.trino.metadata.TableHandle)

Aggregations

PlanNode (io.trino.sql.planner.plan.PlanNode)3 TableExecuteNode (io.trino.sql.planner.plan.TableExecuteNode)3 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Session (io.trino.Session)1 StatsProvider (io.trino.cost.StatsProvider)1 Metadata (io.trino.metadata.Metadata)1 MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 TableExecuteHandle (io.trino.metadata.TableExecuteHandle)1 TableHandle (io.trino.metadata.TableHandle)1 TableLayout (io.trino.metadata.TableLayout)1 TableMetadata (io.trino.metadata.TableMetadata)1 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)1 PlanBuilder.newPlanBuilder (io.trino.sql.planner.PlanBuilder.newPlanBuilder)1 Symbol (io.trino.sql.planner.Symbol)1 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)1 MatchResult.match (io.trino.sql.planner.assertions.MatchResult.match)1 FilterNode (io.trino.sql.planner.plan.FilterNode)1