From 722d512a35e1265b27f81c66e658c665e5a20dd8 Mon Sep 17 00:00:00 2001 From: Sun Chenyang Date: Fri, 15 Aug 2025 14:20:39 +0800 Subject: [PATCH] [fix](variant) building index on the variant column is prohibited (#54777) this problem intro by #48461, should not remove this restriction. --- .../apache/doris/alter/SchemaChangeHandler.java | 14 ++++++++++++++ .../load.groovy | 6 ++---- .../suites/variant_p0/with_index/var_index.groovy | 6 ++---- 3 files changed, 18 insertions(+), 8 deletions(-) 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 eed7550759b4f1..364cacab538131 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 @@ -2180,6 +2180,20 @@ public int getAsInt() { throw new DdlException("BUILD INDEX operation failed: No need to do it in cloud mode."); } + for (Column column : olapTable.getBaseSchema()) { + if (!column.getType().isVariantType()) { + continue; + } + // variant type column can not support for building index + for (String indexColumn : index.getColumns()) { + if (column.getName().equalsIgnoreCase(indexColumn)) { + throw new DdlException("BUILD INDEX operation failed: The " + + indexDef.getIndexName() + " index can not be built on the " + + indexColumn + " column, because it is a variant type column."); + } + } + } + if (indexDef.getPartitionNames().isEmpty()) { indexOnPartitions.put(index.getIndexId(), olapTable.getPartitionNames()); } else { diff --git a/regression-test/suites/variant_github_events_nonConcurrent_p2/load.groovy b/regression-test/suites/variant_github_events_nonConcurrent_p2/load.groovy index 2a979de61a7bfb..1496df355372b5 100644 --- a/regression-test/suites/variant_github_events_nonConcurrent_p2/load.groovy +++ b/regression-test/suites/variant_github_events_nonConcurrent_p2/load.groovy @@ -104,11 +104,9 @@ suite("regression_test_variant_github_events_p2", "nonConcurrent,p2"){ load_json_data.call(table_name, """${getS3Url() + '/regression/gharchive.m/2022-11-07-23.json'}""") // BUILD INDEX - try { + test { sql """ BUILD INDEX idx_var ON github_events""" - } catch (Exception e) { - log.info(e.getMessage()) - assertTrue(e.getMessage().contains("The idx_var index can not be built on the v column, because it is a variant type column")) + exception "The idx_var index can not be built on the v column, because it is a variant type column" } // // add bloom filter at the end of loading data diff --git a/regression-test/suites/variant_p0/with_index/var_index.groovy b/regression-test/suites/variant_p0/with_index/var_index.groovy index f57bd6915befba..21b2f5f6f007da 100644 --- a/regression-test/suites/variant_p0/with_index/var_index.groovy +++ b/regression-test/suites/variant_p0/with_index/var_index.groovy @@ -149,11 +149,9 @@ suite("regression_test_variant_var_index", "p0, nonConcurrent"){ properties("replication_num" = "1", "disable_auto_compaction" = "true", "inverted_index_storage_format" = "V1"); """ sql """ALTER TABLE var_index ADD INDEX idx_var(v) USING INVERTED""" - try { + test { sql """ build index idx_var on var_index""" - } catch (Exception e) { - log.info(e.getMessage()) - assertTrue(e.getMessage().contains("The idx_var index can not be built on the v column, because it is a variant type column")) + exception "The idx_var index can not be built on the v column, because it is a variant type column" } }