Skip to content

Commit

Permalink
[Fix](Json type) forbit schema change adding JSON columns with none n…
Browse files Browse the repository at this point in the history
…ull default value (#33686)
  • Loading branch information
eldenmoon authored Apr 17, 2024
1 parent 198f8c2 commit 6aa7665
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public void validate(boolean isOlap, Set<String> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6aa7665

Please sign in to comment.