This is an automated email from the ASF dual-hosted git repository.
eldenmoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new b4140d0b053 [fix](variant) Reject Decimal256 in VARIANT templates
(#71006)
b4140d0b053 is described below
commit b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927
Author: lihangyu <[email protected]>
AuthorDate: Mon Nov 30 13:21:00 2026 +0800
[fix](variant) Reject Decimal256 in VARIANT templates (#71006)
---
.../trees/plans/commands/info/CreateTableInfo.java | 6 ++
.../trees/plans/commands/info/IndexDefinition.java | 14 +---
.../apache/doris/nereids/types/VariantType.java | 13 ++++
.../doris/catalog/VariantTemplateDdlTest.java | 72 ++++++++++++++++++
.../v2/variant_decimal256_storage_error.groovy | 88 ++++------------------
.../test_variant_values_index_ddl.groovy | 2 +-
6 files changed, 106 insertions(+), 89 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
index bde406d7741..2fce45d348c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
@@ -499,6 +499,12 @@ public class CreateTableInfo {
throw new AnalysisException("Disable to create table with
`DECIMAL` type columns,"
+ "please use `DECIMALV3`.");
}
+ DataType type = columnDef.getType();
+ if (type instanceof VariantType
+ && ((VariantType) type).hasDecimal256Template()) {
+ throw new AnalysisException("Decimal256 is not supported in
VARIANT templates for column '"
+ + columnDef.getName() + "'");
+ }
}
// check duplicated columns
Map<String, ColumnDefinition> columnMap = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
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 23865956435..46eadfa6ae5 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
@@ -34,7 +34,6 @@ import org.apache.doris.indexpolicy.IndexPolicy;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.DataType;
-import org.apache.doris.nereids.types.DecimalV3Type;
import org.apache.doris.nereids.types.VariantType;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.thrift.TInvertedIndexFileStorageFormat;
@@ -542,8 +541,7 @@ public class IndexDefinition {
if (variantType.getEnableNestedGroup()) {
throw new AnalysisException("VARIANT values index does not support
NestedGroup");
}
- if (variantType.getPredefinedFields().stream()
- .anyMatch(field -> containsDecimal256(field.getDataType()))) {
+ if (variantType.hasDecimal256Template()) {
throw new AnalysisException("VARIANT values index does not support
declared Decimal256 paths");
}
if (invertedIndexFileStorageFormat !=
TInvertedIndexFileStorageFormat.SNII) {
@@ -572,16 +570,6 @@ public class IndexDefinition {
}
}
- private static boolean containsDecimal256(DataType type) {
- if (type instanceof DecimalV3Type) {
- return ((DecimalV3Type) type).getPrecision() > 38;
- }
- if (type instanceof ArrayType) {
- return containsDecimal256(((ArrayType) type).getItemType());
- }
- return false;
- }
-
private void validateBloomFilterProperties() {
if (properties.isEmpty()) {
return;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
index ef5ae5871e5..ccea5b54603 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
@@ -267,6 +267,19 @@ public class VariantType extends PrimitiveType {
return predefinedFields;
}
+ /** Whether any declared storage path uses Decimal256, including array
elements. */
+ public boolean hasDecimal256Template() {
+ return predefinedFields.stream().anyMatch(field ->
containsDecimal256(field.getDataType()));
+ }
+
+ private static boolean containsDecimal256(DataType type) {
+ while (type instanceof ArrayType) {
+ type = ((ArrayType) type).getItemType();
+ }
+ return type instanceof DecimalV3Type
+ && ((DecimalV3Type) type).getPrecision() >
DecimalV3Type.MAX_DECIMAL128_PRECISION;
+ }
+
public int getVariantMaxSubcolumnsCount() {
return variantMaxSubcolumnsCount;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java
new file mode 100644
index 00000000000..d6b3c8299d8
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class VariantTemplateDdlTest extends TestWithFeService {
+ private boolean originalDecimal256;
+ private boolean originalNereids;
+
+ @Override
+ protected void runBeforeAll() throws Exception {
+ createDatabase("variant_template_ddl");
+ connectContext.setDatabase("variant_template_ddl");
+ }
+
+ @BeforeEach
+ public void enableDecimal256() {
+ originalDecimal256 =
connectContext.getSessionVariable().enableDecimal256;
+ originalNereids = connectContext.getState().isNereids();
+ connectContext.getSessionVariable().enableDecimal256 = true;
+ connectContext.getState().setNereids(true);
+ }
+
+ @AfterEach
+ public void restoreSettings() {
+ connectContext.getSessionVariable().enableDecimal256 =
originalDecimal256;
+ connectContext.getState().setNereids(originalNereids);
+ }
+
+ @Test
+ public void testDecimal256TemplatesAreRejectedInV2() {
+ for (String type : new String[] {"DECIMAL(39, 2)", "ARRAY<DECIMAL(76,
2)>"}) {
+ AnalysisException error =
Assertions.assertThrows(AnalysisException.class,
+ () -> createTable(ddl("rejected_template",
"VARIANT<'amount':" + type + ">")));
+ Assertions.assertTrue(error.getMessage().contains("Decimal256 is
not supported in VARIANT templates"),
+ error.getMessage());
+ }
+ }
+
+ @Test
+ public void testDecimal128TemplateAndStandaloneDecimal256AreAllowed()
throws Exception {
+ createTable(ddl("allowed_types",
+ "VARIANT<'amount':DECIMAL(38, 2), 'items':ARRAY<DECIMAL(38,
2)>>, wide DECIMAL(76, 2)"));
+ }
+
+ private static String ddl(String table, String columns) {
+ return "CREATE TABLE " + table + " (id INT, v " + columns + ")
DUPLICATE KEY(id) "
+ + "DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES('replication_num'='1')";
+ }
+}
diff --git
a/regression-test/suites/variant_p0/v2/variant_decimal256_storage_error.groovy
b/regression-test/suites/variant_p0/v2/variant_decimal256_storage_error.groovy
index 9407a7cdd62..dc7511530b5 100644
---
a/regression-test/suites/variant_p0/v2/variant_decimal256_storage_error.groovy
+++
b/regression-test/suites/variant_p0/v2/variant_decimal256_storage_error.groovy
@@ -19,80 +19,18 @@ suite("variant_decimal256_storage_error",
"p0,nonConcurrent") {
sql "SET enable_decimal256 = true"
sql "SET debug_variant_enable_doc_mode = false"
- sql "DROP TABLE IF EXISTS variant_decimal256_materialized"
- sql """
- CREATE TABLE variant_decimal256_materialized (
- id INT,
- var VARIANT<
- 'decimal256_': DECIMAL(76, 2),
- PROPERTIES(
- "variant_max_subcolumns_count" = "1",
- "variant_enable_typed_paths_to_sparse" = "false")
- >
- ) ENGINE = OLAP
- DUPLICATE KEY(id)
- DISTRIBUTED BY HASH(id) BUCKETS 1
- PROPERTIES("replication_num" = "1")
- """
- sql """
- INSERT INTO variant_decimal256_materialized VALUES
- (1, parse_to_variant('{"decimal256_":"123.45","hot":1}')),
- (2, parse_to_variant('{"hot":2}'))
- """
- sql "SYNC"
- test {
- sql "SELECT var FROM variant_decimal256_materialized ORDER BY id"
- exception "Conversion from Decimal256 materialized storage column to
Variant V2 is not supported"
- }
-
- sql "DROP TABLE IF EXISTS variant_decimal256_sparse"
- sql """
- CREATE TABLE variant_decimal256_sparse (
- id INT,
- var VARIANT<
- 'decimal256_': DECIMAL(76, 2),
- PROPERTIES(
- "variant_max_subcolumns_count" = "1",
- "variant_enable_typed_paths_to_sparse" = "true")
- >
- ) ENGINE = OLAP
- DUPLICATE KEY(id)
- DISTRIBUTED BY HASH(id) BUCKETS 1
- PROPERTIES("replication_num" = "1")
- """
- sql """
- INSERT INTO variant_decimal256_sparse VALUES
- (1, parse_to_variant('{"decimal256_":"123.45","hot":1}')),
- (2, parse_to_variant('{"hot":2}'))
- """
- sql "SYNC"
- test {
- sql "SELECT var FROM variant_decimal256_sparse ORDER BY id"
- exception "Conversion from Decimal256 storage cell to Variant V2 is
not supported"
- }
-
- sql "DROP TABLE IF EXISTS variant_decimal256_array_materialized"
- sql """
- CREATE TABLE variant_decimal256_array_materialized (
- id INT,
- var VARIANT<
- 'array_decimal256_': ARRAY<DECIMAL(76, 2)>,
- PROPERTIES(
- "variant_max_subcolumns_count" = "1",
- "variant_enable_typed_paths_to_sparse" = "false")
- >
- ) ENGINE = OLAP
- DUPLICATE KEY(id)
- DISTRIBUTED BY HASH(id) BUCKETS 1
- PROPERTIES("replication_num" = "1")
- """
- sql """
- INSERT INTO variant_decimal256_array_materialized VALUES
- (1, parse_to_variant('{"array_decimal256_":[1.23,2.34]}'))
- """
- sql "SYNC"
- test {
- sql "SELECT var FROM variant_decimal256_array_materialized ORDER BY id"
- exception "Conversion from Decimal256 materialized storage column to
Variant V2 is not supported"
+ for (def template : ["DECIMAL(76, 2)", "ARRAY<DECIMAL(76, 2)>"]) {
+ test {
+ sql """
+ CREATE TABLE variant_decimal256_template (
+ id INT,
+ var VARIANT<'amount': ${template}>
+ ) ENGINE = OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num" = "1")
+ """
+ exception "Decimal256 is not supported in VARIANT templates"
+ }
}
}
diff --git
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
index 505dd86990c..c70786c2b25 100644
---
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
+++
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_ddl.groovy
@@ -86,7 +86,7 @@ suite("test_variant_values_index_ddl", "p0") {
rejected('VARIANT<PROPERTIES("variant_enable_nested_group"="true")>',
english, "SNII", "DUPLICATE", "",
"VARIANT values index does not support NestedGroup")
rejected("VARIANT<'wide':DECIMAL(76,2)>", english, "SNII", "DUPLICATE", "",
- "VARIANT values index does not support declared Decimal256 paths")
+ "Decimal256 is not supported in VARIANT templates")
rejected("VARIANT", english, "SNII", "UNIQUE",
',"enable_unique_key_merge_on_write"="false"',
"INVERTED index with parser can NOT be used in value columns of
UNIQUE_KEYS table with merge_on_write disable")
rejected("VARIANT", ',"analyzer"="english"', "SNII", "UNIQUE",
',"enable_unique_key_merge_on_write"="false"',
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]