|
17 | 17 | package base_test |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "fmt" |
20 | 21 | "reflect" |
21 | 22 | "testing" |
22 | 23 |
|
@@ -225,3 +226,62 @@ func TestNormalizeCreateTableSql(t *testing.T) { |
225 | 226 | } |
226 | 227 | } |
227 | 228 | } |
| 229 | + |
| 230 | +func TestHandleSchemaChangeVariantProperties(t *testing.T) { |
| 231 | + data := `{ |
| 232 | + "dbId":1759183589184, |
| 233 | + "tableId":1759183589229, |
| 234 | + "baseIndexId":1759183589230, |
| 235 | + "indexSchemaMap": { |
| 236 | + "1759183589230":[{ |
| 237 | + "name":"id", |
| 238 | + "type":{"clazz":"ScalarType","type":"INT","len":-1,"precision":0,"scale":0}, |
| 239 | + "isAggregationTypeImplicit":false, |
| 240 | + "isKey":true,"isAllowNull":true, |
| 241 | + "isAutoInc":false, |
| 242 | + "autoIncInitValue":-1, |
| 243 | + "comment":"", |
| 244 | + "stats":{"avgSerializedSize":-1.0,"maxSize":-1,"numDistinctValues":-1,"numNulls":-1}, |
| 245 | + "children":[],"visible":true,"uniqueId":0,"clusterKeyId":-1,"hasOnUpdateDefaultValue":false,"gctt":[] |
| 246 | + }, { |
| 247 | + "name":"j","type":{"clazz":"ScalarType","type":"JSONB","len":-1,"precision":0,"scale":0}, |
| 248 | + "aggregationType":"NONE","isAggregationTypeImplicit":true,"isKey":false,"isAllowNull":true, |
| 249 | + "isAutoInc":false,"autoIncInitValue":0,"comment":"", |
| 250 | + "stats":{"avgSerializedSize":-1.0,"maxSize":-1,"numDistinctValues":-1,"numNulls":-1}, |
| 251 | + "children":[],"visible":true,"uniqueId":1,"clusterKeyId":-1,"hasOnUpdateDefaultValue":false,"gctt":[] |
| 252 | + },{ |
| 253 | + "name":"v", |
| 254 | + "type":{"clazz":"VariantType","fieldMap":{},"fields":[],"variantMaxSubcolumnsCount":2,"enableTypedPathsToSparse":false, |
| 255 | + "variantMaxSparseColumnStatisticsSize":10000,"type":"VARIANT","len":-1,"precision":0,"scale":0}, |
| 256 | + "aggregationType":"NONE","isAggregationTypeImplicit":true,"isKey":false,"isAllowNull":true,"isAutoInc":false,"autoIncInitValue":0, |
| 257 | + "comment":"", |
| 258 | + "stats":{"avgSerializedSize":-1.0,"maxSize":-1,"numDistinctValues":-1,"numNulls":-1}, |
| 259 | + "children":[],"visible":true,"uniqueId":2,"clusterKeyId":-1,"hasOnUpdateDefaultValue":false,"gctt":[] |
| 260 | + }]}, |
| 261 | + "oldIndexSchemaMap":{ |
| 262 | + "1759183589230":[ |
| 263 | + {"name":"id","type":{"clazz":"ScalarType","type":"INT","len":-1,"precision":0,"scale":0}, |
| 264 | + "isAggregationTypeImplicit":false,"isKey":true,"isAllowNull":true,"isAutoInc":false,"autoIncInitValue":-1,"comment":"", |
| 265 | + "stats":{"avgSerializedSize":-1.0,"maxSize":-1,"numDistinctValues":-1,"numNulls":-1}, |
| 266 | + "children":[],"visible":true,"uniqueId":0,"clusterKeyId":-1,"hasOnUpdateDefaultValue":false,"gctt":[]}, |
| 267 | + {"name":"j","type":{"clazz":"ScalarType","type":"JSONB","len":-1,"precision":0,"scale":0}, |
| 268 | + "aggregationType":"NONE","isAggregationTypeImplicit":true,"isKey":false,"isAllowNull":true,"isAutoInc":false, |
| 269 | + "autoIncInitValue":0,"comment":"","stats":{"avgSerializedSize":-1.0,"maxSize":-1,"numDistinctValues":-1,"numNulls":-1}, |
| 270 | + "children":[],"visible":true,"uniqueId":1,"clusterKeyId":-1,"hasOnUpdateDefaultValue":false,"gctt":[]} |
| 271 | + ]},"indexNameToId":{"tbl_332464610":1759183589230}, |
| 272 | + "indexes":[],"jobId":1759183590091, |
| 273 | + "rawSql":"%s"}` |
| 274 | + |
| 275 | + raw := "ALTER TABLE `regression_test_db_sync_cdt_column_add`.`tbl_332464610` ADD COLUMN `v` variant\\u003cPROPERTIES (\\\"variant_max_subcolumns_count\\\" \\u003d \\\"2\\\",)\u003e NULL COMMENT \\\"\\\"" |
| 276 | + expect := "ALTER TABLE `regression_test_db_sync_cdt_column_add`.`tbl_332464610` ADD COLUMN `v` variant<PROPERTIES (\"variant_max_subcolumns_count\" = \"2\")> NULL COMMENT \"\"" |
| 277 | + |
| 278 | + data = fmt.Sprintf(data, raw) |
| 279 | + origin, err := record.NewModifyTableAddOrDropColumnsFromJson(data) |
| 280 | + if err != nil { |
| 281 | + t.Errorf("unmarshal json failed, err: %v", err) |
| 282 | + return |
| 283 | + } |
| 284 | + if actual := base.HandleSchemaChangeVariantProperties(origin.RawSql, origin); actual != expect { |
| 285 | + t.Errorf("case failed, expect %s, but got %s", expect, actual) |
| 286 | + } |
| 287 | +} |
0 commit comments