Skip to content

Commit

Permalink
Merge pull request #200 from AdaptiveScale/release-2.1.2
Browse files Browse the repository at this point in the history
Release 2.1.2
  • Loading branch information
nbesimi authored Feb 28, 2024
2 parents c75c658 + fae01bb commit 1b789c3
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = 'com.adaptivescale'
version = '2.1.1'
version = '2.1.2'
sourceCompatibility = 11
targetCompatibility = 11
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -19,8 +21,8 @@ public class Column {
private int columnDisplaySize;
private int scale;
private int precision;
private List<ColumnProperties> columnProperties = new ArrayList<>();
private Tests tests;

private List<ForeignKey> foreignKeys;

public Column() {
Expand Down Expand Up @@ -138,12 +140,26 @@ public void setPrecision(int precision) {
this.precision = precision;
}

public List<ColumnProperties> getColumnProperties() {
return columnProperties;
}

public String columnPropertiesAsString() {
return Optional.ofNullable(columnProperties)
.map(it -> it.toString())
.orElse("");

}

public void setColumnProperties(List<ColumnProperties> columnProperties) {
this.columnProperties = columnProperties;
}

public Tests getTests() {
return tests;
}

public void setTests(Tests tests) {
this.tests = tests;
}

}
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ private List<Change<?>> 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<Column> columnChange = ChangeFactory.columnChange(expectedColumn, actualColumn, Change.Status.ALTER, expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> params = new HashMap<>();
params.put("schemaName", table.getSchema());
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,13 +19,28 @@ 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<String> 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()) {
// builder.append(SHARD_KEY);
// }
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit 1b789c3

Please sign in to comment.