Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
}

group 'com.gotocompany'
version '0.10.19'
version '0.10.20'

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,24 @@ private static List<MaxComputeColumnDetail> getMaxComputeColumnDetailDifference(
if (Objects.isNull(oldMetadata)) { //handle new column / struct field
changedMetadata.add(entry.getValue());
if (isStructType(entry.getValue().getTypeInfo()) || isStructArrayType(entry.getValue().getTypeInfo())) {
skipStructFields(entry, newMaxComputeColumnDetailIterator);
StructTypeInfo structTypeInfo = isStructType(entry.getValue().getTypeInfo()) ? (StructTypeInfo) entry.getValue().getTypeInfo() : ((StructTypeInfo) ((ArrayTypeInfo) entry.getValue().getTypeInfo()).getElementTypeInfo());
skipStructFields(structTypeInfo, newMaxComputeColumnDetailIterator);
}
}
}
return changedMetadata;
}

private static void skipStructFields(Map.Entry<String, MaxComputeColumnDetail> entry, Iterator<Map.Entry<String, MaxComputeColumnDetail>> newMaxComputeColumnDetailIterator) {
StructTypeInfo structTypeInfo = isStructType(entry.getValue().getTypeInfo()) ? (StructTypeInfo) entry.getValue().getTypeInfo()
: ((StructTypeInfo) ((ArrayTypeInfo) entry.getValue().getTypeInfo()).getElementTypeInfo());
private static void skipStructFields(StructTypeInfo structTypeInfo, Iterator<Map.Entry<String, MaxComputeColumnDetail>> newMaxComputeColumnDetailIterator) {
for (int i = 0; i < structTypeInfo.getFieldCount(); i++) {
newMaxComputeColumnDetailIterator.next();
TypeInfo currentTypeInfo = structTypeInfo.getFieldTypeInfos().get(i);
if (isPrimitiveType(currentTypeInfo) || isPrimitiveArrayType(currentTypeInfo)) {
newMaxComputeColumnDetailIterator.next();
} else if (isStructType(currentTypeInfo) || isStructArrayType(currentTypeInfo)) {
newMaxComputeColumnDetailIterator.next();
StructTypeInfo currentStructTypeInfo = isStructType(currentTypeInfo) ? (StructTypeInfo) currentTypeInfo : ((StructTypeInfo) ((ArrayTypeInfo) currentTypeInfo).getElementTypeInfo());
skipStructFields(currentStructTypeInfo, newMaxComputeColumnDetailIterator);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ public void testGetSchemaDifferenceDdl() {
.build();
Set<String> expectedMetadataColumns = new HashSet<>(Arrays.asList(
"alter table test_schema.test_table add column if not exists `col3`.`f3` array<string>;",
"alter table test_schema.test_table add column if not exists `metadata_2` string;",
"alter table test_schema.test_table add column if not exists `col4`.element.`f42` struct<`f421`:string>;",
"alter table test_schema.test_table add column if not exists `col5` array<struct<`f51`:int>>;",
"alter table test_schema.test_table add column if not exists `col6` struct<`f61`:string>;",
"alter table test_schema.test_table add column if not exists `metadata_2` string;",
"alter table test_schema.test_table add column if not exists `col7` struct<`order`:struct<`f711`:string,`f712`:int>,`end`:string>;",
"alter table test_schema.test_table add column if not exists `col7`.`order`.`f711` string;",
"alter table test_schema.test_table add column if not exists `col7`.`order`.`f712` int;"
"alter table test_schema.test_table add column if not exists `col7` struct<`order`:struct<`f711`:string,`f712`:int>,`end`:string>;"
));

Set<String> actualMetadataColumns = new HashSet<>(SchemaDifferenceUtils.getSchemaDifferenceSql(oldTableSchema, newTableSchema, "test_schema", "test_table"));

assertEquals(actualMetadataColumns.size(), expectedMetadataColumns.size());
assertEquals(expectedMetadataColumns.size(), actualMetadataColumns.size());
assertTrue(expectedMetadataColumns.containsAll(actualMetadataColumns));
}

Expand Down