From 5214e6b4bc85d888e2de7ae1a290510f67961bfa Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Mon, 23 Sep 2024 10:19:19 +0800 Subject: [PATCH] [fix](Variant) check enable light_schema_change when create table with variant type (#40908) --- .../apache/doris/datasource/InternalCatalog.java | 10 ++++++++++ regression-test/suites/variant_p0/load.groovy | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index c3d7c74a615594..36ea8ff80f9c08 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -2526,6 +2526,16 @@ private boolean createOlapTable(Database db, CreateTableStmt stmt) throws UserEx // use light schema change optimization olapTable.setEnableLightSchemaChange(enableLightSchemaChange); + // check if light schema change is disabled, variant type rely on light schema change + if (!enableLightSchemaChange) { + for (Column column : baseSchema) { + if (column.getType().isVariantType()) { + throw new DdlException("Variant type rely on light schema change, " + + " please use light_schema_change = true."); + } + } + } + boolean disableAutoCompaction = false; try { disableAutoCompaction = PropertyAnalyzer.analyzeDisableAutoCompaction(properties); diff --git a/regression-test/suites/variant_p0/load.groovy b/regression-test/suites/variant_p0/load.groovy index 65a5a838c5038e..8f4b9a3cee53fd 100644 --- a/regression-test/suites/variant_p0/load.groovy +++ b/regression-test/suites/variant_p0/load.groovy @@ -446,6 +446,22 @@ suite("regression_test_variant", "p0"){ exception("Invalid type for variant column: 36") } + test { + sql """ + create table var( + `key` int, + `content` variant + ) + DUPLICATE KEY(`key`) + distributed by hash(`key`) buckets 8 + properties( + "replication_allocation" = "tag.location.default: 1", + "light_schema_change" = "false" + ); + """ + exception("errCode = 2, detailMessage = Variant type rely on light schema change") + } + } finally { // reset flags }