Skip to content
Merged
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 @@ -6071,16 +6071,16 @@ private Optional<TableVersion> extractTableVersion(Table table, Optional<Express
if (version.isEmpty()) {
return tableVersion;
}
if (analysis.isDescribe()) {
throw semanticException(NOT_SUPPORTED, table, "DESCRIBE is not supported if a versioned table uses parameters");
}
ExpressionAnalysis expressionAnalysis = analyzeExpression(version.get(), scope.get());
analysis.recordSubqueries(table, expressionAnalysis);

// Once the range value is analyzed, we can evaluate it
Type versionType = expressionAnalysis.getType(version.get());
PointerType pointerType = toPointerType(table.getQueryPeriod().get().getRangeType());
if (versionType == UNKNOWN) {
if (analysis.isDescribe()) {
throw semanticException(NOT_SUPPORTED, table, "DESCRIBE is not supported if a versioned table uses parameters");
}
throw semanticException(INVALID_ARGUMENTS, table.getQueryPeriod().get(), "Pointer value cannot be NULL");
}
Object evaluatedVersion = evaluateConstant(version.get(), versionType, analysis.getParameters(), plannerContext, session, accessControl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7948,6 +7948,32 @@ public void testPreparedStatementWithParameterizedVersionedTable()
assertQueryFails(session, "DESCRIBE OUTPUT my_query", ".* DESCRIBE is not supported if a versioned table uses parameters");
Comment thread
ebyhr marked this conversation as resolved.
}

@Test
public void testDescribeOutputWithVersionedTable()
{
try (TestTable table = newTrinoTable("test", "(x int)", List.of("1"))) {
Session firstSession = Session.builder(getSession())
.addPreparedStatement("my_query", "SELECT * FROM %s FOR VERSION AS OF %s".formatted(table.getName(), getCurrentSnapshotId(table.getName())))
Comment thread
ebyhr marked this conversation as resolved.
.build();
assertThat(query(firstSession, "DESCRIBE OUTPUT my_query"))
Comment thread
ebyhr marked this conversation as resolved.
.matches("VALUES ('x', 'iceberg', 'tpch', '" + table.getName() + "', 'integer', 4, false)");

// Add a new snapshot with a new column for a different output
assertUpdate("ALTER TABLE " + table.getName() + " ADD COLUMN y int");
assertUpdate("INSERT INTO " + table.getName() + " VALUES (2, 2)", 1);

Session secondSession = Session.builder(getSession())
.addPreparedStatement("my_query", "SELECT * FROM %s FOR VERSION AS OF %s".formatted(table.getName(), getCurrentSnapshotId(table.getName())))
.build();
assertThat(query(firstSession, "DESCRIBE OUTPUT my_query"))
.matches("VALUES ('x', 'iceberg', 'tpch', '" + table.getName() + "', 'integer', 4, false)");
assertThat(query(secondSession, "DESCRIBE OUTPUT my_query"))
.matches("VALUES" +
"('x', 'iceberg', 'tpch', '" + table.getName() + "', 'integer', 4, false)," +
"('y', 'iceberg', 'tpch', '" + table.getName() + "', 'integer', 4, false)");
}
}

@Test
public void testDeleteRetainsTableHistory()
{
Expand Down