Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(timeline): fixes a renaming corner case #11843

Merged
Merged
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
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
Loading