From 76d62c42dba793857c842abf152379ccd698cbb7 Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Mon, 23 Sep 2024 14:30:16 +0800 Subject: [PATCH] [pick](Variant) check enable light_schema_change when create table with variant type (#41102) #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 ceccc89524..8f37f73a82 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 @@ -2358,6 +2358,16 @@ public class InternalCatalog implements CatalogIf { // 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 161b8ce0ca..0618785a70 100644 --- a/regression-test/suites/variant_p0/load.groovy +++ b/regression-test/suites/variant_p0/load.groovy @@ -431,6 +431,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 }