diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/IndexDefinition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/IndexDefinition.java index d1ae4d260b102e..8630d80b7dc0ab 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/IndexDefinition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/IndexDefinition.java @@ -344,7 +344,7 @@ public void validate() { if (partitionNames != null) { partitionNames.validate(); } - if (isBuildDeferred && indexType == IndexType.INVERTED) { + if (isBuildDeferred && (indexType == IndexType.INVERTED || indexType == IndexType.NGRAM_BF)) { if (Strings.isNullOrEmpty(name)) { throw new AnalysisException("index name cannot be blank."); } @@ -359,7 +359,8 @@ public void validate() { AnnIndexPropertiesChecker.checkProperties(this.properties); } - if (indexType == IndexType.BITMAP || indexType == IndexType.INVERTED) { + if (indexType == IndexType.BITMAP || indexType == IndexType.INVERTED + || indexType == IndexType.NGRAM_BF) { if (cols == null || cols.size() != 1) { throw new AnalysisException( indexType.toString() + " index can only apply to a single column."); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/IndexDefinitionTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/IndexDefinitionTest.java index 837bdd0ddfa379..7b41ddc95cf840 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/IndexDefinitionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/IndexDefinitionTest.java @@ -19,6 +19,7 @@ import org.apache.doris.catalog.AggregateType; import org.apache.doris.catalog.KeysType; +import org.apache.doris.catalog.info.IndexType; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.plans.commands.info.ColumnDefinition; import org.apache.doris.nereids.trees.plans.commands.info.IndexDefinition; @@ -136,6 +137,20 @@ void testNgramBFIndex() throws AnalysisException { KeysType.DUP_KEYS, false, null); } + @Test + void testNgramBFIndexOnlySingleColumn() { + IndexDefinition def = new IndexDefinition("ngram_bf_index", false, Lists.newArrayList("col1", "col2"), + "NGRAM_BF", null, "comment"); + AnalysisException exception = Assertions.assertThrows(AnalysisException.class, def::validate); + Assertions.assertEquals("NGRAM_BF index can only apply to a single column.", exception.getMessage()); + } + + @Test + void testNgramBFBuildIndexValidateWithoutColumns() { + IndexDefinition def = new IndexDefinition("ngram_bf_index", null, IndexType.NGRAM_BF); + Assertions.assertDoesNotThrow(def::validate); + } + @Test void testInvalidNgramBFIndexColumnType() { Map properties = new HashMap<>(); diff --git a/regression-test/suites/index_p0/test_ngram_bloomfilter_index.groovy b/regression-test/suites/index_p0/test_ngram_bloomfilter_index.groovy index 5bcd55e96f40b3..05e77400b556ba 100644 --- a/regression-test/suites/index_p0/test_ngram_bloomfilter_index.groovy +++ b/regression-test/suites/index_p0/test_ngram_bloomfilter_index.groovy @@ -110,4 +110,41 @@ suite("test_ngram_bloomfilter_index") { sql """ALTER TABLE ${tableName3} ADD INDEX idx_http_url(http_url) USING NGRAM_BF PROPERTIES("gram_size"="256", "bf_size"="65535") COMMENT 'http_url ngram_bf index'""" exception "java.sql.SQLException: errCode = 2, detailMessage = 'gram_size' should be an integer between 1 and 255." } + + sql "DROP TABLE IF EXISTS test_ngram_bloomfilter_multi_column_index" + test { + sql """ + CREATE TABLE test_ngram_bloomfilter_multi_column_index ( + `key_id` bigint(20) NULL COMMENT '', + `http_url` text NULL COMMENT '', + `url_path` varchar(2000) NULL COMMENT '', + INDEX idx_ngrambf_multi (`http_url`, `url_path`) USING NGRAM_BF + PROPERTIES("gram_size" = "2", "bf_size" = "512") + ) ENGINE=OLAP + DUPLICATE KEY(`key_id`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`key_id`) BUCKETS 1 + PROPERTIES("replication_num" = "1"); + """ + exception "NGRAM_BF index can only apply to a single column." + } + + sql """ + CREATE TABLE test_ngram_bloomfilter_multi_column_index ( + `key_id` bigint(20) NULL COMMENT '', + `http_url` text NULL COMMENT '', + `url_path` varchar(2000) NULL COMMENT '' + ) ENGINE=OLAP + DUPLICATE KEY(`key_id`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`key_id`) BUCKETS 1 + PROPERTIES("replication_num" = "1"); + """ + test { + sql """ + CREATE INDEX idx_ngrambf_multi ON test_ngram_bloomfilter_multi_column_index(`http_url`, `url_path`) + USING NGRAM_BF PROPERTIES("gram_size" = "2", "bf_size" = "512") + """ + exception "NGRAM_BF index can only apply to a single column." + } }