Search in sources :

Example 16 with Analysis

use of io.trino.sql.analyzer.Analysis 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)

Example 17 with Analysis

use of io.trino.sql.analyzer.Analysis in project trino by trinodb.

the class LogicalPlanner method createInsertPlan.

private RelationPlan createInsertPlan(Analysis analysis, Insert insertStatement) {
    Analysis.Insert insert = analysis.getInsert().orElseThrow();
    TableHandle tableHandle = insert.getTarget();
    Query query = insertStatement.getQuery();
    Optional<TableLayout> newTableLayout = insert.getNewTableLayout();
    return getInsertPlan(analysis, insert.getTable(), query, tableHandle, insert.getColumns(), newTableLayout, Optional.empty());
}
Also used : Query(io.trino.sql.tree.Query) Analysis(io.trino.sql.analyzer.Analysis) TableHandle(io.trino.metadata.TableHandle) TableLayout(io.trino.metadata.TableLayout)

Aggregations

Analysis (io.trino.sql.analyzer.Analysis)17 Expression (io.trino.sql.tree.Expression)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 Session (io.trino.Session)11 TableHandle (io.trino.metadata.TableHandle)11 Query (io.trino.sql.tree.Query)11 List (java.util.List)11 Objects.requireNonNull (java.util.Objects.requireNonNull)11 Optional (java.util.Optional)11 PlannerContext (io.trino.sql.PlannerContext)10 PlanBuilder.newPlanBuilder (io.trino.sql.planner.PlanBuilder.newPlanBuilder)10 PlanNode (io.trino.sql.planner.plan.PlanNode)10 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)10 NodeRef (io.trino.sql.tree.NodeRef)10 Map (java.util.Map)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)9 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)9 ColumnHandle (io.trino.spi.connector.ColumnHandle)9