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 559e6159916728..6207a5088af8c6 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 void analyze(boolean isOlap) throws AnalysisException { + "]."); } - 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 9360f2d608a482..806aa7cd2aa232 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 void validate(boolean isOlap, Set keysSet, boolean isEnableMergeO 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 fb6a6947dd2620..7728ceb43994eb 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