[Fix](Json type) forbit schema change adding JSON columns with none null default value (#33686)
This commit is contained in:
@ -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) {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user