Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.trino.metadata.ViewColumn;
import io.trino.security.AccessControl;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition.WhenStaleBehavior;
import io.trino.spi.type.Type;
import io.trino.sql.PlannerContext;
import io.trino.sql.analyzer.Analysis;
Expand Down Expand Up @@ -55,6 +56,7 @@
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.spi.StandardErrorCode.TYPE_MISMATCH;
import static io.trino.spi.connector.ConnectorCapabilities.MATERIALIZED_VIEW_GRACE_PERIOD;
import static io.trino.spi.connector.ConnectorCapabilities.MATERIALIZED_VIEW_WHEN_STALE_BEHAVIOR;
import static io.trino.sql.SqlFormatterUtil.getFormattedSql;
import static io.trino.sql.analyzer.ConstantEvaluator.evaluateConstant;
import static io.trino.sql.analyzer.SemanticExceptions.semanticException;
Expand Down Expand Up @@ -156,12 +158,21 @@ Analysis executeInternal(
return Duration.ofMillis(milliseconds);
});

Optional<WhenStaleBehavior> whenStale = statement.getWhenStaleBehavior()
.map(_ -> {
if (!plannerContext.getMetadata().getConnectorCapabilities(session, catalogHandle).contains(MATERIALIZED_VIEW_WHEN_STALE_BEHAVIOR)) {
throw semanticException(NOT_SUPPORTED, statement, "Catalog '%s' does not support WHEN STALE", catalogName);
}
Comment on lines +163 to +165
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should catalogs need to handle anything in order to support it ? If it is some sort of MV property (like security mode in case of views) - It should be supported for all connectors supporting MVs right ? Or we could fail during the creation or alter phase ?

throw semanticException(NOT_SUPPORTED, statement, "WHEN STALE is not supported yet");
});

MaterializedViewDefinition definition = new MaterializedViewDefinition(
sql,
session.getCatalog(),
session.getSchema(),
columns,
gracePeriod,
whenStale,
statement.getComment(),
session.getIdentity(),
session.getPath().getPath().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.trino.spi.connector.CatalogSchemaName;
import io.trino.spi.connector.CatalogSchemaTableName;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition.WhenStaleBehavior;
import io.trino.spi.security.Identity;

import java.time.Duration;
Expand All @@ -31,6 +32,7 @@ public class MaterializedViewDefinition
extends ViewDefinition
{
private final Optional<Duration> gracePeriod;
private final Optional<WhenStaleBehavior> whenStaleBehavior;
private final Optional<CatalogSchemaTableName> storageTable;

public MaterializedViewDefinition(
Expand All @@ -39,6 +41,7 @@ public MaterializedViewDefinition(
Optional<String> schema,
List<ViewColumn> columns,
Optional<Duration> gracePeriod,
Optional<WhenStaleBehavior> whenStaleBehavior,
Optional<String> comment,
Identity owner,
List<CatalogSchemaName> path,
Expand All @@ -47,6 +50,7 @@ public MaterializedViewDefinition(
super(originalSql, catalog, schema, columns, comment, Optional.of(owner), path);
this.gracePeriod = requireNonNull(gracePeriod, "gracePeriod is null");
checkArgument(gracePeriod.isEmpty() || !gracePeriod.get().isNegative(), "gracePeriod cannot be negative: %s", gracePeriod);
this.whenStaleBehavior = requireNonNull(whenStaleBehavior, "whenStaleBehavior is null");
this.storageTable = requireNonNull(storageTable, "storageTable is null");
}

Expand All @@ -55,6 +59,11 @@ public Optional<Duration> getGracePeriod()
return gracePeriod;
}

public Optional<WhenStaleBehavior> getWhenStaleBehavior()
{
return whenStaleBehavior;
}

public Optional<CatalogSchemaTableName> getStorageTable()
{
return storageTable;
Expand All @@ -71,6 +80,7 @@ public ConnectorMaterializedViewDefinition toConnectorMaterializedViewDefinition
.map(column -> new ConnectorMaterializedViewDefinition.Column(column.name(), column.type(), column.comment()))
.collect(toImmutableList()),
getGracePeriod(),
whenStaleBehavior,
getComment(),
getRunAsIdentity().map(Identity::getUser),
getPath());
Expand All @@ -85,6 +95,7 @@ public String toString()
.add("schema", getSchema().orElse(null))
.add("columns", getColumns())
.add("gracePeriod", gracePeriod.orElse(null))
.add("whenStaleBehavior", whenStaleBehavior.orElse(null))
.add("comment", getComment().orElse(null))
.add("runAsIdentity", getRunAsIdentity())
.add("path", getPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,7 @@ private static MaterializedViewDefinition createMaterializedViewDefinition(Conne
.map(column -> new ViewColumn(column.getName(), column.getType(), Optional.empty()))
.collect(toImmutableList()),
view.getGracePeriod(),
view.getWhenStaleBehavior(),
view.getComment(),
runAsIdentity,
view.getPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,6 @@ protected Scope visitCreateMaterializedView(CreateMaterializedView node, Optiona
throw semanticException(NOT_SUPPORTED, node, "'CREATE OR REPLACE' and 'IF NOT EXISTS' clauses can not be used together");
}
node.getGracePeriod().ifPresent(gracePeriod -> analyzeExpression(gracePeriod, Scope.create()));
if (node.getWhenStaleBehavior().isPresent()) {
throw new TrinoException(NOT_SUPPORTED, "WHEN STALE is not supported yet");
}

// analyze the query that creates the view
StatementAnalyzer analyzer = statementAnalyzerFactory.createStatementAnalyzer(analysis, session, warningCollector, CorrelationSupport.ALLOWED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ protected MaterializedViewDefinition someMaterializedView(String sql, List<ViewC
columns,
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("owner"),
ImmutableList.of(),
Optional.empty());
Expand Down Expand Up @@ -553,6 +554,7 @@ public void setMaterializedViewColumnComment(Session session, QualifiedObjectNam
.map(currentViewColumn -> columnName.equals(currentViewColumn.name()) ? new ViewColumn(currentViewColumn.name(), currentViewColumn.type(), comment) : currentViewColumn)
.collect(toImmutableList()),
view.getGracePeriod(),
view.getWhenStaleBehavior(),
view.getComment(),
view.getRunAsIdentity().get(),
view.getPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7889,6 +7889,7 @@ public void setup()
Optional.of("s1"),
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.of("comment"),
Identity.ofUser("user"),
ImmutableList.of(),
Expand Down Expand Up @@ -8019,6 +8020,7 @@ public void setup()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TPCH_CATALOG, "s1", "t1"))),
Expand Down Expand Up @@ -8073,6 +8075,7 @@ public void setup()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("b", BIGINT.getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
// t3 has a, b column and hidden column x
Expand All @@ -8093,6 +8096,7 @@ public void setup()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TPCH_CATALOG, "s1", "t2"))),
Expand All @@ -8112,6 +8116,7 @@ public void setup()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("c", BIGINT.getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TPCH_CATALOG, "s1", "t2"))),
Expand All @@ -8131,6 +8136,7 @@ public void setup()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("b", RowType.anonymousRow(TINYINT).getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TPCH_CATALOG, "s1", "t2"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ protected PlanTester createPlanTester()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("b", BIGINT.getTypeId(), Optional.empty())),
Optional.of(STALE_MV_STALENESS.plusHours(1)),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TEST_CATALOG_NAME, SCHEMA, "storage_table")));
Expand Down Expand Up @@ -223,6 +224,7 @@ protected PlanTester createPlanTester()
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("b", BIGINT.getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TEST_CATALOG_NAME, SCHEMA, "storage_table_with_casts")));
Expand Down Expand Up @@ -257,6 +259,7 @@ protected PlanTester createPlanTester()
ImmutableList.of(new ViewColumn("id", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("ts", timestampWithTimezone3.getTypeId(), Optional.empty())),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TEST_CATALOG_NAME, SCHEMA, "timestamp_test_storage")));
Expand Down Expand Up @@ -288,6 +291,7 @@ private void createMaterializedView(String materializedViewName, String query)
ImmutableList.of(new ViewColumn("a", BIGINT.getTypeId(), Optional.empty()), new ViewColumn("b", BIGINT.getTypeId(), Optional.empty())),
Optional.of(STALE_MV_STALENESS.plusHours(1)),
Optional.empty(),
Optional.empty(),
Identity.ofUser("some user"),
ImmutableList.of(),
Optional.of(new CatalogSchemaTableName(TEST_CATALOG_NAME, SCHEMA, "storage_table")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public TestColumnMask()
new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.empty(),
Optional.of(VIEW_OWNER),
ImmutableList.of());

Expand All @@ -148,6 +149,7 @@ public TestColumnMask()
new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.empty(),
Optional.of(VIEW_OWNER),
ImmutableList.of());

Expand All @@ -163,6 +165,7 @@ public TestColumnMask()
new ConnectorMaterializedViewDefinition.Column("comment", VarcharType.createVarcharType(152).getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.empty(),
Optional.of(VIEW_OWNER),
ImmutableList.of());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static ConnectorMaterializedViewDefinition someMaterializedView()
ImmutableList.of(new Column("test", BIGINT.getTypeId(), Optional.empty())),
Optional.of(Duration.ZERO),
Optional.empty(),
Optional.empty(),
Optional.of("owner"),
ImmutableList.of());
}
Expand Down
5 changes: 5 additions & 0 deletions core/trino-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@
<old>method void io.trino.spi.eventlistener.QueryStatistics::&lt;init&gt;(java.time.Duration, java.time.Duration, java.time.Duration, java.time.Duration, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, long, long, long, long, long, long, long, long, long, long, long, long, long, long, double, double, java.util.List&lt;io.trino.spi.eventlistener.StageGcStatistics&gt;, int, boolean, java.util.List&lt;io.trino.spi.eventlistener.StageCpuDistribution&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageOutputBufferUtilization&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageOutputBufferMetrics&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageTaskStatistics&gt;, java.util.List&lt;io.trino.spi.eventlistener.DynamicFilterDomainStatistics&gt;, java.util.function.Supplier&lt;java.util.List&lt;java.lang.String&gt;&gt;, java.util.List&lt;io.trino.spi.eventlistener.QueryPlanOptimizerStatistics&gt;, java.util.Map&lt;java.lang.String, io.trino.spi.metrics.Metrics&gt;, java.util.Optional&lt;java.lang.String&gt;)</old>
<new>method void io.trino.spi.eventlistener.QueryStatistics::&lt;init&gt;(java.time.Duration, java.time.Duration, java.time.Duration, java.time.Duration, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.time.Duration&gt;, long, long, long, long, long, long, long, long, long, long, long, long, long, long, double, double, java.util.List&lt;io.trino.spi.eventlistener.StageGcStatistics&gt;, int, boolean, java.util.List&lt;io.trino.spi.eventlistener.StageCpuDistribution&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageOutputBufferUtilization&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageOutputBufferMetrics&gt;, java.util.List&lt;io.trino.spi.eventlistener.StageTaskStatistics&gt;, java.util.List&lt;io.trino.spi.eventlistener.DynamicFilterDomainStatistics&gt;, java.util.function.Supplier&lt;java.util.List&lt;java.lang.String&gt;&gt;, java.util.List&lt;io.trino.spi.eventlistener.QueryPlanOptimizerStatistics&gt;, java.util.Map&lt;java.lang.String, io.trino.spi.metrics.Metrics&gt;, java.util.Optional&lt;java.lang.String&gt;)</new>
</item>
<item>
<code>java.method.numberOfParametersChanged</code>
<old>method void io.trino.spi.connector.ConnectorMaterializedViewDefinition::&lt;init&gt;(java.lang.String, java.util.Optional&lt;io.trino.spi.connector.CatalogSchemaTableName&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.List&lt;io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.List&lt;io.trino.spi.connector.CatalogSchemaName&gt;)</old>
<new>method void io.trino.spi.connector.ConnectorMaterializedViewDefinition::&lt;init&gt;(java.lang.String, java.util.Optional&lt;io.trino.spi.connector.CatalogSchemaTableName&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.List&lt;io.trino.spi.connector.ConnectorMaterializedViewDefinition.Column&gt;, java.util.Optional&lt;java.time.Duration&gt;, java.util.Optional&lt;io.trino.spi.connector.ConnectorMaterializedViewDefinition.WhenStaleBehavior&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.Optional&lt;java.lang.String&gt;, java.util.List&lt;io.trino.spi.connector.CatalogSchemaName&gt;)</new>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public enum ConnectorCapabilities
DEFAULT_COLUMN_VALUE,
NOT_NULL_COLUMN_CONSTRAINT,
MATERIALIZED_VIEW_GRACE_PERIOD,
MATERIALIZED_VIEW_WHEN_STALE_BEHAVIOR,
}
Loading