mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-13 08:37:03 +00:00
Fixes #2593 - Column data length change is not handled and the table entity version does not change (#2691)
This commit is contained in:
parent
61c3e4ec87
commit
dc8d0b62df
@ -19,6 +19,7 @@ import static org.openmetadata.catalog.Entity.LOCATION;
|
||||
import static org.openmetadata.catalog.Entity.TABLE;
|
||||
import static org.openmetadata.catalog.Entity.helper;
|
||||
import static org.openmetadata.catalog.jdbi3.Relationship.JOINED_WITH;
|
||||
import static org.openmetadata.catalog.util.EntityUtil.getColumnField;
|
||||
import static org.openmetadata.common.utils.CommonUtil.parseDate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -835,6 +836,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
}
|
||||
|
||||
updateColumnDescription(stored, updated);
|
||||
updateColumnDataLength(stored, updated);
|
||||
updateTags(
|
||||
stored.getFullyQualifiedName(),
|
||||
fieldName + "." + updated.getName() + ".tags",
|
||||
@ -848,7 +850,7 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
}
|
||||
}
|
||||
|
||||
majorVersionChange = !deletedColumns.isEmpty();
|
||||
majorVersionChange = majorVersionChange || !deletedColumns.isEmpty();
|
||||
}
|
||||
|
||||
private void updateColumnDescription(Column origColumn, Column updatedColumn) throws JsonProcessingException {
|
||||
@ -865,10 +867,14 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
recordChange(getColumnField(origColumn, "constraint"), origColumn.getConstraint(), updatedColumn.getConstraint());
|
||||
}
|
||||
|
||||
private String getColumnField(Column column, String columnField) {
|
||||
// Remove table FQN from column FQN to get the local name
|
||||
String localColumnName = EntityUtil.getLocalColumnName(column.getFullyQualifiedName());
|
||||
return "columns." + localColumnName + (columnField == null ? "" : "." + columnField);
|
||||
private void updateColumnDataLength(Column origColumn, Column updatedColumn) throws JsonProcessingException {
|
||||
if (recordChange(
|
||||
getColumnField(origColumn, "dataLength"), origColumn.getDataLength(), updatedColumn.getDataLength())) {
|
||||
if (updatedColumn.getDataLength() < origColumn.getDataLength()) {
|
||||
// The data length of a column changed. Treat it as backward-incompatible change
|
||||
majorVersionChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,6 +438,13 @@ public final class EntityUtil {
|
||||
return localColumnName.toString();
|
||||
}
|
||||
|
||||
/** Return column field name of format columnName.fieldName */
|
||||
public static String getColumnField(Column column, String columnField) {
|
||||
// Remove table FQN from column FQN to get the local name
|
||||
String localColumnName = EntityUtil.getLocalColumnName(column.getFullyQualifiedName());
|
||||
return "columns." + localColumnName + (columnField == null ? "" : "." + columnField);
|
||||
}
|
||||
|
||||
public static Boolean toBoolean(Include include) {
|
||||
if (include.equals(DELETED)) {
|
||||
return Boolean.TRUE;
|
||||
|
||||
@ -432,7 +432,7 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
|
||||
assertEquals(bankTagUsageCount + 1, getTagUsageCount(USER_BANK_ACCOUNT_TAG_LABEL.getTagFQN(), userAuthHeaders()));
|
||||
|
||||
//
|
||||
// Add a new column using PUT
|
||||
// Add a new column c2 using PUT
|
||||
//
|
||||
change = getChangeDescription(table.getVersion());
|
||||
Column c2 = getColumn("c2", BINARY, null).withOrdinalPosition(2).withDataLength(10).withTags(tags);
|
||||
@ -445,6 +445,25 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
|
||||
assertEquals(addressTagUsageCount + 2, getTagUsageCount(USER_ADDRESS_TAG_LABEL.getTagFQN(), userAuthHeaders()));
|
||||
assertEquals(bankTagUsageCount + 2, getTagUsageCount(USER_BANK_ACCOUNT_TAG_LABEL.getTagFQN(), userAuthHeaders()));
|
||||
|
||||
//
|
||||
// Change the column c2 data length from 10 to 20. Increasing the data length is considered backward compatible
|
||||
// and only minor version changes
|
||||
//
|
||||
c2.setDataLength(20);
|
||||
change = getChangeDescription(table.getVersion());
|
||||
String fieldName = "columns.c2.dataLength";
|
||||
change.getFieldsUpdated().add(new FieldChange().withName(fieldName).withOldValue(10).withNewValue(20));
|
||||
table = updateAndCheckEntity(request.withColumns(updatedColumns), OK, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
|
||||
|
||||
//
|
||||
// Change the column c2 data length from 20 to 10. Decreasing the data length is considered backward compatible
|
||||
// and results in major version changes
|
||||
//
|
||||
c2.setDataLength(10);
|
||||
change = getChangeDescription(table.getVersion());
|
||||
change.getFieldsUpdated().add(new FieldChange().withName(fieldName).withOldValue(20).withNewValue(10));
|
||||
table = updateAndCheckEntity(request.withColumns(updatedColumns), OK, ADMIN_AUTH_HEADERS, MAJOR_UPDATE, change);
|
||||
|
||||
//
|
||||
// Remove a column c2 and make sure it is deleted by PUT
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user