mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-01 02:56:10 +00:00
Fix table repository bug (#6871)
This commit is contained in:
parent
994b769d25
commit
6db7eba16b
@ -1250,11 +1250,12 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
recordChange(columnField, origColumn.getConstraint(), updatedColumn.getConstraint());
|
||||
}
|
||||
|
||||
private void updateColumnDataLength(Column origColumn, Column updatedColumn) throws JsonProcessingException {
|
||||
protected void updateColumnDataLength(Column origColumn, Column updatedColumn) throws JsonProcessingException {
|
||||
String columnField = getColumnField(original, origColumn, "dataLength");
|
||||
boolean updated = recordChange(columnField, origColumn.getDataLength(), updatedColumn.getDataLength());
|
||||
if (updated && updatedColumn.getDataLength() < origColumn.getDataLength()) {
|
||||
// The data length of a column was reduced. Treat it as backward-incompatible change
|
||||
if (updated
|
||||
&& (origColumn.getDataLength() == null || updatedColumn.getDataLength() < origColumn.getDataLength())) {
|
||||
// The data length of a column was reduced or added. Treat it as backward-incompatible change
|
||||
majorVersionChange = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openmetadata.catalog.entity.data.Table;
|
||||
import org.openmetadata.catalog.type.Column;
|
||||
|
||||
public class TableRepositoryUnitTest {
|
||||
|
||||
@Test
|
||||
void testWhenUpdatingAColumnDataLengthWhichWasNotSet_issue6868() throws JsonProcessingException {
|
||||
TableRepository outerObject = new TableRepository(mock(CollectionDAO.class));
|
||||
Table origTable = new Table().withFullyQualifiedName("service.db.table");
|
||||
TableRepository.TableUpdater tableUpdater =
|
||||
outerObject.new TableUpdater(origTable, new Table(), EntityRepository.Operation.PUT);
|
||||
Column origColumn = new Column().withFullyQualifiedName("service.db.table.column");
|
||||
Column newColumn = new Column().withFullyQualifiedName("service.db.table.column").withDataLength(100);
|
||||
tableUpdater.updateColumnDataLength(origColumn, newColumn);
|
||||
assertTrue(tableUpdater.majorVersionChange);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user