Fix table repository bug (#6871)

This commit is contained in:
Nahuel 2022-08-23 15:13:11 +02:00 committed by GitHub
parent 994b769d25
commit 6db7eba16b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}