From bc09834157d0d36bf6ed54f549c5313daac8f4ef Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 7 Jun 2022 12:20:02 +0200 Subject: [PATCH] Disallow null table version It probably does not have any practical use, so it is safer to just disallow it, so that connectors do not have to check for (the rather unexpected) null. Note that `NULL` version (without a CAST) was not supported anyway. --- .../trino/sql/analyzer/StatementAnalyzer.java | 9 +++++++++ .../io/trino/sql/analyzer/TestAnalyzer.java | 20 +++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index 30a82fcd38c9..dd39d06dabe0 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -4573,6 +4573,7 @@ private Optional extractTableVersion(Table table, QualifiedObjectN private void validateVersionPointer(QualifiedObjectName tableName, QueryPeriod queryPeriod, TableVersion extractedVersion) { Type type = extractedVersion.getObjectType(); + Object pointer = extractedVersion.getPointer(); if (extractedVersion.getPointerType() == PointerType.TEMPORAL) { // Before checking if the connector supports the version type, verify that version is a valid time-based type if (!(type instanceof TimestampWithTimeZoneType || @@ -4582,6 +4583,14 @@ private void validateVersionPointer(QualifiedObjectName tableName, QueryPeriod q "Type %s invalid. Temporal pointers must be of type Timestamp, Timestamp with Time Zone, or Date.", type.getDisplayName())); } + if (pointer == null) { + throw semanticException(INVALID_ARGUMENTS, queryPeriod, "Pointer value cannot be NULL"); + } + } + else { + if (pointer == null) { + throw semanticException(INVALID_ARGUMENTS, queryPeriod, "Pointer value cannot be NULL"); + } } if (!metadata.isValidTableVersion(session, tableName, extractedVersion)) { diff --git a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java index 28a54c567add..048c44774f72 100644 --- a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java +++ b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java @@ -402,14 +402,14 @@ public void testTemporalTableVersion() // null value with right type assertFails("SELECT * FROM t1 FOR TIMESTAMP AS OF CAST(NULL AS date)") - .hasErrorCode(NOT_SUPPORTED) - .hasMessage("This connector does not support versioned tables"); + .hasErrorCode(INVALID_ARGUMENTS) + .hasMessage("line 1:18: Pointer value cannot be NULL"); assertFails("SELECT * FROM t1 FOR TIMESTAMP AS OF CAST(NULL AS timestamp(3))") - .hasErrorCode(NOT_SUPPORTED) - .hasMessage("This connector does not support versioned tables"); + .hasErrorCode(INVALID_ARGUMENTS) + .hasMessage("line 1:18: Pointer value cannot be NULL"); assertFails("SELECT * FROM t1 FOR TIMESTAMP AS OF CAST(NULL AS timestamp(3) with time zone)") - .hasErrorCode(NOT_SUPPORTED) - .hasMessage("This connector does not support versioned tables"); + .hasErrorCode(INVALID_ARGUMENTS) + .hasMessage("line 1:18: Pointer value cannot be NULL"); // null value with wrong type assertFails("SELECT * FROM t1 FOR TIMESTAMP AS OF NULL") @@ -448,11 +448,11 @@ public void testRangeIdTableVersion() .hasErrorCode(INVALID_ARGUMENTS) .hasMessage("line 1:18: Pointer value cannot be NULL"); assertFails("SELECT * FROM t1 FOR VERSION AS OF CAST(NULL AS bigint)") - .hasErrorCode(NOT_SUPPORTED) - .hasMessage("This connector does not support versioned tables"); + .hasErrorCode(INVALID_ARGUMENTS) + .hasMessage("line 1:18: Pointer value cannot be NULL"); assertFails("SELECT * FROM t1 FOR VERSION AS OF CAST(NULL AS varchar)") - .hasErrorCode(NOT_SUPPORTED) - .hasMessage("This connector does not support versioned tables"); + .hasErrorCode(INVALID_ARGUMENTS) + .hasMessage("line 1:18: Pointer value cannot be NULL"); } @Test