mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-25 17:15:09 +00:00
fix(timeline): fixes a renaming corner case (#11843)
This commit is contained in:
parent
9f5bf31009
commit
3f5fc9a540
@ -266,6 +266,7 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
|
||||
SchemaField renamedField =
|
||||
findRenamedField(
|
||||
curBaseField,
|
||||
new HashSet<>(baseFields.subList(baseFieldIdx, baseFields.size())),
|
||||
targetFields.subList(targetFieldIdx, targetFields.size()),
|
||||
renamedFields);
|
||||
if (renamedField == null) {
|
||||
@ -289,7 +290,10 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
|
||||
// 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;
|
||||
@ -348,10 +352,14 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -153,6 +153,37 @@ public class SchemaMetadataChangeEventGeneratorTest extends AbstractTestNGSpring
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user