Skip to content

Commit 3265322

Browse files
committed
[fix](variant) Preserve dotted-key encoding in copy-tablet DDL
### Background ADMIN COPY TABLET generates a CREATE TABLE statement for reading a tablet snapshot at a specific version. The debug table must retain the source table's VARIANT key encoding. ### What problem does this PR solve? Issue Number: None Related PR: #69995 PR Type: Bugfix Problem Summary: Both specific-version DDL paths returned before emitting variant_escape_dots_in_keys. Reuse the normal DDL property renderer in both paths so debug tables preserve dotted-key lookup semantics. ### Details - **Frequency:** Copying a tablet from a table with variant_escape_dots_in_keys=true. - **Root cause:** The specific-version branches emit a reduced property list and bypass normal OLAP properties. - **Why existing tests missed it:** Copy-tablet DDL was not covered by the escaped-table property tests. - **Fix:** Share the opt-in property renderer across normal DDL and both specific-version branches. - **Other paths and branches:** Cover getDdlStmt and getCreateTableLikeStmt; preserve default-false DDL and snapshot version output. ### Testing - Both new copy-tablet tests fail before the fix on the missing property. - 13 affected FE test classes: 223 passed, 1 existing @disabled test skipped, zero failures or errors. - Both entry points cover true/false, single-bucket DDL, replication count, snapshot version, and executing the generated DDL to restore the encoding and visible version. - FE Checkstyle passed with zero violations. ### Release note ADMIN COPY TABLET preserves variant_escape_dots_in_keys in generated debug-table DDL. ### Check List (For Author) - Behavior changed: Yes (copy-tablet DDL preserves the source encoding). - Does this need documentation: No. - Pre-submission status: Ready. ### AI Disclosure - Tool: OpenAI Codex. - Generated: Code, tests, and commit description. - Human review: Pending.
1 parent b1a24ab commit 3265322

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,10 +4346,7 @@ private static void addOlapTablePropertyInfo(OlapTable olapTable, StringBuilder
43464346
sb.append(",\n\"").append(PropertyAnalyzer.PROPERTIES_DISABLE_AUTO_COMPACTION).append("\" = \"");
43474347
sb.append(olapTable.disableAutoCompaction()).append("\"");
43484348

4349-
if (olapTable.getVariantEscapeDotsInKeys()) {
4350-
sb.append(",\n\"").append(PropertyAnalyzer.PROPERTIES_VARIANT_ESCAPE_DOTS_IN_KEYS)
4351-
.append("\" = \"true\"");
4352-
}
4349+
addVariantEscapeDotsInKeysProperty(olapTable, sb);
43534350

43544351
if (olapTable.variantEnableFlattenNested()) {
43554352
// enable flatten nested type in variant
@@ -4407,6 +4404,13 @@ private static void addOlapTablePropertyInfo(OlapTable olapTable, StringBuilder
44074404
}
44084405
}
44094406

4407+
private static void addVariantEscapeDotsInKeysProperty(OlapTable olapTable, StringBuilder sb) {
4408+
if (olapTable.getVariantEscapeDotsInKeys()) {
4409+
sb.append(",\n\"").append(PropertyAnalyzer.PROPERTIES_VARIANT_ESCAPE_DOTS_IN_KEYS)
4410+
.append("\" = \"true\"");
4411+
}
4412+
}
4413+
44104414
/**.
44114415
*
44124416
* @param getDdlForLike Get schema for 'create table like' or not. when true, without hidden columns.
@@ -4516,7 +4520,9 @@ public static void getCreateTableLikeStmt(CreateTableLikeInfo createTableLikeInf
45164520
sb.append("\nDISTRIBUTED BY HASH(").append(olapTable.getBaseSchema().get(0).getName())
45174521
.append(") BUCKETS 1");
45184522
sb.append("\nPROPERTIES (\n" + "\"replication_num\" = \"1\",\n" + "\"version_info\" = \""
4519-
+ specificVersion + "\"\n" + ")");
4523+
+ specificVersion + "\"");
4524+
addVariantEscapeDotsInKeysProperty(olapTable, sb);
4525+
sb.append("\n)");
45204526
createTableStmt.add(sb + ";");
45214527
return;
45224528
}
@@ -4870,7 +4876,9 @@ public static void getDdlStmt(Command command, String dbName, TableIf table, Lis
48704876
sb.append("\nDISTRIBUTED BY HASH(").append(olapTable.getBaseSchema().get(0).getName())
48714877
.append(") BUCKETS 1");
48724878
sb.append("\nPROPERTIES (\n" + "\"replication_num\" = \"1\",\n" + "\"version_info\" = \""
4873-
+ specificVersion + "\"\n" + ")");
4879+
+ specificVersion + "\"");
4880+
addVariantEscapeDotsInKeysProperty(olapTable, sb);
4881+
sb.append("\n)");
48744882
createTableStmt.add(sb + ";");
48754883
return;
48764884
}

‎fe/fe-core/src/test/java/org/apache/doris/catalog/VariantEscapeTableTest.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
import org.apache.doris.common.FeConstants;
2121
import org.apache.doris.common.util.PropertyAnalyzer;
2222
import org.apache.doris.nereids.parser.NereidsParser;
23+
import org.apache.doris.nereids.trees.plans.commands.CreateTableLikeCommand;
2324
import org.apache.doris.persist.gson.GsonUtils;
2425
import org.apache.doris.utframe.TestWithFeService;
2526

2627
import org.junit.jupiter.api.Assertions;
2728
import org.junit.jupiter.api.Test;
2829

30+
import java.util.ArrayList;
31+
import java.util.List;
32+
2933
public class VariantEscapeTableTest extends TestWithFeService {
3034
@Override
3135
protected void runBeforeAll() throws Exception {
@@ -40,6 +44,47 @@ private OlapTable table(String name) throws Exception {
4044
.getTableOrMetaException(name);
4145
}
4246

47+
@Test
48+
public void testCopyTabletDdl() throws Exception {
49+
checkCopyTabletDdl(false);
50+
}
51+
52+
@Test
53+
public void testCopyTabletLikeDdl() throws Exception {
54+
checkCopyTabletDdl(true);
55+
}
56+
57+
private void checkCopyTabletDdl(boolean forLike) throws Exception {
58+
for (boolean escaped : new boolean[] {true, false}) {
59+
String sourceName = "copy_tablet_" + forLike + "_" + escaped;
60+
String targetName = sourceName + "_restored";
61+
createTable("CREATE TABLE " + sourceName + "(k INT, v VARIANT) DUPLICATE KEY(k) "
62+
+ "DISTRIBUTED BY HASH(k) BUCKETS 3 PROPERTIES('replication_num'='1',"
63+
+ "'variant_escape_dots_in_keys'='" + escaped + "')");
64+
List<String> statements = new ArrayList<>();
65+
if (forLike) {
66+
CreateTableLikeCommand command = (CreateTableLikeCommand) new NereidsParser().parseSingle(
67+
"CREATE TABLE " + targetName + " LIKE " + sourceName);
68+
Env.getCreateTableLikeStmt(command.getInfo(), null, table(sourceName), statements, null, null,
69+
false, true, false, 42L, false, false);
70+
} else {
71+
// ADMIN COPY TABLET uses this entry point with the snapshot version.
72+
Env.getDdlStmt(table(sourceName), statements, null, null, false, true, 42L);
73+
}
74+
Assertions.assertEquals(1, statements.size());
75+
String ddl = statements.get(0);
76+
Assertions.assertTrue(ddl.contains("DISTRIBUTED BY HASH(k) BUCKETS 1"), ddl);
77+
Assertions.assertTrue(ddl.contains("\"replication_num\" = \"1\""), ddl);
78+
Assertions.assertTrue(ddl.contains("\"version_info\" = \"42\""), ddl);
79+
Assertions.assertEquals(escaped, ddl.contains("\"variant_escape_dots_in_keys\" = \"true\""), ddl);
80+
Assertions.assertFalse(ddl.contains("\"variant_escape_dots_in_keys\" = \"false\""), ddl);
81+
82+
createTable(ddl.replace("`" + sourceName + "`", "`" + targetName + "`"));
83+
Assertions.assertEquals(escaped, table(targetName).getVariantEscapeDotsInKeys());
84+
Assertions.assertEquals(42L, table(targetName).getPartitions().iterator().next().getVisibleVersion());
85+
}
86+
}
87+
4388
@Test
4489
public void testPropertyPersistenceAndFalseOmission() throws Exception {
4590
createTable("CREATE TABLE escaped(k INT, v VARIANT) DUPLICATE KEY(k) "

0 commit comments

Comments
 (0)