This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new ff175d9eeab branch-4.0: [fix](variant) variant type rely on light 
schema change #59712 (#59855)
ff175d9eeab is described below

commit ff175d9eeab8a8088a1b08fce3562efa3851fb9d
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jan 14 17:45:14 2026 +0800

    branch-4.0: [fix](variant) variant type rely on light schema change #59712 
(#59855)
    
    Cherry-picked from #59712
    
    Co-authored-by: Gary <[email protected]>
    Co-authored-by: lihangyu <[email protected]>
---
 .../apache/doris/alter/SchemaChangeHandler.java    | 11 ++++++
 .../doris/alter/SchemaChangeHandlerTest.java       | 41 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
index 145e0d9f473..96b2c609138 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
@@ -570,6 +570,13 @@ public class SchemaChangeHandler extends AlterHandler {
         Column modColumn = alterClause.getColumn();
         boolean lightSchemaChange = false;
 
+        // Defensive guard: no type conversions to VARIANT are allowed today, 
but legacy metadata
+        // may still contain VARIANT columns with light_schema_change disabled.
+        if (modColumn.getType().isVariantType() && 
!olapTable.getEnableLightSchemaChange()) {
+            throw new DdlException("Variant type rely on light schema change, "
+                    + "please use light_schema_change = true.");
+        }
+
         if (KeysType.AGG_KEYS == olapTable.getKeysType()) {
             if (modColumn.isKey() && null != modColumn.getAggregationType()) {
                 throw new DdlException("Can not assign aggregation method on 
key column: " + modColumn.getName());
@@ -960,6 +967,10 @@ public class SchemaChangeHandler extends AlterHandler {
         if (newColumn.isAutoInc()) {
             throw new DdlException("Can not add auto-increment column " + 
newColumn.getName());
         }
+        if (newColumn.getType().isVariantType() && !lightSchemaChange) {
+            throw new DdlException("Variant type rely on light schema change, "
+                    + "please use light_schema_change = true.");
+        }
 
         // check the validation of aggregation method on column.
         // also fill the default aggregation method if not specified.
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
index b97dbb50c76..05bea450c0b 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
@@ -319,6 +319,47 @@ public class SchemaChangeHandlerTest extends 
TestWithFeService {
         }
     }
 
+    @Test
+    public void testAddVariantColumnWithLightSchemaChangeDisabled() throws 
Exception {
+        String tableName = "sc_variant_no_lsc";
+        dropTable("test." + tableName, false);
+        String createTableStmt = "CREATE TABLE test." + tableName + " (\n"
+                + "id INT,\n"
+                + "name VARCHAR(10)\n"
+                + ") DUPLICATE KEY(id)\n"
+                + "DISTRIBUTED BY HASH(id) BUCKETS 1\n"
+                + "PROPERTIES ('replication_num' = '1', 'light_schema_change' 
= 'false');";
+        createTable(createTableStmt);
+
+        String alterStmt = "ALTER TABLE test." + tableName + " ADD COLUMN v 
VARIANT";
+        expectException(alterStmt, "Variant type rely on light schema change");
+    }
+
+    @Test
+    public void testModifyColumnToVariantWithLightSchemaChangeDisabled() 
throws Exception {
+        String tableName = "sc_variant_modify_no_lsc";
+        dropTable("test." + tableName, false);
+        String createTableStmt = "CREATE TABLE test." + tableName + " (\n"
+                + "id INT,\n"
+                + "v VARIANT\n"
+                + ") DUPLICATE KEY(id)\n"
+                + "DISTRIBUTED BY HASH(id) BUCKETS 1\n"
+                + "PROPERTIES ('replication_num' = '1', 'light_schema_change' 
= 'true');";
+        createTable(createTableStmt);
+
+        Database db = 
Env.getCurrentInternalCatalog().getDbOrMetaException("test");
+        OlapTable tbl = (OlapTable) db.getTableOrMetaException(tableName, 
Table.TableType.OLAP);
+        tbl.writeLock();
+        try {
+            tbl.setEnableLightSchemaChange(false);
+        } finally {
+            tbl.writeUnlock();
+        }
+
+        String alterStmt = "ALTER TABLE test." + tableName + " MODIFY COLUMN v 
VARIANT";
+        expectException(alterStmt, "Variant type rely on light schema change");
+    }
+
     @Test
     public void testAggAddOrDropColumn() throws Exception {
         LOG.info("dbName: {}", Env.getCurrentInternalCatalog().getDbNames());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to