Search in sources :

Example 1 with CreateReference

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

the class LogicalPlanner method createTableCreationPlan.

private RelationPlan createTableCreationPlan(Analysis analysis, Query query) {
    Analysis.Create create = analysis.getCreate().orElseThrow();
    QualifiedObjectName destination = create.getDestination().orElseThrow();
    RelationPlan plan = createRelationPlan(analysis, query);
    if (!create.isCreateTableAsSelectWithData()) {
        PlanNode root = new LimitNode(idAllocator.getNextId(), plan.getRoot(), 0L, false);
        plan = new RelationPlan(root, plan.getScope(), plan.getFieldMappings(), Optional.empty());
    }
    ConnectorTableMetadata tableMetadata = create.getMetadata().orElseThrow();
    Optional<TableLayout> newTableLayout = create.getLayout();
    List<String> columnNames = tableMetadata.getColumns().stream().filter(// todo this filter is redundant
    column -> !column.isHidden()).map(ColumnMetadata::getName).collect(toImmutableList());
    TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, destination.getCatalogName(), tableMetadata);
    return createTableWriterPlan(analysis, plan.getRoot(), visibleFields(plan), new CreateReference(destination.getCatalogName(), tableMetadata, newTableLayout), columnNames, tableMetadata.getColumns(), newTableLayout, statisticsMetadata);
}
Also used : TableStatisticsMetadata(io.trino.spi.statistics.TableStatisticsMetadata) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) PlanNode(io.trino.sql.planner.plan.PlanNode) LimitNode(io.trino.sql.planner.plan.LimitNode) Analysis(io.trino.sql.analyzer.Analysis) CreateReference(io.trino.sql.planner.plan.TableWriterNode.CreateReference) TableLayout(io.trino.metadata.TableLayout) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata)

Aggregations

MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 TableLayout (io.trino.metadata.TableLayout)1 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)1 TableStatisticsMetadata (io.trino.spi.statistics.TableStatisticsMetadata)1 Analysis (io.trino.sql.analyzer.Analysis)1 LimitNode (io.trino.sql.planner.plan.LimitNode)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 CreateReference (io.trino.sql.planner.plan.TableWriterNode.CreateReference)1