Skip to content

Commit

Permalink
fix(updater): process nested columns (#20088)
Browse files Browse the repository at this point in the history
- fixed updater to process nested columns properly
  • Loading branch information
sushi30 authored Mar 6, 2025
1 parent 3980d03 commit 5261cd9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3849,7 +3849,7 @@ public void updateColumns(
continue;
}

updateColumnDescription(stored, updated);
updateColumnDescription(fieldName, stored, updated);
updateColumnDisplayName(stored, updated);
updateColumnDataLength(stored, updated);
updateColumnPrecision(stored, updated);
Expand All @@ -3871,13 +3871,15 @@ public void updateColumns(
majorVersionChange = majorVersionChange || !deletedColumns.isEmpty();
}

private void updateColumnDescription(Column origColumn, Column updatedColumn) {
private void updateColumnDescription(
String fieldName, Column origColumn, Column updatedColumn) {
if (operation.isPut() && !nullOrEmpty(origColumn.getDescription()) && updatedByBot()) {
// Revert the non-empty task description if being updated by a bot
updatedColumn.setDescription(origColumn.getDescription());
return;
}
String columnField = getColumnField(origColumn, FIELD_DESCRIPTION);
String columnField =
EntityUtil.getFieldName(fieldName, origColumn.getName(), FIELD_DESCRIPTION);
recordChange(columnField, origColumn.getDescription(), updatedColumn.getDescription());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
import org.openmetadata.service.resources.databases.DatabaseUtil;
import org.openmetadata.service.resources.databases.TableResource;
import org.openmetadata.service.resources.feeds.MessageParser.EntityLink;
import org.openmetadata.service.search.SearchClient;
import org.openmetadata.service.security.mask.PIIMasker;
import org.openmetadata.service.util.EntityUtil;
import org.openmetadata.service.util.EntityUtil.Fields;
Expand Down Expand Up @@ -138,8 +137,6 @@ public class TableRepository extends EntityRepository<Table> {
private static final Set<String> CHANGE_SUMMARY_FIELDS =
Set.of("description", "owners", "columns.description");

private static final SearchClient searchClient = Entity.getSearchRepository().getSearchClient();

public TableRepository() {
super(
TableResource.COLLECTION_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1988,9 +1988,14 @@ void patch_tableColumnsTags_200_ok(TestInfo test) throws IOException {

@Test
void patch_withChangeSource(TestInfo test) throws IOException {
Column nestedColumns = getColumn("testNested", INT, null);
CreateTable create =
createRequest(test)
.withColumns(List.of(getColumn(C1, INT, null), getColumn(C2, BIGINT, null)));
.withColumns(
List.of(
getColumn(C1, INT, null),
getColumn(C2, BIGINT, null),
getColumn("withNested", STRUCT, null).withChildren(List.of(nestedColumns))));
Table table = createAndCheckEntity(create, ADMIN_AUTH_HEADERS);

Table updated = JsonUtils.deepCopy(table, Table.class);
Expand Down Expand Up @@ -2074,6 +2079,35 @@ void patch_withChangeSource(TestInfo test) throws IOException {
.get(
FullyQualifiedName.build(
"columns", automatedUpdate.getColumns().get(0).getName(), "description")));

Table nestedColumnUpdate = JsonUtils.deepCopy(columnDelete, Table.class);
nestedColumnUpdate
.getColumns()
.get(1)
.getChildren()
.get(0)
.setDescription("nested description");
nestedColumnUpdate =
patchEntity(
table.getId(),
JsonUtils.pojoToJson(columnDelete),
nestedColumnUpdate,
ADMIN_AUTH_HEADERS,
ChangeSource.AUTOMATED);

assertEquals(
nestedColumnUpdate
.getChangeDescription()
.getChangeSummary()
.getAdditionalProperties()
.get(
FullyQualifiedName.build(
"columns",
nestedColumnUpdate.getColumns().get(1).getName(),
nestedColumnUpdate.getColumns().get(1).getChildren().get(0).getName(),
"description"))
.getChangeSource(),
ChangeSource.AUTOMATED);
}

private void assertChangeSummaryInSearch(EntityInterface entity) throws IOException {
Expand Down

0 comments on commit 5261cd9

Please sign in to comment.