Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -176,6 +176,7 @@
import io.trino.sql.tree.Identifier;
import io.trino.sql.tree.Insert;
import io.trino.sql.tree.Intersect;
import io.trino.sql.tree.IntervalLiteral;
import io.trino.sql.tree.Join;
import io.trino.sql.tree.JoinCriteria;
import io.trino.sql.tree.JoinOn;
Expand Down Expand Up @@ -338,6 +339,7 @@
import static io.trino.spi.StandardErrorCode.INVALID_COPARTITIONING;
import static io.trino.spi.StandardErrorCode.INVALID_DEFAULT_COLUMN_VALUE;
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static io.trino.spi.StandardErrorCode.INVALID_GRACE_PERIOD;
import static io.trino.spi.StandardErrorCode.INVALID_LIMIT_CLAUSE;
import static io.trino.spi.StandardErrorCode.INVALID_ORDER_BY;
import static io.trino.spi.StandardErrorCode.INVALID_PARTITION_BY;
Expand Down Expand Up @@ -1478,7 +1480,12 @@ protected Scope visitCreateMaterializedView(CreateMaterializedView node, Optiona
if (node.isReplace() && node.isNotExists()) {
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()));
node.getGracePeriod().ifPresent(gracePeriod -> {
if (gracePeriod.getSign() == IntervalLiteral.Sign.NEGATIVE) {
throw semanticException(INVALID_GRACE_PERIOD, gracePeriod, "Grace period cannot be negative");
}
analyzeExpression(gracePeriod, Scope.create());
});

// 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 @@ -141,6 +141,7 @@
import static io.trino.spi.StandardErrorCode.INVALID_COLUMN_REFERENCE;
import static io.trino.spi.StandardErrorCode.INVALID_COPARTITIONING;
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static io.trino.spi.StandardErrorCode.INVALID_GRACE_PERIOD;
import static io.trino.spi.StandardErrorCode.INVALID_LABEL;
import static io.trino.spi.StandardErrorCode.INVALID_LIMIT_CLAUSE;
import static io.trino.spi.StandardErrorCode.INVALID_LITERAL;
Expand Down Expand Up @@ -5833,6 +5834,15 @@ public void testAnalyzeMaterializedViewWithAccessControl()
.hasMessage("Access Denied: Cannot select from columns [a, b] in table or view tpch.s1.fresh_materialized_view");
}

@Test
public void testCreateMaterializedViewWithNegativeGracePeriod()
{
assertFails("CREATE MATERIALIZED VIEW mv_negative_grace_period GRACE PERIOD INTERVAL -'1' HOUR AS SELECT * FROM nation")
.hasErrorCode(INVALID_GRACE_PERIOD)
.hasMessage("line 1:64: Grace period cannot be negative")
.hasLocation(1, 64);
}

@Test
public void testJsonContextItemType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public enum StandardErrorCode
BRANCH_ALREADY_EXISTS(135, USER_ERROR),
INVALID_BRANCH_PROPERTY(136, USER_ERROR),
INVALID_DEFAULT_COLUMN_VALUE(137, USER_ERROR),
INVALID_GRACE_PERIOD(138, USER_ERROR),

GENERIC_INTERNAL_ERROR(65536, INTERNAL_ERROR),
TOO_MANY_REQUESTS_FAILED(65537, INTERNAL_ERROR),
Expand Down