Search in sources :

Example 1 with RefreshMaterializedViewNode

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

the class LogicalPlanner method createRefreshMaterializedViewPlan.

private RelationPlan createRefreshMaterializedViewPlan(Analysis analysis) {
    Optional<QualifiedObjectName> delegatedRefreshMaterializedView = analysis.getDelegatedRefreshMaterializedView();
    if (delegatedRefreshMaterializedView.isPresent()) {
        return new RelationPlan(new RefreshMaterializedViewNode(idAllocator.getNextId(), delegatedRefreshMaterializedView.get()), analysis.getRootScope(), ImmutableList.of(), Optional.empty());
    }
    checkState(analysis.getRefreshMaterializedView().isPresent(), "RefreshMaterializedViewAnalysis handle is missing");
    Analysis.RefreshMaterializedViewAnalysis viewAnalysis = analysis.getRefreshMaterializedView().get();
    TableHandle tableHandle = viewAnalysis.getTarget();
    Query query = viewAnalysis.getQuery();
    Optional<TableLayout> newTableLayout = metadata.getInsertLayout(session, viewAnalysis.getTarget());
    TableWriterNode.RefreshMaterializedViewReference writerTarget = new TableWriterNode.RefreshMaterializedViewReference(viewAnalysis.getTable(), tableHandle, new ArrayList<>(analysis.getTables()));
    return getInsertPlan(analysis, viewAnalysis.getTable(), query, tableHandle, viewAnalysis.getColumns(), newTableLayout, Optional.of(writerTarget));
}
Also used : RefreshMaterializedViewNode(io.trino.sql.planner.plan.RefreshMaterializedViewNode) Query(io.trino.sql.tree.Query) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Analysis(io.trino.sql.analyzer.Analysis) TableHandle(io.trino.metadata.TableHandle) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) TableLayout(io.trino.metadata.TableLayout)

Aggregations

MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)1 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 TableHandle (io.trino.metadata.TableHandle)1 TableLayout (io.trino.metadata.TableLayout)1 Analysis (io.trino.sql.analyzer.Analysis)1 RefreshMaterializedViewNode (io.trino.sql.planner.plan.RefreshMaterializedViewNode)1 TableWriterNode (io.trino.sql.planner.plan.TableWriterNode)1 Query (io.trino.sql.tree.Query)1