Skip to content

Commit c5ee12c

Browse files
morningmanGabriel39claude
committed
[test](iceberg) Port the branch-4.1 schema matrix assertions for joins, branch reads and DESC comments
### What problem does this PR solve? Issue Number: None Related PR: #66246, #66007, #66112 Problem Summary: branch-4.1 #66246 backported #66112, #66223 and #66007 and added test assertions that master never got. Master implements the behavior, but its tests either lack the checks or still assert an old, negative contract: - test_iceberg_schema_dual_relation_matrix: a historical relation joined with the latest relation of the same table, in either order, keeps each relation's own schema (old_name on the snapshot, new_name on the latest table). - test_iceberg_schema_time_travel_matrix: a branch read uses the table's current schema. Master only checked that the old name is unknown and that nested types are the promoted ones, and called both a leak. The suite now also reads the renamed and re-added fields from the branch head, which come back NULL instead of old values. - test_iceberg_schema_metadata_atomicity_matrix: with show_column_comment_in_describe enabled, DESC shows the top-level and nested Iceberg field comments. Master asserted that they were absent, which only held because the variable is off by default. - CreateTableCommandTest: an existing CTAS target fails with "already exists" before any sink is built. #67545 replaced this case with the configuration preflight case; it is added back next to that case. An audit of the rest of #66246 against master found no other missing test or behavior, apart from a deliberate difference in Hudi plain reads, which this change leaves alone. ### Release note None ### Check List (For Author) - Test: Regression test / Unit Test - The three suites pass on a local Iceberg docker environment against master. test_iceberg_schema_time_travel_matrix.out is generated by the regression script and has the same rows as on branch-4.2 - CreateTableCommandTest: all 4 cases pass - Behavior changed: No - Does this need documentation: No Co-authored-by: Gabriel <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 2524893 commit c5ee12c

5 files changed

Lines changed: 78 additions & 5 deletions

File tree

‎fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommandTest.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ void ctasValidatesSinkBeforePublishingMetadata() throws Exception {
100100
}
101101
}
102102

103+
@Test
104+
void existingCtasTargetPrecedesUnsupportedSinkValidation() throws Exception {
105+
LogicalPlan query = Mockito.mock(LogicalPlan.class);
106+
CreateTableInfo createTableInfo = Mockito.mock(CreateTableInfo.class);
107+
ConnectContext context = Mockito.mock(ConnectContext.class);
108+
StmtExecutor executor = Mockito.mock(StmtExecutor.class);
109+
Env env = Mockito.mock(Env.class);
110+
List<String> tableNameParts = ImmutableList.of("catalog", "database", "target");
111+
112+
Mockito.when(createTableInfo.getTableNameParts()).thenReturn(tableNameParts);
113+
Mockito.when(createTableInfo.getTableName()).thenReturn("target");
114+
CreateTableCommand command = Mockito.spy(
115+
new CreateTableCommand(Optional.of(query), createTableInfo));
116+
Mockito.doNothing().when(command).validateCreateTableAsSelect(context, query);
117+
Mockito.doNothing().when(command).validateCreateTableProperties(context);
118+
Mockito.doReturn(true).when(command).targetTableExists(context);
119+
120+
try (MockedStatic<Env> envMock = Mockito.mockStatic(Env.class);
121+
MockedStatic<UnboundTableSinkCreator> sinkMock =
122+
Mockito.mockStatic(UnboundTableSinkCreator.class)) {
123+
envMock.when(Env::getCurrentEnv).thenReturn(env);
124+
Exception exception = org.junit.jupiter.api.Assertions.assertThrows(
125+
Exception.class, () -> command.run(context, executor));
126+
127+
org.junit.jupiter.api.Assertions.assertTrue(exception.getMessage().contains("already exists"));
128+
sinkMock.verifyNoInteractions();
129+
Mockito.verify(env, Mockito.never()).createTable(createTableInfo);
130+
Mockito.verify(env, Mockito.never()).dropTable(
131+
Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
132+
Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean(),
133+
Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyBoolean());
134+
}
135+
}
136+
103137
@Test
104138
void ctasConfigurationPreflightPrecedesTargetLookup() throws Exception {
105139
LogicalPlan query = Mockito.mock(LogicalPlan.class);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !doris_nested_branch_current_schema --
3+
1 10 \N 100 \N 1000 \N
4+
5+
-- !top_branch_current_schema --
6+
1 alpha \N 10
7+

‎regression-test/suites/external_table_p0/iceberg/test_iceberg_schema_dual_relation_matrix.groovy‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ suite("test_iceberg_schema_dual_relation_matrix",
9393
order by id
9494
"""))
9595

96+
// Latest metadata must be restored even when a historical relation is bound first.
97+
assertEquals([[1, "old-1", "old-1"]], sql("""
98+
select h.id, h.old_name, l.new_name
99+
from ${tableName} for version as of ${oldSnapshot} h
100+
join ${tableName} l on h.id = l.id
101+
order by h.id
102+
"""))
103+
104+
// Binding the same pair in reverse order must preserve both relation-local schemas.
105+
assertEquals([[1, "old-1", "old-1"]], sql("""
106+
select l.id, l.new_name, h.old_name
107+
from ${tableName} l
108+
join ${tableName} for version as of ${oldSnapshot} h on l.id = h.id
109+
order by l.id
110+
"""))
111+
96112
// Scenario TC07-join: each historical relation binds and scans its OWN snapshot schema, so a
97113
// self-join across the rename resolves old_name (old snapshot) and new_name (new snapshot).
98114
assertEquals([[1, "old-1", "old-1"]], sql("""

‎regression-test/suites/external_table_p0/iceberg/test_iceberg_schema_metadata_atomicity_matrix.groovy‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ suite("test_iceberg_schema_metadata_atomicity_matrix",
5858
sql """switch ${catalogName}"""
5959
sql """create database if not exists ${dbName}"""
6060
sql """use ${dbName}"""
61+
// DESC hides comments by default, so enable them before validating Iceberg field docs.
62+
sql """set show_column_comment_in_describe=true"""
6163

6264
try {
6365
sql """drop table if exists ${tableName}"""
@@ -89,9 +91,8 @@ suite("test_iceberg_schema_metadata_atomicity_matrix",
8991
it == null ? "" : it.toString()
9092
}.join(" ")
9193
assertTrue(sparkDescriptionText.contains("top-level-comment"))
92-
// Negative contract: Doris DESC currently omits Iceberg field comments.
93-
assertFalse(descAfterComment.contains("top-level-comment"))
94-
assertFalse(descAfterComment.contains("nested-comment"))
94+
assertTrue(descAfterComment.contains("top-level-comment"))
95+
assertTrue(descAfterComment.contains("nested-comment"))
9596
assertEquals(initialSnapshots, snapshotCount())
9697

9798
// Scenario S19-nullability: relaxing required to optional preserves data and historical refs.

‎regression-test/suites/external_table_p0/iceberg/test_iceberg_schema_time_travel_matrix.groovy‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,22 @@ suite("test_iceberg_schema_time_travel_matrix",
443443
from ${dorisNestedTable}@tag(doris_nested_cp0)
444444
order by id
445445
"""))
446-
// Negative contract: an old branch currently leaks the latest BIGINT nested types.
446+
// A branch read uses the table's current schema, so an old branch reads the promoted BIGINT
447+
// nested types.
447448
assertEquals([[1, 10L, 100L, 1000L]],
448449
sql("""
449450
select id, info.metric, events[1].score, attrs['k'].code
450451
from ${dorisNestedTable}@branch(doris_nested_cp0_branch)
451452
order by id
452453
"""))
454+
// Named branches keep their head rows but expose renamed fields from the current schema.
455+
qt_doris_nested_branch_current_schema """
456+
select id, info.metric, info.renamed,
457+
events[1].score, events[1].renamed,
458+
attrs['k'].code, attrs['k'].renamed
459+
from ${dorisNestedTable}@branch(doris_nested_cp0_branch)
460+
order by id
461+
"""
453462
assertUnknownColumn("""
454463
select info.renamed
455464
from ${dorisNestedTable} for version as of ${dorisNestedCp0}
@@ -546,7 +555,8 @@ suite("test_iceberg_schema_time_travel_matrix",
546555
from ${topTable}@tag(top_cp0)
547556
order by id
548557
"""))
549-
// Negative contract: an old branch is currently analyzed with the latest rename schema.
558+
// A branch read uses the table's current schema, so the old name is unknown on an old branch
559+
// and the current names read the branch head rows.
550560
test {
551561
sql """
552562
select id, old_name, victim, metric
@@ -555,6 +565,11 @@ suite("test_iceberg_schema_time_travel_matrix",
555565
"""
556566
exception "Unknown column 'old_name'"
557567
}
568+
qt_top_branch_current_schema """
569+
select id, MixedName, victim, metric
570+
from ${topTable}@branch(top_cp0_branch)
571+
order by id
572+
"""
558573
assertUnknownColumn("""
559574
select MixedName from ${topTable} for version as of ${topCp0}
560575
""", "MixedName")

0 commit comments

Comments
 (0)