diff --git a/metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGenerator.java b/metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGenerator.java index c40fa49173627..df902f95245ef 100644 --- a/metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGenerator.java +++ b/metadata-io/src/main/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGenerator.java @@ -266,6 +266,7 @@ private static List computeDiffs( SchemaField renamedField = findRenamedField( curBaseField, + new HashSet<>(baseFields.subList(baseFieldIdx, baseFields.size())), targetFields.subList(targetFieldIdx, targetFields.size()), renamedFields); if (renamedField == null) { @@ -289,7 +290,10 @@ private static List 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; @@ -348,10 +352,14 @@ private static void sortFieldsByPath(SchemaMetadata schemaMetadata) { } private static SchemaField findRenamedField( - SchemaField curField, List targetFields, Set renamedFields) { + SchemaField curField, + Set baseFields, + List targetFields, + Set 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); } diff --git a/metadata-io/src/test/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGeneratorTest.java b/metadata-io/src/test/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGeneratorTest.java index 22dc3162c1e86..afa0730483108 100644 --- a/metadata-io/src/test/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGeneratorTest.java +++ b/metadata-io/src/test/java/com/linkedin/metadata/timeline/eventgenerator/SchemaMetadataChangeEventGeneratorTest.java @@ -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 from = + getSchemaMetadata( + List.of( + new SchemaField().setFieldPath("id").setNativeDataType("VARCHAR"), + new SchemaField().setFieldPath("fullname").setNativeDataType("VARCHAR"), + new SchemaField().setFieldPath("LastName").setNativeDataType("VARCHAR"))); + Aspect to = + getSchemaMetadata( + List.of( + new SchemaField().setFieldPath("id").setNativeDataType("VARCHAR"), + new SchemaField().setFieldPath("fullname").setNativeDataType("VARCHAR"), + new SchemaField().setFieldPath("lastName").setNativeDataType("VARCHAR"))); + List 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