diff --git a/build.gradle b/build.gradle index 58e495ee..8ea8bd20 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ repositories { allprojects { group = 'com.adaptivescale' - version = '2.1.1' + version = '2.1.2' sourceCompatibility = 11 targetCompatibility = 11 } diff --git a/cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java b/cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java index 8afcccb6..f7eb3163 100644 --- a/cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java +++ b/cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java @@ -56,7 +56,7 @@ @Slf4j @CommandLine.Command(name = "cli", mixinStandardHelpOptions = true, - version = "2.1.1", + version = "2.1.2", description = "Declarative Database Management - DDL Transpiler" ) class Cli implements Callable { diff --git a/common/src/main/java/com/adaptivescale/rosetta/common/models/Column.java b/common/src/main/java/com/adaptivescale/rosetta/common/models/Column.java index 48169c6f..f77d9f4b 100644 --- a/common/src/main/java/com/adaptivescale/rosetta/common/models/Column.java +++ b/common/src/main/java/com/adaptivescale/rosetta/common/models/Column.java @@ -2,7 +2,9 @@ import com.adaptivescale.rosetta.common.models.test.Tests; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class Column { @@ -19,8 +21,8 @@ public class Column { private int columnDisplaySize; private int scale; private int precision; + private List columnProperties = new ArrayList<>(); private Tests tests; - private List foreignKeys; public Column() { @@ -138,6 +140,21 @@ public void setPrecision(int precision) { this.precision = precision; } + public List getColumnProperties() { + return columnProperties; + } + + public String columnPropertiesAsString() { + return Optional.ofNullable(columnProperties) + .map(it -> it.toString()) + .orElse(""); + + } + + public void setColumnProperties(List columnProperties) { + this.columnProperties = columnProperties; + } + public Tests getTests() { return tests; } @@ -145,5 +162,4 @@ public Tests getTests() { public void setTests(Tests tests) { this.tests = tests; } - } diff --git a/common/src/main/java/com/adaptivescale/rosetta/common/models/ColumnProperties.java b/common/src/main/java/com/adaptivescale/rosetta/common/models/ColumnProperties.java new file mode 100644 index 00000000..4a0a1019 --- /dev/null +++ b/common/src/main/java/com/adaptivescale/rosetta/common/models/ColumnProperties.java @@ -0,0 +1,40 @@ +package com.adaptivescale.rosetta.common.models; + +public class ColumnProperties { + + private String name; + + private Integer sequenceId; + + public ColumnProperties() { + } + + public ColumnProperties(String name, Integer sequenceId) { + this.name = name; + this.sequenceId = sequenceId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSequenceId() { + return sequenceId; + } + + public void setSequenceId(Integer sequenceId) { + this.sequenceId = sequenceId; + } + + @Override + public String toString() { + return "ColumnProperties{" + + "name='" + name + '\'' + + ", sequenceId=" + sequenceId + + '}'; + } +} diff --git a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/change/KineticaChangeFinder.java b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/change/KineticaChangeFinder.java index d0755ef8..91b2523e 100644 --- a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/change/KineticaChangeFinder.java +++ b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/change/KineticaChangeFinder.java @@ -120,7 +120,8 @@ private List> findChangesInColumnsForTable(Table expected, Table actua && Objects.equals(expectedColumn.getScale(), actualColumn.getScale()) && Objects.equals(expectedColumn.getOrdinalPosition(), actualColumn.getOrdinalPosition()) && Objects.equals(expectedColumn.getColumnDisplaySize(), actualColumn.getColumnDisplaySize()) - && Objects.equals(expectedColumn.getPrimaryKeySequenceId(), actualColumn.getPrimaryKeySequenceId()); + && Objects.equals(expectedColumn.getPrimaryKeySequenceId(), actualColumn.getPrimaryKeySequenceId()) + && Objects.equals(expectedColumn.getColumnProperties(), actualColumn.getColumnProperties()); if (!same) { Change columnChange = ChangeFactory.columnChange(expectedColumn, actualColumn, Change.Status.ALTER, expected); diff --git a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaColumnDecoratorFactory.java b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaColumnDecoratorFactory.java index 51e3338c..697e59fb 100644 --- a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaColumnDecoratorFactory.java +++ b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaColumnDecoratorFactory.java @@ -4,13 +4,13 @@ import com.adaptivescale.rosetta.ddl.targets.ColumnDataTypeName; import com.adaptivescale.rosetta.ddl.targets.ColumnSQLDecorator; import com.adaptivescale.rosetta.ddl.targets.ColumnSQLDecoratorFactory; +import com.adaptivescale.rosetta.ddl.targets.kinetica.decorators.DefaultKineticaColumnSQLDecorator; import com.adaptivescale.rosetta.ddl.targets.kinetica.decorators.KineticaColumnTypeName; -import com.adaptivescale.rosetta.ddl.targets.postgres.decorators.DefaultPostgresColumnSQLDecorator; public class KineticaColumnDecoratorFactory implements ColumnSQLDecoratorFactory { @Override public ColumnSQLDecorator decoratorFor(Column column) { ColumnDataTypeName columnDataTypeName = new KineticaColumnTypeName(); - return new DefaultPostgresColumnSQLDecorator(column, columnDataTypeName); + return new DefaultKineticaColumnSQLDecorator(column, columnDataTypeName); } } diff --git a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaDDLGenerator.java b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaDDLGenerator.java index 35020b82..957f7809 100644 --- a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaDDLGenerator.java +++ b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/KineticaDDLGenerator.java @@ -139,7 +139,8 @@ public String alterColumn(ColumnChange change) { Column expected = change.getExpected(); if (!Objects.equals(expected.getTypeName(), actual.getTypeName()) - || !Objects.equals(expected.isNullable(), actual.isNullable())) { + || !Objects.equals(expected.isNullable(), actual.isNullable()) + || !Objects.equals(expected.getColumnProperties(), actual.getColumnProperties())) { Map params = new HashMap<>(); params.put("schemaName", table.getSchema()); diff --git a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/DefaultKineticaColumnSQLDecorator.java b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/DefaultKineticaColumnSQLDecorator.java new file mode 100644 index 00000000..8642c063 --- /dev/null +++ b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/DefaultKineticaColumnSQLDecorator.java @@ -0,0 +1,32 @@ +package com.adaptivescale.rosetta.ddl.targets.kinetica.decorators; + +import com.adaptivescale.rosetta.common.models.Column; +import com.adaptivescale.rosetta.common.models.ColumnProperties; +import com.adaptivescale.rosetta.ddl.targets.ColumnDataTypeName; +import com.adaptivescale.rosetta.ddl.targets.ColumnSQLDecorator; + +import java.util.List; + +import static com.adaptivescale.rosetta.ddl.targets.postgres.Constants.DEFAULT_WRAPPER; + +public class DefaultKineticaColumnSQLDecorator implements ColumnSQLDecorator { + private final Column column; + private final ColumnDataTypeName columnDataTypeName; + + public DefaultKineticaColumnSQLDecorator(Column column, ColumnDataTypeName columnDataTypeName) { + this.column = column; + this.columnDataTypeName = columnDataTypeName; + } + + @Override + public String expressSQl() { + StringBuilder builder = new StringBuilder(); + builder.append(DEFAULT_WRAPPER).append(column.getName()).append(DEFAULT_WRAPPER).append(" "); + builder.append(columnDataTypeName.nameForColumn(column)); + if(!column.isNullable()) { + builder.append(" NOT NULL "); + } + return builder.toString(); + } + +} diff --git a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/KineticaColumnTypeName.java b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/KineticaColumnTypeName.java index 40529243..3b76f327 100644 --- a/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/KineticaColumnTypeName.java +++ b/ddl/src/main/java/com/adaptivescale/rosetta/ddl/targets/kinetica/decorators/KineticaColumnTypeName.java @@ -1,8 +1,13 @@ package com.adaptivescale.rosetta.ddl.targets.kinetica.decorators; import com.adaptivescale.rosetta.common.models.Column; +import com.adaptivescale.rosetta.common.models.ColumnProperties; import com.adaptivescale.rosetta.ddl.targets.ColumnDataTypeName; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + import static com.adaptivescale.rosetta.ddl.targets.kinetica.Constants.PRECISION_DEFAULTS; import static com.adaptivescale.rosetta.ddl.targets.kinetica.Constants.PRECISION_TYPES; @@ -14,8 +19,22 @@ public class KineticaColumnTypeName implements ColumnDataTypeName { public String nameForColumn(Column column) { StringBuilder builder = new StringBuilder(); builder.append(ColumnDataTypeName.super.nameForColumn(column)); - if ( !PRECISION_DEFAULTS.contains(column.getPrecision()) && PRECISION_TYPES.contains(column.getTypeName().toLowerCase())) { - builder.append("(").append(column.getPrecision()).append(")"); + if ( (!PRECISION_DEFAULTS.contains(column.getPrecision()) && PRECISION_TYPES.contains(column.getTypeName().toLowerCase())) + || (Optional.ofNullable(column.getColumnProperties()).isPresent() && !column.getColumnProperties().isEmpty())) { + builder.append("("); + List items = new ArrayList<>(); + if (!PRECISION_DEFAULTS.contains(column.getPrecision()) && PRECISION_TYPES.contains(column.getTypeName().toLowerCase())) { + items.add(column.getPrecision()+""); + } + + if (Optional.ofNullable(column.getColumnProperties()).isPresent()) { + column.getColumnProperties().forEach((columnProperty -> { + items.add(columnProperty.getName()); + })); + } + + builder.append(String.join(",", items)); + builder.append(")"); } //TODO: Enable this with foreign key functionality // if (column.getForeignKeys() != null && !column.getForeignKeys().isEmpty()) { @@ -23,4 +42,5 @@ public String nameForColumn(Column column) { // } return builder.toString(); } + } diff --git a/ddl/src/test/java/com/adaptivescale/rosetta/ddl/test/KineticaDDLTest.java b/ddl/src/test/java/com/adaptivescale/rosetta/ddl/test/KineticaDDLTest.java index a01025d2..060b7a0f 100644 --- a/ddl/src/test/java/com/adaptivescale/rosetta/ddl/test/KineticaDDLTest.java +++ b/ddl/src/test/java/com/adaptivescale/rosetta/ddl/test/KineticaDDLTest.java @@ -69,6 +69,12 @@ public void addColumn() throws IOException { Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"Position\" ADD \"DESCRIPTION\" varchar(100);", ddl); } + @Test + public void addColumnWithProperties() throws IOException { + String ddl = generateDDL("add_column_with_column_properties"); + Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"Position\" ADD \"DESCRIPTION\" varchar(100,dict);", ddl); + } + @Test public void addColumnWithForeignKey() throws IOException { String ddl = generateDDL("add_column_with_foreign_key"); @@ -100,6 +106,12 @@ public void alterColumnToNotNullable() throws IOException { Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"PLAYER\" MODIFY \"ID\" numeric NOT NULL ;", ddl); } + @Test + public void alterColumnNewProperty() throws IOException { + String ddl = generateDDL("alter_column_new_property"); + Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"PLAYER\" MODIFY \"ID\" numeric(dict);", ddl); + } + @Test public void dropColumnWithForeignKey() throws IOException { String ddl = generateDDL("drop_column_with_foreign_key"); diff --git a/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/actual_model.yaml b/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/actual_model.yaml new file mode 100644 index 00000000..f77bc3ae --- /dev/null +++ b/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/actual_model.yaml @@ -0,0 +1,141 @@ +--- +tables: + - name: "PLAYER" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "POSITION_ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "PLAYER_FK" + tableName: "PLAYER" + columnName: "POSITION_ID" + deleteRule: "3" + primaryTableName: "Position" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "Position" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "Name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "TEAM" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "country" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "TEAMPLAYERS" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "TEAMID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "TEAMPLAYERS_FK_TEAM" + tableName: "TEAMPLAYERS" + columnName: "TEAMID" + deleteRule: "3" + primaryTableName: "TEAM" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "PLAYERID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "TEAMPLAYERS_FK" + tableName: "TEAMPLAYERS" + columnName: "PLAYERID" + deleteRule: "3" + primaryTableName: "PLAYER" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false +databaseProductName: "kinetica" +databaseType: "kinetica" diff --git a/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/expected_model.yaml b/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/expected_model.yaml new file mode 100644 index 00000000..0a5fddf8 --- /dev/null +++ b/ddl/src/test/resources/ddl/kinetica/add_column_with_column_properties/expected_model.yaml @@ -0,0 +1,153 @@ +--- +tables: + - name: "PLAYER" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "POSITION_ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "PLAYER_FK" + tableName: "PLAYER" + columnName: "POSITION_ID" + deleteRule: "3" + primaryTableName: "Position" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "Position" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "DESCRIPTION" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + columnProperties: + - name: "dict" + primaryKey: false + - name: "Name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "TEAM" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "country" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true + - name: "TEAMPLAYERS" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "TEAMID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "TEAMPLAYERS_FK_TEAM" + tableName: "TEAMPLAYERS" + columnName: "TEAMID" + deleteRule: "3" + primaryTableName: "TEAM" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "PLAYERID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "TEAMPLAYERS_FK" + tableName: "TEAMPLAYERS" + columnName: "PLAYERID" + deleteRule: "3" + primaryTableName: "PLAYER" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false +databaseProductName: "kinetica" +databaseType: "kinetica" diff --git a/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/actual_model.yaml b/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/actual_model.yaml new file mode 100644 index 00000000..5f7523dc --- /dev/null +++ b/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/actual_model.yaml @@ -0,0 +1,47 @@ +--- +tables: + - name: "PLAYER" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "POSITION_ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "PLAYER_FK" + schema: "FBAL" + tableName: "PLAYER" + columnName: "POSITION_ID" + deleteRule: "3" + primaryTableSchema: "FBAL" + primaryTableName: "Position" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: false + autoincrement: false + primaryKey: true +databaseProductName: "kinetica" +databaseType: "kinetica" diff --git a/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/expected_model.yaml b/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/expected_model.yaml new file mode 100644 index 00000000..4b4fc8d0 --- /dev/null +++ b/ddl/src/test/resources/ddl/kinetica/alter_column_new_property/expected_model.yaml @@ -0,0 +1,49 @@ +--- +tables: + - name: "PLAYER" + type: "TABLE" + schema: "ROSETTA" + columns: + - name: "name" + typeName: "varchar" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 100 + nullable: true + autoincrement: false + primaryKey: false + - name: "POSITION_ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 0 + columnDisplaySize: 0 + scale: 0 + precision: 38 + foreignKeys: + - name: "PLAYER_FK" + schema: "FBAL" + tableName: "PLAYER" + columnName: "POSITION_ID" + deleteRule: "3" + primaryTableSchema: "FBAL" + primaryTableName: "Position" + primaryColumnName: "ID" + nullable: true + autoincrement: false + primaryKey: false + - name: "ID" + typeName: "numeric" + ordinalPosition: 0 + primaryKeySequenceId: 1 + columnDisplaySize: 0 + scale: 0 + precision: 38 + nullable: true + autoincrement: false + columnProperties: + - name: "dict" + primaryKey: true +databaseProductName: "kinetica" +databaseType: "kinetica" diff --git a/diff/src/main/java/com/adaptivescale/rosetta/diff/DefaultTester.java b/diff/src/main/java/com/adaptivescale/rosetta/diff/DefaultTester.java index d02643f2..190b44d1 100644 --- a/diff/src/main/java/com/adaptivescale/rosetta/diff/DefaultTester.java +++ b/diff/src/main/java/com/adaptivescale/rosetta/diff/DefaultTester.java @@ -122,6 +122,13 @@ public List find(Database localValue, Database targetValue) { columnsChangesLogs.add(result); } + if (!Objects.equals(localColumn.getColumnProperties(), targetColumn.get().getColumnProperties())) { + String result = String.format(COLUMN_CHANGED_FORMAT, localColumn.getName(), + table.getName(), "Column Properties", localColumn.columnPropertiesAsString(), + targetColumn.get().columnPropertiesAsString()); + columnsChangesLogs.add(result); + } + columnsChangesLogs.addAll(sameForeignKeys(localColumn.getForeignKeys(), targetColumn.get().getForeignKeys())); } diff --git a/source/src/main/java/com/adataptivescale/rosetta/source/core/extractors/column/KineticaColumnsExtractor.java b/source/src/main/java/com/adataptivescale/rosetta/source/core/extractors/column/KineticaColumnsExtractor.java index ae03daaa..f0232a85 100644 --- a/source/src/main/java/com/adataptivescale/rosetta/source/core/extractors/column/KineticaColumnsExtractor.java +++ b/source/src/main/java/com/adataptivescale/rosetta/source/core/extractors/column/KineticaColumnsExtractor.java @@ -19,11 +19,17 @@ import com.adaptivescale.rosetta.common.TranslationMatrix; import com.adaptivescale.rosetta.common.annotations.RosettaModule; import com.adaptivescale.rosetta.common.models.Column; +import com.adaptivescale.rosetta.common.models.ColumnProperties; import com.adaptivescale.rosetta.common.models.input.Connection; import com.adaptivescale.rosetta.common.types.RosettaModuleTypes; +import org.apache.commons.lang3.StringUtils; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; @RosettaModule( name = "kinetica", @@ -31,6 +37,8 @@ ) public class KineticaColumnsExtractor extends ColumnsExtractor { + private static final List KINETICA_PROPERTIES = Arrays.asList("DICT", "INIT_WITH_NOW", "INIT_WITH_UUID", "IPV4", "SHARD_KEY", "TEXT_SEARCH"); + public KineticaColumnsExtractor(Connection connection) { super(connection); } @@ -46,5 +54,24 @@ protected void extract(ResultSet resultSet, Column column) throws SQLException { column.setColumnDisplaySize(resultSet.getInt("COLUMN_SIZE")); column.setScale(resultSet.getInt("DECIMAL_DIGITS")); column.setPrecision(resultSet.getInt("COLUMN_SIZE")); + + String[] columnProperties = Optional.ofNullable(resultSet.getString("REMARKS")) + .map(it -> it.replace("[", "")) + .map(it -> it.replace("]", "")) + .map(it -> it.split(",")) + .orElse(new String[0]); + + List columnPropertiesList = new ArrayList<>(); + for (String columnProperty : columnProperties) { + String trimmedProperty = StringUtils.trim(columnProperty); + if (KINETICA_PROPERTIES.stream().anyMatch(trimmedProperty.toLowerCase()::equalsIgnoreCase)) { + ColumnProperties cp = new ColumnProperties(trimmedProperty, null); + columnPropertiesList.add(cp); + } + } + + column.setColumnProperties(columnPropertiesList); } + + }