Skip to content

Commit

Permalink
fix(timeline): fixes a renaming corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien committed Nov 12, 2024
1 parent c1fb876 commit 03c3693
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ private static List<ChangeEvent> computeDiffs(
SchemaField renamedField =
findRenamedField(
curBaseField,
new HashSet<>(baseFields.subList(baseFieldIdx, baseFields.size())),
targetFields.subList(targetFieldIdx, targetFields.size()),
renamedFields);
if (renamedField == null) {
Expand All @@ -289,7 +290,10 @@ private static List<ChangeEvent> computeDiffs(
// minor version bump for both.
SchemaField renamedField =
findRenamedField(
curTargetField, baseFields.subList(baseFieldIdx, baseFields.size()), renamedFields);
curTargetField,
new HashSet<>(targetFields.subList(targetFieldIdx, targetFields.size())),
baseFields.subList(baseFieldIdx, baseFields.size()),
renamedFields);
if (renamedField == null) {
processAdd(changeCategories, changeEvents, datasetUrn, curTargetField, auditStamp);
++targetFieldIdx;
Expand Down Expand Up @@ -348,10 +352,14 @@ private static void sortFieldsByPath(SchemaMetadata schemaMetadata) {
}

private static SchemaField findRenamedField(
SchemaField curField, List<SchemaField> targetFields, Set<SchemaField> renamedFields) {
SchemaField curField,
Set<SchemaField> baseFields,
List<SchemaField> targetFields,
Set<SchemaField> renamedFields) {
return targetFields.stream()
.filter(schemaField -> isRenamed(curField, schemaField))
.filter(field -> !renamedFields.contains(field))
.filter(field -> !baseFields.contains(field)) // Filter out fields that will match later
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,37 @@ public void testSchemaFieldRename() throws Exception {
Set.of(SchemaFieldModificationCategory.RENAME.toString()), actual);
}

@Test
public void testSchemaFieldRename2() throws Exception {
SchemaMetadataChangeEventGenerator test = new SchemaMetadataChangeEventGenerator();

Urn urn = getTestUrn();
String entity = "dataset";
String aspect = "schemaMetadata";
AuditStamp auditStamp = getTestAuditStamp();

Aspect<SchemaMetadata> from =
getSchemaMetadata(
List.of(
new SchemaField().setFieldPath("id").setNativeDataType("VARCHAR"),
new SchemaField().setFieldPath("fullname").setNativeDataType("VARCHAR"),
new SchemaField().setFieldPath("LastName").setNativeDataType("VARCHAR")));
Aspect<SchemaMetadata> to =
getSchemaMetadata(
List.of(
new SchemaField().setFieldPath("id").setNativeDataType("VARCHAR"),
new SchemaField().setFieldPath("fullname").setNativeDataType("VARCHAR"),
new SchemaField().setFieldPath("lastName").setNativeDataType("VARCHAR")));
List<ChangeEvent> actual = test.getChangeEvents(urn, entity, aspect, from, to, auditStamp);
compareDescriptions(
Set.of(
"A forwards & backwards compatible change due to renaming of the field 'LastName to lastName'."),
actual);
assertEquals(1, actual.size());
compareModificationCategories(
Set.of(SchemaFieldModificationCategory.RENAME.toString()), actual);
}

@Test
public void testSchemaFieldDropAdd() throws Exception {
// When a rename cannot be detected, treated as drop -> add
Expand Down

0 comments on commit 03c3693

Please sign in to comment.