This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 223af45351faeabb2f258c3874580313a05613dd Author: lihangyu <[email protected]> AuthorDate: Wed Apr 17 11:28:51 2024 +0800 [Fix](Json type) forbit schema change adding JSON columns with none null default value (#33686) --- .../src/main/java/org/apache/doris/analysis/ColumnDef.java | 12 +++++++++--- .../trees/plans/commands/info/ColumnDefinition.java | 4 ++++ .../test_unique_model_schema_key_change.groovy | 14 +++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java index 559e6159916..6207a5088af 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java @@ -389,9 +389,15 @@ public class ColumnDef { + "]."); } - if (isKey() && type.getPrimitiveType() == PrimitiveType.JSONB) { - throw new AnalysisException("JSONB type should not be used in key column[" + getName() - + "]."); + if (type.getPrimitiveType() == PrimitiveType.JSONB + || type.getPrimitiveType() == PrimitiveType.VARIANT) { + if (isKey()) { + throw new AnalysisException("JSONB or VARIANT type should not be used in key column[" + getName() + + "]."); + } + if (defaultValue.isSet && defaultValue != DefaultValue.NULL_DEFAULT_VALUE) { + throw new AnalysisException("JSONB or VARIANT type column default value just support null"); + } } if (type.getPrimitiveType() == PrimitiveType.MAP) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java index 9360f2d608a..806aa7cd2aa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java @@ -299,6 +299,10 @@ public class ColumnDefinition { if (defaultValue.isPresent() && defaultValue.get() != DefaultValue.NULL_DEFAULT_VALUE) { throw new AnalysisException("Struct type column default value just support null"); } + } else if (type.isJsonType() || type.isVariantType()) { + if (defaultValue.isPresent() && defaultValue.get() != DefaultValue.NULL_DEFAULT_VALUE) { + throw new AnalysisException("Json or Variant type column default value just support null"); + } } if (!isNullable && defaultValue.isPresent() diff --git a/regression-test/suites/schema_change_p0/test_unique_model_schema_key_change.groovy b/regression-test/suites/schema_change_p0/test_unique_model_schema_key_change.groovy index fb6a6947dd2..7728ceb4399 100644 --- a/regression-test/suites/schema_change_p0/test_unique_model_schema_key_change.groovy +++ b/regression-test/suites/schema_change_p0/test_unique_model_schema_key_change.groovy @@ -255,10 +255,22 @@ suite("test_unique_model_schema_key_change","p0") { },errorMessage) + //TODO Test the unique model by adding a column with JSON type none default value + errorMessage="errCode = 2, detailMessage = JSONB or VARIANT type column default value just support null" + expectException({ + sql initTable + sql initTableData + sql """ alter table ${tbName} add column j JSON DEFAULT '{\"a\": 300}' AFTER username """ + insertSql = " insert into ${tbName} values(123456689, 'Alice', '{\"k1\":\"v31\", \"k2\": 300}', 'Yaan', 25, 0, 13812345678, 'No. 123 Street, Beijing', '2022-01-01 10:00:00'); " + waitForSchemaChangeDone({ + sql getTableStatusSql + time 60 + }, insertSql, true,"${tbName}") + },errorMessage) //TODO Test the unique model by adding a key column with JSON - errorMessage="errCode = 2, detailMessage = JSONB type should not be used in key column[j]." + errorMessage="errCode = 2, detailMessage = JSONB or VARIANT type should not be used in key column[j]." expectException({ sql initTable sql initTableData --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
