From 4d6eaaa6fc7ae6829279f9a53e3001f3efcce5e3 Mon Sep 17 00:00:00 2001 From: KushnirykOleh Date: Fri, 16 Aug 2024 17:38:29 +0300 Subject: [PATCH] refactoring --- .../AddCheckConstraintChangeDatabricks.java | 51 +-- ...AddCheckConstraintGeneratorDatabricks.java | 11 +- ...AddCheckConstraintStatementDatabricks.java | 38 +- ...dForeignKeyConstraintChangeDatabricks.java | 399 ------------------ .../AddLookupTableChangeDatabricks.java | 208 +-------- .../CreateTableChangeDatabricks.java | 18 +- .../DropCheckConstraintChangeDatabricks.java | 4 +- ...ropCheckConstraintGeneratorDatabricks.java | 2 +- ...ropCheckConstraintStatementDatabricks.java | 31 +- .../optimizeTable/OptimizeTableChange.java | 36 +- .../optimizeTable/OptimizeTableStatement.java | 37 +- .../change/vacuumTable/VacuumTableChange.java | 40 +- .../vacuumTable/VacuumTableStatement.java | 21 +- .../database/DatabricksDatabase.java | 22 +- .../ArrayIntegerDataTypeDatabricks.java | 6 - .../ArrayStringDataTypeDatabricks.java | 5 - .../datatype/BigintDatatypeDatabricks.java | 17 - .../datatype/BinaryDataTypeDatabricks.java | 5 +- .../datatype/BooleanDatatypeDatabricks.java | 19 +- .../datatype/DatetimeDatatypeDatabricks.java | 13 +- .../datatype/DoubleDatatypeDatabricks.java | 20 +- .../datatype/FloatDatatypeDatabricks.java | 18 +- .../datatype/IntegerDatatypeDatabricks.java | 18 +- .../datatype/SmallintDatatypeDatabricks.java | 14 +- .../datatype/StringDatatypeDatabricks.java | 17 +- .../datatype/TimestampDatatypeDatabricks.java | 21 - .../datatype/TinyintDatatypeDatabricks.java | 15 +- .../executor/DatabricksExecutor.java | 34 -- ...ForeignKeySnapshotGeneratorDatabricks.java | 3 - .../jvm/IndexSnapshotGeneratorDatabricks.java | 1 - .../SchemaSnapshotGeneratorDatabricks.java | 10 - .../AddColumnGeneratorDatabricks.java | 8 +- ...reignKeyConstraintGeneratorDatabricks.java | 4 - .../AddPrimaryKeyGeneratorDatabricks.java | 13 +- .../CreateTableGeneratorDatabricks.java | 37 +- .../RenameColumnGeneratorDatabricks.java | 17 +- .../RenameTableGeneratorDatabricks.java | 15 - .../RenameViewGeneratorDatabricks.java | 18 - .../services/liquibase.executor.Executor | 1 - 39 files changed, 114 insertions(+), 1153 deletions(-) delete mode 100644 src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java delete mode 100644 src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java delete mode 100644 src/main/resources/META-INF/services/liquibase.executor.Executor diff --git a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java index ff0033f6..da5f4296 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java @@ -6,6 +6,8 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; +import lombok.Getter; +import lombok.Setter; import java.text.MessageFormat; @@ -14,56 +16,27 @@ priority = PrioritizedService.PRIORITY_DATABASE, appliesTo = {"column"} ) +@Setter +@Getter public class AddCheckConstraintChangeDatabricks extends AbstractChange { private String catalogName; private String schemaName; private String tableName; - private String constraintName; - private String constraintBody; - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName(String catalogName) { - this.catalogName = catalogName; - } - - public String getTableName() { - return tableName; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName(String schemaName) { - this.schemaName = schemaName; - } - // Name of Delta Table Constraint @DatabaseChangeProperty(description = "Name of the check constraint") public String getConstraintName() { return this.constraintName; } - public void setConstraintName(String name) { - this.constraintName = name; - } - // This is the SQL expression involving the constraint @DatabaseChangeProperty( serializationType = SerializationType.DIRECT_VALUE @@ -72,10 +45,6 @@ public String getConstraintBody() { return this.constraintBody; } - public void setConstraintBody(String body) { - this.constraintBody = body; - } - @Override public String getConfirmationMessage() { return MessageFormat.format("{0}.{1}.{2} successfully Added check constraint {3}.", getCatalogName(), getSchemaName(), getTableName(), @@ -83,13 +52,13 @@ public String getConfirmationMessage() { } protected Change[] createInverses() { - DropCheckConstraintChangeDatabricks var1 = new DropCheckConstraintChangeDatabricks(); - var1.setTableName(getTableName()); - var1.setSchemaName(getSchemaName()); - var1.setCatalogName(getCatalogName()); - var1.setConstraintName(getConstraintName()); + DropCheckConstraintChangeDatabricks inverse = new DropCheckConstraintChangeDatabricks(); + inverse.setTableName(getTableName()); + inverse.setSchemaName(getSchemaName()); + inverse.setCatalogName(getCatalogName()); + inverse.setConstraintName(getConstraintName()); - return new Change[]{var1}; + return new Change[]{inverse}; } @Override diff --git a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java index 24b06c4d..58729505 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java @@ -1,17 +1,11 @@ package liquibase.ext.databricks.change.addCheckConstraint; - import liquibase.database.Database; import liquibase.exception.ValidationErrors; -import liquibase.ext.databricks.change.addCheckConstraint.AddCheckConstraintStatementDatabricks; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.sqlgenerator.SqlGeneratorChain; -import liquibase.database.Database; -import liquibase.exception.ValidationErrors; -import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; -import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.sqlgenerator.core.AbstractSqlGenerator; public class AddCheckConstraintGeneratorDatabricks extends AbstractSqlGenerator { @@ -44,10 +38,7 @@ public Sql[] generateSql(AddCheckConstraintStatementDatabricks statement, Databa // Constrinat Name sql.append(statement.getConstraintName()); - sql.append(" CHECK ("); - - sql.append(statement.getConstraintBody().toString() + ")"); - + sql.append(" CHECK (").append(statement.getConstraintBody()).append(")"); return new Sql[] { new UnparsedSql(sql.toString()) }; diff --git a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java index 8d39489d..ff692de1 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java @@ -1,45 +1,15 @@ package liquibase.ext.databricks.change.addCheckConstraint; import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class AddCheckConstraintStatementDatabricks extends AbstractSqlStatement { private String catalogName; private String schemaName; private String tableName; private String constraintName; private String constraintBody; - - - public String getCatalogName() { - return this.catalogName; - } - - public void setCatalogName(String catalogName) {this.catalogName = catalogName;} - - - public String getSchemaName() { - return this.schemaName; - } - - public void setSchemaName(String schemaName) {this.schemaName = schemaName;} - - public String getTableName() { - return this.tableName; - } - - public void setTableName(String tableName) {this.tableName = tableName;} - - public String getConstraintName() { - return this.constraintName; - } - - public void setConstraintName(String constraintName) {this.constraintName = constraintName;} - - public String getConstraintBody() { - return this.constraintBody; - } - - public void setConstraintBody(String constraintBody) { - this.constraintBody = constraintBody; - } } diff --git a/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java deleted file mode 100644 index ae55635d..00000000 --- a/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java +++ /dev/null @@ -1,399 +0,0 @@ -package liquibase.ext.databricks.change.addForeignKeyConstraint; - -import liquibase.change.*; -import liquibase.database.Database; -import liquibase.database.DatabaseFactory; -import liquibase.exception.UnexpectedLiquibaseException; -import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.servicelocator.PrioritizedService; -import liquibase.snapshot.SnapshotGeneratorFactory; -import liquibase.statement.SqlStatement; -import liquibase.statement.core.AddForeignKeyConstraintStatement; -import liquibase.structure.core.Column; -import liquibase.structure.core.ForeignKey; -import liquibase.structure.core.ForeignKeyConstraintType; -import liquibase.structure.core.Table; -import liquibase.change.core.AddForeignKeyConstraintChange; -import liquibase.change.core.DropForeignKeyConstraintChange; -import java.util.ArrayList; -import java.util.List; - -/** - * Adds a foreign key constraint to an existing column. - */ -@DatabaseChange(name = "addForeignKeyConstraint", - description = "Adds a foreign key constraint to an existing column", - priority = PrioritizedService.PRIORITY_DATABASE, - appliesTo = "column") -//TODO this class need refactoring as it copies parent class instead of properly inheriting it. -public class AddForeignKeyConstraintChangeDatabricks extends AddForeignKeyConstraintChange { - - private String baseTableCatalogName; - private String baseTableSchemaName; - private String baseTableName; - private String baseColumnNames; - - private String referencedTableCatalogName; - private String referencedTableSchemaName; - private String referencedTableName; - private String referencedColumnNames; - - private String constraintName; - - private Boolean deferrable; - private Boolean initiallyDeferred; - private Boolean shouldValidate; - - private String onUpdate; - private String onDelete; - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } - - @Override - protected String[] createSupportedDatabasesMetaData( - String parameterName, DatabaseChangeProperty changePropertyAnnotation) { - if ("deferrable".equals(parameterName) || "initiallyDeferred".equals(parameterName)) { - List supported = new ArrayList<>(); - for (Database database : DatabaseFactory.getInstance().getImplementedDatabases()) { - if (database.supportsInitiallyDeferrableColumns()) { - supported.add(database.getShortName()); - } - } - return supported.toArray(new String[0]); - - } else { - return super.createSupportedDatabasesMetaData(parameterName, changePropertyAnnotation); - } - } - - @DatabaseChangeProperty(since = "3.0", mustEqualExisting ="column.relation.catalog", - description = "Name of the database catalog of the base table") - public String getBaseTableCatalogName() { - return baseTableCatalogName; - } - - public void setBaseTableCatalogName(String baseTableCatalogName) { - this.baseTableCatalogName = baseTableCatalogName; - } - - @DatabaseChangeProperty(mustEqualExisting ="column.relation.schema", description = "Name of the database schema of the base table") - public String getBaseTableSchemaName() { - return baseTableSchemaName; - } - - public void setBaseTableSchemaName(String baseTableSchemaName) { - this.baseTableSchemaName = baseTableSchemaName; - } - - @DatabaseChangeProperty( - description = "Name of the table containing the column to constrain", - exampleValue = "address", - mustEqualExisting = "column.relation" - ) - public String getBaseTableName() { - return baseTableName; - } - - public void setBaseTableName(String baseTableName) { - this.baseTableName = baseTableName; - } - - @DatabaseChangeProperty( - description = "Name of the column(s) to place the foreign key constraint on. Comma-separate if multiple", - exampleValue = "person_id", - mustEqualExisting = "column" - ) - public String getBaseColumnNames() { - return baseColumnNames; - } - - public void setBaseColumnNames(String baseColumnNames) { - this.baseColumnNames = baseColumnNames; - } - - @DatabaseChangeProperty(since = "3.0", mustEqualExisting = "column", - description = "Name of the database catalog of the referenced table") - public String getReferencedTableCatalogName() { - return referencedTableCatalogName; - } - - public void setReferencedTableCatalogName(String referencedTableCatalogName) { - this.referencedTableCatalogName = referencedTableCatalogName; - } - - @DatabaseChangeProperty(description = "Name of the database schema of the referenced table") - public String getReferencedTableSchemaName() { - return referencedTableSchemaName; - } - - public void setReferencedTableSchemaName(String referencedTableSchemaName) { - this.referencedTableSchemaName = referencedTableSchemaName; - } - - @DatabaseChangeProperty( - description = "Name of the table the foreign key points to", - exampleValue = "person") - public String getReferencedTableName() { - return referencedTableName; - } - - public void setReferencedTableName(String referencedTableName) { - this.referencedTableName = referencedTableName; - } - - @DatabaseChangeProperty( - description = "Name of the column(s) the foreign key points to. Comma-separate if multiple", - exampleValue = "id") - public String getReferencedColumnNames() { - return referencedColumnNames; - } - - public void setReferencedColumnNames(String referencedColumnNames) { - this.referencedColumnNames = referencedColumnNames; - } - - @DatabaseChangeProperty(description = "Name of the new foreign key constraint", exampleValue = "fk_address_person") - public String getConstraintName() { - return constraintName; - } - - public void setConstraintName(String constraintName) { - this.constraintName = constraintName; - } - - @DatabaseChangeProperty(description = "Defines whether the foreign key is deferrable") - public Boolean getDeferrable() { - return deferrable; - } - - public void setDeferrable(Boolean deferrable) { - this.deferrable = deferrable; - } - - @DatabaseChangeProperty(description = "Defines whether the foreign key is initially deferred") - public Boolean getInitiallyDeferred() { - return initiallyDeferred; - } - - public void setInitiallyDeferred(Boolean initiallyDeferred) { - this.initiallyDeferred = initiallyDeferred; - } - - /** - * the VALIDATE keyword defines whether to check if a foreign key constraint - * on a column in a table refers to a valid row or not. - * @return true if ENABLE VALIDATE (this is the default), or false if ENABLE NOVALIDATE. - */ - @DatabaseChangeProperty(description = "Defines whether to check if the foreign key constraint refers to a valid row. " + - "This is true if the foreign key has 'ENABLE VALIDATE' set, or false if the foreign key has 'ENABLE NOVALIDATE' set.") - public Boolean getValidate() { - return shouldValidate; - } - - /** - * - * @param shouldValidate - if shouldValidate is set to FALSE then the constraint will be created - * with the 'ENABLE NOVALIDATE' mode. This means the constraint would be created, but that no - * check will be done to ensure old data has valid foreign keys - only new data would be checked - * to see if it complies with the constraint logic. The default state for foreign keys is to - * have 'ENABLE VALIDATE' set. - */ - public void setValidate(Boolean shouldValidate) { - this.shouldValidate = shouldValidate; - } - - /** - * @deprecated Use {@link #getOnDelete()}. - * This always returns null so it doesn't impact checksums when settings onDelete vs. deleteCascade - */ - @DatabaseChangeProperty( - description = "Deprecated. This is true to set onDelete to Cascade, priority given to onDelete tag if one exists") - public Boolean getDeleteCascade() { - return null; - } - - public void setDeleteCascade(Boolean deleteCascade) { - if ((deleteCascade != null) && deleteCascade && (this.onDelete == null)) { - setOnDelete("CASCADE"); - } else { - setOnDelete((String) null); - } - } - - public void setOnUpdate(String rule) { - this.onUpdate = rule; - } - - @DatabaseChangeProperty( - description = "ON UPDATE functionality. Possible values: 'CASCADE', 'SET NULL', 'SET DEFAULT', " + - "'RESTRICT', 'NO ACTION'", - exampleValue = "RESTRICT") - public String getOnUpdate() { - return onUpdate; - } - - @DatabaseChangeProperty(description = "ON DELETE functionality. Possible values: 'CASCADE', 'SET NULL', " + - "'SET DEFAULT', 'RESTRICT', 'NO ACTION'", - exampleValue = "CASCADE") - public String getOnDelete() { - return this.onDelete; - } - - public void setOnDelete(String onDelete) { - this.onDelete = onDelete; - } - - public void setOnDelete(ForeignKeyConstraintType rule) { - if (rule == null) { - //nothing - } else if (rule == ForeignKeyConstraintType.importedKeyCascade) { - setOnDelete("CASCADE"); - } else if (rule == ForeignKeyConstraintType.importedKeySetNull) { - setOnDelete("SET NULL"); - } else if (rule == ForeignKeyConstraintType.importedKeySetDefault) { - setOnDelete("SET DEFAULT"); - } else if (rule == ForeignKeyConstraintType.importedKeyRestrict) { - setOnDelete("RESTRICT"); - } else if (rule == ForeignKeyConstraintType.importedKeyNoAction){ - setOnDelete("NO ACTION"); - } else { - throw new UnexpectedLiquibaseException("Unknown onDelete action: "+rule); - } - } - - public void setOnUpdate(ForeignKeyConstraintType rule) { - if (rule == null) { - //nothing - } else if (rule == ForeignKeyConstraintType.importedKeyCascade) { - setOnUpdate("CASCADE"); - } else if (rule == ForeignKeyConstraintType.importedKeySetNull) { - setOnUpdate("SET NULL"); - } else if (rule == ForeignKeyConstraintType.importedKeySetDefault) { - setOnUpdate("SET DEFAULT"); - } else if (rule == ForeignKeyConstraintType.importedKeyRestrict) { - setOnUpdate("RESTRICT"); - } else if (rule == ForeignKeyConstraintType.importedKeyNoAction) { - setOnUpdate("NO ACTION"); - } else { - throw new UnexpectedLiquibaseException("Unknown onUpdate action: "+onUpdate); - } - } - - @Override - public SqlStatement[] generateStatements(Database database) { - - // Databricks FKs are deferrable and initially deffered by default - - boolean deferrable = true; - if (getDeferrable() != null) { - deferrable = getDeferrable(); - } - - boolean initiallyDeferred = true; - if (getInitiallyDeferred() != null) { - initiallyDeferred = getInitiallyDeferred(); - } - - boolean shouldValidate = true; - if (getValidate() != null) { - shouldValidate = getValidate(); - } - - return new SqlStatement[]{ - new AddForeignKeyConstraintStatement(getConstraintName(), - getBaseTableCatalogName(), - getBaseTableSchemaName(), - getBaseTableName(), - ColumnConfig.arrayFromNames(getBaseColumnNames()), - getReferencedTableCatalogName(), - getReferencedTableSchemaName(), - getReferencedTableName(), - ColumnConfig.arrayFromNames(getReferencedColumnNames())) - .setDeferrable(deferrable) - .setInitiallyDeferred(initiallyDeferred) - .setOnUpdate(getOnUpdate()) - .setOnDelete(getOnDelete()) - .setShouldValidate(shouldValidate) - }; - } - - @Override - protected Change[] createInverses() { - DropForeignKeyConstraintChange inverse = new DropForeignKeyConstraintChange(); - inverse.setBaseTableSchemaName(getBaseTableSchemaName()); - inverse.setBaseTableName(getBaseTableName()); - inverse.setConstraintName(getConstraintName()); - - return new Change[]{ - inverse - }; - } - - @Override - public ChangeStatus checkStatus(Database database) { - ChangeStatus result = new ChangeStatus(); - try { - ForeignKey example = new ForeignKey( - getConstraintName(), - getBaseTableCatalogName(), - getBaseTableSchemaName(), - getBaseTableName() - ); - example.setPrimaryKeyTable( - new Table(getReferencedTableCatalogName(), getReferencedTableSchemaName(), getReferencedTableName()) - ); - example.setForeignKeyColumns(Column.listFromNames(getBaseColumnNames())); - example.setPrimaryKeyColumns(Column.listFromNames(getReferencedColumnNames())); - - ForeignKey snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(example, database); - result.assertComplete(snapshot != null, "Foreign key does not exist"); - - if (snapshot != null) { - if (getInitiallyDeferred() != null) { - result.assertCorrect( - getInitiallyDeferred().equals(snapshot.isInitiallyDeferred()), - "Initially deferred incorrect" - ); - } - if (getDeferrable() != null) { - result.assertCorrect( - getDeferrable().equals(snapshot.isDeferrable()), - "Initially deferred incorrect" - ); - } - if (getValidate() != null) { - result.assertCorrect(getValidate().equals(snapshot.shouldValidate()), "validate incorrect"); - } - } - - return result; - } catch (Exception e) { - return result.unknown(e); - } - } - - @Override - public String getConfirmationMessage() { - return "Foreign key constraint added to " + getBaseTableName() + " (" + getBaseColumnNames() + ")"; - } - - /** - * @deprecated No longer supported in 3.0 - */ - @Deprecated - @DatabaseChangeProperty(description = "Deprecated") - public Boolean getReferencesUniqueColumn() { - return null; - } - - public void setReferencesUniqueColumn(Boolean referencesUniqueColumn) { - } - - @Override - public String getSerializedObjectNamespace() { - return STANDARD_CHANGELOG_NAMESPACE; - } -} \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java index b9ba8f03..d6f08175 100644 --- a/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java @@ -6,174 +6,35 @@ import liquibase.change.core.*; import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.Scope; import liquibase.change.*; import liquibase.database.Database; -import liquibase.database.core.Db2zDatabase; -import liquibase.database.core.OracleDatabase; -import liquibase.exception.ValidationErrors; import liquibase.servicelocator.PrioritizedService; -import liquibase.snapshot.SnapshotGeneratorFactory; import liquibase.statement.SqlStatement; -import liquibase.statement.core.RawSqlStatement; +import liquibase.statement.core.RawParameterizedSqlStatement; import liquibase.structure.core.Column; -import liquibase.structure.core.ForeignKey; -import liquibase.structure.core.Table; import liquibase.change.core.AddLookupTableChange; +import static liquibase.statement.SqlStatement.EMPTY_SQL_STATEMENT; + /** * Extracts data from an existing column to create a lookup table. * A foreign key is created between the old column and the new lookup table. */ -//TODO this class need refactoring as it copies parent class instead of properly inheriting it. -@DatabaseChange(name = "addLookupTable", priority = PrioritizedService.PRIORITY_DATABASE, appliesTo = "column", +@DatabaseChange(name = "addLookupTable", priority = PrioritizedService.PRIORITY_DATABASE, appliesTo = "column", description = "Creates a lookup table containing values stored in a column and creates a foreign key to the new table.") public class AddLookupTableChangeDatabricks extends AddLookupTableChange { - private String existingTableCatalogName; - private String existingTableSchemaName; - private String existingTableName; - private String existingColumnName; - - private String newTableCatalogName; - private String newTableSchemaName; - private String newTableName; - private String newColumnName; - private String newColumnDataType; - private String constraintName; - - @Override - public ValidationErrors validate(Database database) { - ValidationErrors errors = super.validate(database); - if (database instanceof Db2zDatabase) { - if (this.getNewColumnDataType() == null) { - errors.addError("newColumnDataType is required for " + Scope.getCurrentScope().getSingleton(ChangeFactory.class).getChangeMetaData(this).getName() + " on " + database.getShortName()); - } - } - return errors; - } - - @DatabaseChangeProperty(description = "Name of the database catalog of the existing table") - public String getExistingTableCatalogName() { - return existingTableCatalogName; - } - - public void setExistingTableCatalogName(String existingTableCatalogName) { - this.existingTableCatalogName = existingTableCatalogName; - } - - @DatabaseChangeProperty(mustEqualExisting ="column.relation.schema", description = "Name of the database schema where the table containing data to extract resides") - public String getExistingTableSchemaName() { - return existingTableSchemaName; - } - - public void setExistingTableSchemaName(String existingTableSchemaName) { - this.existingTableSchemaName = existingTableSchemaName; - } - - @DatabaseChangeProperty(mustEqualExisting = "column.relation", description = "Name of the table containing the data to extract", - exampleValue = "address") - public String getExistingTableName() { - return existingTableName; - } - - public void setExistingTableName(String existingTableName) { - this.existingTableName = existingTableName; - } - - @DatabaseChangeProperty(mustEqualExisting = "column", description = "Name of the column containing the data to extract", - exampleValue = "state") - public String getExistingColumnName() { - return existingColumnName; - } - - public void setExistingColumnName(String existingColumnName) { - this.existingColumnName = existingColumnName; - } - - @DatabaseChangeProperty(description = "Name of the database catalog for the lookup table") - public String getNewTableCatalogName() { - return newTableCatalogName; - } - - public void setNewTableCatalogName(String newTableCatalogName) { - this.newTableCatalogName = newTableCatalogName; - } - - @DatabaseChangeProperty(description = "Name of the database schema for the lookup table") - public String getNewTableSchemaName() { - return newTableSchemaName; - } - - public void setNewTableSchemaName(String newTableSchemaName) { - this.newTableSchemaName = newTableSchemaName; - } - - @DatabaseChangeProperty(description = "Name of lookup table to create", exampleValue = "state") - public String getNewTableName() { - return newTableName; - } - - public void setNewTableName(String newTableName) { - this.newTableName = newTableName; - } - - @DatabaseChangeProperty(description = "Name of the column in the new table to create", exampleValue = "abbreviation") - public String getNewColumnName() { - return newColumnName; - } - - public void setNewColumnName(String newColumnName) { - this.newColumnName = newColumnName; - } - - @DatabaseChangeProperty(description = "Data type of the new table column", exampleValue = "char(2)") - public String getNewColumnDataType() { - return newColumnDataType; - } - - public void setNewColumnDataType(String newColumnDataType) { - this.newColumnDataType = newColumnDataType; - } - - @DatabaseChangeProperty(description = "Name of the foreign key constraint to create between the existing table and the lookup table", - exampleValue = "fk_address_state") - public String getConstraintName() { - return constraintName; - } - public String getFinalConstraintName() { - if (constraintName == null) { + if (getConstraintName() == null) { return ("fk_" + getExistingTableName() + "_" + getNewTableName()).toLowerCase(); } else { - return constraintName; + return getConstraintName(); } } - public void setConstraintName(String constraintName) { - this.constraintName = constraintName; - } - @Override public boolean supports(Database database) { - return (database instanceof DatabricksDatabase); - } - - @Override - protected Change[] createInverses() { - DropForeignKeyConstraintChange dropFK = new DropForeignKeyConstraintChange(); - dropFK.setBaseTableSchemaName(getExistingTableSchemaName()); - dropFK.setBaseTableName(getExistingTableName()); - dropFK.setConstraintName(getFinalConstraintName()); - - DropTableChange dropTable = new DropTableChange(); - dropTable.setSchemaName(getNewTableSchemaName()); - dropTable.setTableName(getNewTableName()); - - return new Change[]{ - dropFK, - dropTable, - }; + return (database instanceof DatabricksDatabase); } @Override @@ -185,9 +46,10 @@ public SqlStatement[] generateStatements(Database database) { String existingTableCatalogName = getExistingTableCatalogName(); String existingTableSchemaName = getExistingTableSchemaName(); - SqlStatement[] createTablesSQL = {new RawSqlStatement("CREATE TABLE " + database.escapeTableName(newTableCatalogName, newTableSchemaName, getNewTableName()) - + " USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') " - + " AS SELECT DISTINCT " + database.escapeObjectName(getExistingColumnName(), Column.class) + SqlStatement[] createTablesSQL = {new RawParameterizedSqlStatement("CREATE TABLE " + database.escapeTableName(newTableCatalogName, newTableSchemaName + , getNewTableName()) + + " USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') " + + " AS SELECT DISTINCT " + database.escapeObjectName(getExistingColumnName(), Column.class) + " AS " + database.escapeObjectName(getNewColumnName(), Column.class) + " FROM " + database.escapeTableName(existingTableCatalogName, existingTableSchemaName, getExistingTableName()) + " WHERE " + database.escapeObjectName(getExistingColumnName(), Column.class) @@ -196,14 +58,12 @@ public SqlStatement[] generateStatements(Database database) { List statements = new ArrayList<>(Arrays.asList(createTablesSQL)); - if (!(database instanceof OracleDatabase) && !(database instanceof Db2zDatabase)) { - AddNotNullConstraintChange addNotNullChange = new AddNotNullConstraintChange(); - addNotNullChange.setSchemaName(newTableSchemaName); - addNotNullChange.setTableName(getNewTableName()); - addNotNullChange.setColumnName(getNewColumnName()); - addNotNullChange.setColumnDataType(getNewColumnDataType()); - statements.addAll(Arrays.asList(addNotNullChange.generateStatements(database))); - } + AddNotNullConstraintChange addNotNullChange = new AddNotNullConstraintChange(); + addNotNullChange.setSchemaName(newTableSchemaName); + addNotNullChange.setTableName(getNewTableName()); + addNotNullChange.setColumnName(getNewColumnName()); + addNotNullChange.setColumnDataType(getNewColumnDataType()); + statements.addAll(Arrays.asList(addNotNullChange.generateStatements(database))); AddPrimaryKeyChange addPKChange = new AddPrimaryKeyChange(); addPKChange.setSchemaName(newTableSchemaName); @@ -223,39 +83,7 @@ public SqlStatement[] generateStatements(Database database) { addFKChange.setConstraintName(getFinalConstraintName()); statements.addAll(Arrays.asList(addFKChange.generateStatements(database))); - return statements.toArray(new SqlStatement[0]); - } - - @Override - public ChangeStatus checkStatus(Database database) { - ChangeStatus result = new ChangeStatus(); - try { - Table newTableExample = new Table(getNewTableCatalogName(), getNewTableSchemaName(), getNewTableName()); - Column newColumnExample = new Column(Table.class, getNewTableCatalogName(), getNewTableSchemaName(), getNewTableName(), getNewColumnName()); - - ForeignKey foreignKeyExample = new ForeignKey(getConstraintName(), getExistingTableCatalogName(), getExistingTableSchemaName(), getExistingTableName()); - foreignKeyExample.setPrimaryKeyTable(newTableExample); - foreignKeyExample.setForeignKeyColumns(Column.listFromNames(getExistingColumnName())); - foreignKeyExample.setPrimaryKeyColumns(Column.listFromNames(getNewColumnName())); - - result.assertComplete(SnapshotGeneratorFactory.getInstance().has(newTableExample, database), "New table does not exist"); - result.assertComplete(SnapshotGeneratorFactory.getInstance().has(newColumnExample, database), "New column does not exist"); - result.assertComplete(SnapshotGeneratorFactory.getInstance().has(foreignKeyExample, database), "Foreign key does not exist"); - - return result; - - } catch (Exception e) { - return result.unknown(e); - } - } - - @Override - public String getConfirmationMessage() { - return "Lookup table added for "+getExistingTableName()+"."+getExistingColumnName(); + return statements.toArray(EMPTY_SQL_STATEMENT); } - @Override - public String getSerializedObjectNamespace() { - return STANDARD_CHANGELOG_NAMESPACE; - } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java index a6d087af..9d226cef 100644 --- a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java @@ -8,11 +8,12 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.core.CreateTableStatement; +import lombok.Setter; @DatabaseChange(name = "createTable", description = "Create Table", priority = PrioritizedService.PRIORITY_DATABASE) +@Setter public class CreateTableChangeDatabricks extends CreateTableChange { - private String tableFormat; private String tableLocation; private String clusterColumns; @@ -38,8 +39,6 @@ public ValidationErrors validate(Database database) { @DatabaseChangeProperty public String getTableFormat() {return tableFormat;} - public void setTableFormat(String tableFormat) {this.tableFormat = tableFormat;} - @DatabaseChangeProperty public String getTableLocation() { return tableLocation; @@ -53,16 +52,6 @@ public String getClusterColumns() { @DatabaseChangeProperty public String getPartitionColumns() {return partitionColumns; } - public void setTableLocation(String tableLocation) {this.tableLocation = tableLocation;} - - @DatabaseChangeProperty - public void setClusterColumns(String clusterColumns) { - this.clusterColumns = clusterColumns; - } - - @DatabaseChangeProperty - public void setPartitionColumns(String partitionColumns) { this.partitionColumns = partitionColumns; } - @Override protected CreateTableStatement generateCreateTableStatement() { @@ -82,7 +71,4 @@ public ExtendedTableProperties getExtendedTableProperties() { return extendedTableProperties; } - public void setExtendedTableProperties(ExtendedTableProperties extendedTableProperties) { - this.extendedTableProperties = extendedTableProperties; - } } diff --git a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java index 88248af6..2139d10c 100644 --- a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java @@ -85,8 +85,6 @@ public SqlStatement[] generateStatements(Database database) { statement.setTableName(getTableName()); statement.setConstraintName(getConstraintName()); - SqlStatement[] builtStatement = new SqlStatement[] {statement}; - - return builtStatement; + return new SqlStatement[] {statement}; } } diff --git a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintGeneratorDatabricks.java index 0fbad922..17e6fcf9 100644 --- a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintGeneratorDatabricks.java @@ -35,7 +35,7 @@ public Sql[] generateSql(DropCheckConstraintStatementDatabricks statement, Datab sql.append(" DROP CONSTRAINT "); - // Constrinat Name + // Constraint Name sql.append(statement.getConstraintName()); return new Sql[] { new UnparsedSql(sql.toString()) }; diff --git a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintStatementDatabricks.java b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintStatementDatabricks.java index da6d102e..b7ce4421 100644 --- a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintStatementDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintStatementDatabricks.java @@ -1,38 +1,15 @@ package liquibase.ext.databricks.change.dropCheckConstraint; import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class DropCheckConstraintStatementDatabricks extends AbstractSqlStatement { private String catalogName; private String schemaName; private String tableName; private String constraintName; - private boolean validate = true; - - - public String getCatalogName() { - return this.catalogName; - } - - public void setCatalogName(String catalogName) {this.catalogName = catalogName;} - - - public String getSchemaName() { - return this.schemaName; - } - - public void setSchemaName(String schemaName) {this.schemaName = schemaName;} - - public String getTableName() { - return this.tableName; - } - - public void setTableName(String tableName) {this.tableName = tableName;} - - public String getConstraintName() { - return this.constraintName; - } - - public void setConstraintName(String constraintName) {this.constraintName = constraintName;} } diff --git a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java index 54d9681f..47c89d40 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java @@ -9,10 +9,14 @@ import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import liquibase.change.Change; +import lombok.Getter; +import lombok.Setter; import java.text.MessageFormat; import java.util.ArrayList; +@Setter +@Getter @DatabaseChange(name = "optimizeTable", description = "Optimize and ZOrder Table", priority = PrioritizedService.PRIORITY_DATABASE) public class OptimizeTableChange extends AbstractChange { @@ -21,38 +25,6 @@ public class OptimizeTableChange extends AbstractChange { private String tableName; private String zorderColumns; - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName (String catalogName) { - this.catalogName = catalogName; - } - - public String getTableName() { - return tableName; - } - - public void setTableName (String tableName) { - this.tableName = tableName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName (String schemaName) { - this.schemaName = schemaName; - } - - public String getZorderColumns () { - return zorderColumns; - } - - public void setZorderColumns (String zorderColumns) { - this.zorderColumns = zorderColumns; - } - @Override public String getConfirmationMessage() { return MessageFormat.format("{0}.{1}.{2} successfully optimized.", getCatalogName(), getSchemaName(), getTableName()); diff --git a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java index 9d466d45..24805429 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java @@ -2,12 +2,15 @@ import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; import java.util.ArrayList; import java.util.Arrays; - +@Setter +@Getter public class OptimizeTableStatement extends AbstractSqlStatement { private String catalogName; @@ -15,39 +18,11 @@ public class OptimizeTableStatement extends AbstractSqlStatement { private String tableName; private ArrayList zorderColumns = new ArrayList<>(); - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName (String catalogName) { - this.catalogName = catalogName; - } - - public String getTableName() { - return tableName; - } - - public void setTableName (String tableName) { - this.tableName = tableName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName (String schemaName) { - this.schemaName = schemaName; - } - - public ArrayList getZorderColumns () { - return zorderColumns; - } - - public void setZorderColumns (ArrayList zorderColumns) { + public void setZorderColumns(ArrayList zorderColumns) { this.zorderColumns = zorderColumns; } - public void setZorderColumns (String zorderColumns) { + public void setZorderColumns(String zorderColumns) { if (zorderColumns == null) { this.zorderColumns = new ArrayList<>(); return; diff --git a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java index 65177f3a..e93af016 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java @@ -9,9 +9,13 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; +import lombok.Getter; +import lombok.Setter; import java.text.MessageFormat; +@Setter +@Getter @DatabaseChange(name = "vacuumTable", description = "Vacuum Old Files from Table", priority = PrioritizedService.PRIORITY_DATABASE) public class VacuumTableChange extends AbstractChange { @@ -20,38 +24,6 @@ public class VacuumTableChange extends AbstractChange { private String tableName; private Integer retentionHours; - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName (String catalogName) { - this.catalogName = catalogName; - } - - public String getTableName() { - return tableName; - } - - public void setTableName (String tableName) { - this.tableName = tableName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName (String schemaName) { - this.schemaName = schemaName; - } - - public Integer getRetentionHours () { - return this.retentionHours; - } - - public void setRetentionHours (Integer retentionHours) { - this.retentionHours = retentionHours; - } - @Override public String getConfirmationMessage() { return MessageFormat.format("{0}.{1}.{2} successfully vacuumed.", getCatalogName(), getSchemaName(), getTableName()); @@ -88,8 +60,6 @@ public SqlStatement[] generateStatements(Database database) { statement.setRetentionHours(getRetentionHours()); } - SqlStatement[] builtStatement = new SqlStatement[] {statement}; - - return builtStatement; + return new SqlStatement[] {statement}; } } diff --git a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java index 3eddabce..57280663 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java @@ -2,7 +2,11 @@ import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class VacuumTableStatement extends AbstractSqlStatement { private String catalogName; @@ -14,21 +18,4 @@ public class VacuumTableStatement extends AbstractSqlStatement { private Integer retentionHours; - public String getCatalogName() {return this.catalogName;} - - public String getSchemaName() {return this.schemaName;} - - public String getTableName() {return this.tableName;} - - public Integer getRetentionHours() {return this.retentionHours;} - - - public void setCatalogName(String catalogName) { this.catalogName = catalogName;} - - public void setSchemaName(String schemaName) { this.schemaName = schemaName;} - - public void setTableName(String tableName) {this.tableName = tableName;} - - public void setRetentionHours(Integer retentionHours) {this.retentionHours = retentionHours;} - } diff --git a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java index ea58755d..3d3ee95b 100644 --- a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java +++ b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java @@ -10,6 +10,7 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.Catalog; import liquibase.structure.core.Schema; +import lombok.Setter; import java.math.BigInteger; import java.sql.ResultSet; @@ -22,6 +23,7 @@ public class DatabricksDatabase extends AbstractJdbcDatabase { public static final String PRODUCT_NAME = "databricks"; // Set default catalog - must be unity Catalog Enabled + @Setter private String systemSchema = "information_schema"; // This is from the new INFORMATION_SCHEMA() database @@ -110,7 +112,7 @@ public String getDefaultDriver(String url) { @Override public boolean supportsInitiallyDeferrableColumns() { - return false; + return true; } @Override @@ -170,21 +172,6 @@ public String getAutoIncrementClause(final BigInteger startWith, final BigIntege return autoIncrementClause; } - @Override - protected String getAutoIncrementClause() { - return "GENERATED BY DEFAULT AS IDENTITY"; - } - - @Override - protected String getAutoIncrementStartWithClause() { - return "START WITH %d"; - } - - @Override - protected String getAutoIncrementByClause() { - return "INCREMENT BY %d"; - } - @Override public boolean generateAutoIncrementStartWith(BigInteger startWith) { return true; @@ -286,9 +273,6 @@ public void setDefaultCatalogName(final String catalogName) { this.defaultCatalogName = correctObjectName(catalogName, Catalog.class); } - public void setSystemSchema(String systemSchema) {this.systemSchema = systemSchema;} - - private Set getDatabricksReservedWords() { // Get Reserved words from: https://docs.databricks.com/sql/language-manual/sql-ref-reserved-words.html diff --git a/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java index f2bfe059..ab8510c8 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java @@ -11,17 +11,11 @@ @DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class ArrayIntegerDataTypeDatabricks extends LiquibaseDataType { - - public ArrayIntegerDataTypeDatabricks() { - // empty constructor - } - @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { return new DatabaseDataType("ARARY"); } - return super.toDatabaseDataType(database); } diff --git a/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java index 1a153e60..44db13bb 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java @@ -11,16 +11,11 @@ @DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class ArrayStringDataTypeDatabricks extends LiquibaseDataType { - - public ArrayStringDataTypeDatabricks() { - // empty constructor - } @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { return new DatabaseDataType("ARARY"); } - return super.toDatabaseDataType(database); } diff --git a/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java index 57dd17a0..a3a45c48 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java @@ -14,23 +14,11 @@ minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class BigintDatatypeDatabricks extends BigIntType { - private boolean autoIncrement; - - @Override - public boolean isAutoIncrement() { - return autoIncrement; - } - - public void setAutoIncrement(boolean autoIncrement) { - this.autoIncrement = autoIncrement; - } - @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { return new DatabaseDataType("BIGINT"); } - return super.toDatabaseDataType(database); } @@ -38,9 +26,4 @@ public DatabaseDataType toDatabaseDataType(Database database) { public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - - @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; - } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java index 25080e88..15d0e620 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java @@ -8,18 +8,15 @@ import liquibase.servicelocator.PrioritizedService; @DataTypeInfo(name = "binary", aliases = {"longblob", "java.sql.Types.BLOB", - "java.sql.Types.BINARY", "tinyblob", "mediumblob"}, minParameters = 0, maxParameters = 0 + "java.sql.Types.BINARY", "tinyblob", "mediumblob"}, minParameters = 0, maxParameters = 0 , priority = PrioritizedService.PRIORITY_DATABASE) public class BinaryDataTypeDatabricks extends BlobType { - @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof DatabricksDatabase) { return new DatabaseDataType("BINARY"); } - return super.toDatabaseDataType(database); } diff --git a/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java index 768fe5ce..7151eb50 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java @@ -1,10 +1,9 @@ package liquibase.ext.databricks.datatype; -import liquibase.change.core.LoadDataChange; import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.BooleanType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -15,21 +14,11 @@ aliases = {"java.sql.Types.BOOLEAN", "java.lang.Boolean", "bit", "bool"}, priority = PrioritizedService.PRIORITY_DATABASE ) -public class BooleanDatatypeDatabricks extends LiquibaseDataType { - - public BooleanDatatypeDatabricks() { - // empty constructor - } - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } +public class BooleanDatatypeDatabricks extends BooleanType { @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { - DatabaseDataType type = new DatabaseDataType("BOOLEAN", this.getParameters()); type.setType("BOOLEAN"); return type; @@ -40,7 +29,7 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.BOOLEAN; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java index 478f9cfe..ac6ce694 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java @@ -5,6 +5,7 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.DateTimeType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -15,28 +16,18 @@ maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE ) -public class DatetimeDatatypeDatabricks extends LiquibaseDataType { - +public class DatetimeDatatypeDatabricks extends DateTimeType { @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof DatabricksDatabase) { return new DatabaseDataType("TIMESTAMP"); } - return super.toDatabaseDataType(database); } - @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.DATE; - } - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - - } diff --git a/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java index 8b944812..e7321d3d 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java @@ -1,10 +1,9 @@ package liquibase.ext.databricks.datatype; -import liquibase.change.core.LoadDataChange; import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.DoubleType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -15,32 +14,21 @@ aliases = {"java.sql.Types.DOUBLE", "java.lang.Double"}, priority = PrioritizedService.PRIORITY_DATABASE ) -public class DoubleDatatypeDatabricks extends LiquibaseDataType { - - public DoubleDatatypeDatabricks() { - // empty constructor - } - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } +public class DoubleDatatypeDatabricks extends DoubleType { @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { - DatabaseDataType type = new DatabaseDataType("DOUBLE", this.getParameters()); type.setType("DOUBLE"); return type; } else { return super.toDatabaseDataType(database); } - } @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java index 41c188bb..336deb27 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java @@ -4,7 +4,7 @@ import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.FloatType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -16,31 +16,21 @@ aliases = {"java.sql.Types.FLOAT", "java.lang.Float"}, priority = PrioritizedService.PRIORITY_DATABASE ) -public class FloatDatatypeDatabricks extends LiquibaseDataType { - public FloatDatatypeDatabricks() { - // empty constructor - } - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } +public class FloatDatatypeDatabricks extends FloatType { @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { - DatabaseDataType type = new DatabaseDataType("FLOAT", this.getParameters()); type.setType("FLOAT"); return type; } else { return super.toDatabaseDataType(database); } - } @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java index bdf234f6..4bec6600 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java @@ -4,7 +4,7 @@ import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.IntType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -16,31 +16,21 @@ aliases = {"integer", "java.sql.Types.INTEGER", "java.lang.Integer"}, priority = PrioritizedService.PRIORITY_DATABASE ) -public class IntegerDatatypeDatabricks extends LiquibaseDataType { - public IntegerDatatypeDatabricks() { - // empty constructor - } - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } +public class IntegerDatatypeDatabricks extends IntType { @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { - DatabaseDataType type = new DatabaseDataType("INT", this.getParameters()); type.setType("INT"); return type; } else { return super.toDatabaseDataType(database); } - } @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java index 4c5a98f3..631229e2 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java @@ -4,7 +4,7 @@ import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.SmallIntType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -15,28 +15,18 @@ maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE ) -public class SmallintDatatypeDatabricks extends LiquibaseDataType { - +public class SmallintDatatypeDatabricks extends SmallIntType { @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof DatabricksDatabase) { return new DatabaseDataType("SMALLINT"); } - return super.toDatabaseDataType(database); } - @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; - } - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - - } diff --git a/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java index 21c969f5..e267e026 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java @@ -1,6 +1,5 @@ package liquibase.ext.databricks.datatype; -import liquibase.change.core.LoadDataChange; import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; @@ -13,33 +12,23 @@ minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE, - aliases = {"clob", "java.lang.String" } + aliases = {"clob", "java.lang.String"} ) public class StringDatatypeDatabricks extends VarcharType { - public StringDatatypeDatabricks() { - } - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } @Override public DatabaseDataType toDatabaseDataType(Database database) { if (database instanceof DatabricksDatabase) { - DatabaseDataType type = new DatabaseDataType("STRING"); - type.setType("STRING"); - return type; } else { return super.toDatabaseDataType(database); } - } @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.STRING; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java index 072c5df8..bd685c4b 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java @@ -131,21 +131,7 @@ public DatabaseDataType toDatabaseDataType(Database database) { && additionInformation.toUpperCase(Locale.US).contains("TIMEZONE")) { additionalInformation = additionInformation.toUpperCase(Locale.US).replace("TIMEZONE", "TIME ZONE"); } - // CORE-3229 Oracle 11g doesn't support WITHOUT clause in TIMESTAMP data type - if ((database instanceof OracleDatabase) && additionInformation.startsWith("WITHOUT")) { - // https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm#sthref389 - additionalInformation = null; - } - - if ((database instanceof H2Database) && additionInformation.startsWith("WITHOUT")) { - // http://www.h2database.com/html/datatypes.html - additionalInformation = null; - } - if ((database instanceof SybaseASADatabase) && additionInformation.startsWith("WITHOUT")) { - // https://help.sap.com/docs/SAP_SQL_Anywhere/93079d4ba8e44920ae63ffb4def91f5b/81fe3e6b6ce2101487d8acce02f6aba5.html - additionalInformation = null; - } } type.addAdditionalInformation(additionalInformation); @@ -159,11 +145,4 @@ public DatabaseDataType toDatabaseDataType(Database database) { public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - - @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.DATE; - } - - } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java index 96e9b551..d51b5821 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java @@ -1,10 +1,9 @@ package liquibase.ext.databricks.datatype; -import liquibase.change.core.LoadDataChange; import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.TinyIntType; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; @@ -15,28 +14,18 @@ maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE ) -public class TinyintDatatypeDatabricks extends LiquibaseDataType { - +public class TinyintDatatypeDatabricks extends TinyIntType { @Override public DatabaseDataType toDatabaseDataType(Database database) { - if (database instanceof DatabricksDatabase) { return new DatabaseDataType("TINYINT"); } - return super.toDatabaseDataType(database); } - @Override - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { - return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; - } - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - - } diff --git a/src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java b/src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java deleted file mode 100644 index a185e27a..00000000 --- a/src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java +++ /dev/null @@ -1,34 +0,0 @@ -package liquibase.ext.databricks.executor; - - -import liquibase.database.Database; -import liquibase.exception.DatabaseException; -import liquibase.executor.jvm.JdbcExecutor; -import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.servicelocator.PrioritizedService; -import liquibase.sql.visitor.SqlVisitor; -import liquibase.statement.SqlStatement; -import java.util.List; - -public class DatabricksExecutor extends JdbcExecutor { - - @Override - public int getPriority() { - return PrioritizedService.PRIORITY_DATABASE; - } - - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } - - @Override - public void execute(SqlStatement sql) throws DatabaseException { - super.execute(sql); - } - - @Override - public void execute(SqlStatement sql, List sqlVisitors) throws DatabaseException { - super.execute(sql, sqlVisitors); - } -} \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java index d9a49860..d15b3642 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java @@ -2,7 +2,6 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.snapshot.*; -import liquibase.snapshot.jvm.JdbcSnapshotGenerator; import liquibase.CatalogAndSchema; import liquibase.database.AbstractJdbcDatabase; import liquibase.database.Database; @@ -14,8 +13,6 @@ import liquibase.database.jvm.JdbcConnection; import liquibase.diff.compare.DatabaseObjectComparatorFactory; import liquibase.exception.DatabaseException; -import liquibase.snapshot.jvm.SequenceSnapshotGenerator; -import liquibase.snapshot.jvm.UniqueConstraintSnapshotGenerator; import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; import java.sql.DatabaseMetaData; diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java index 1ff5619f..ec1e3c10 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java @@ -8,7 +8,6 @@ import liquibase.snapshot.InvalidExampleException; import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.SnapshotGeneratorChain; -import liquibase.snapshot.jvm.ForeignKeySnapshotGenerator; import liquibase.snapshot.jvm.IndexSnapshotGenerator; import liquibase.structure.DatabaseObject; diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/SchemaSnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/SchemaSnapshotGeneratorDatabricks.java index 4bff6d2a..8b3c186b 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/SchemaSnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/SchemaSnapshotGeneratorDatabricks.java @@ -1,22 +1,12 @@ package liquibase.ext.databricks.snapshot.jvm; -import liquibase.CatalogAndSchema; import liquibase.database.Database; -import liquibase.database.ObjectQuotingStrategy; import liquibase.database.jvm.JdbcConnection; -import liquibase.diff.compare.DatabaseObjectComparatorFactory; import liquibase.exception.DatabaseException; -import liquibase.ext.databricks.database.DatabricksConnection; import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.snapshot.DatabaseSnapshot; -import liquibase.snapshot.InvalidExampleException; import liquibase.snapshot.jvm.SchemaSnapshotGenerator; import liquibase.structure.DatabaseObject; -import liquibase.structure.core.Catalog; -import liquibase.structure.core.Data; -import liquibase.structure.core.Schema; -import liquibase.util.JdbcUtils; import liquibase.util.JdbcUtil; import java.sql.ResultSet; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java index fa64ebeb..fe3e743f 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java @@ -13,8 +13,6 @@ import liquibase.statement.core.AddColumnStatement; import org.apache.commons.lang3.StringUtils; -import java.util.Iterator; - public class AddColumnGeneratorDatabricks extends AddColumnGenerator { @Override @@ -46,12 +44,10 @@ protected String generateSingleColumnSQL(AddColumnStatement statement, Database alterTable.append(this.getDefaultClauseForColumn(statement, database)); if (!statement.isNullable()) { - Iterator var8 = statement.getConstraints().iterator(); - while(var8.hasNext()) { - ColumnConstraint constraint = var8.next(); + for (ColumnConstraint constraint : statement.getConstraints()) { if (constraint instanceof NotNullConstraint) { - NotNullConstraint notNullConstraint = (NotNullConstraint)constraint; + NotNullConstraint notNullConstraint = (NotNullConstraint) constraint; if (StringUtils.isNotEmpty(notNullConstraint.getConstraintName())) { alterTable.append(" CONSTRAINT ").append(database.escapeConstraintName(notNullConstraint.getConstraintName())); break; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java index 1402f68c..79e0f840 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java @@ -74,8 +74,4 @@ public Sql[] generateSql(AddForeignKeyConstraintStatement statement, Database da }; } - @Override - protected ForeignKey getAffectedForeignKey(AddForeignKeyConstraintStatement statement) { - return new ForeignKey().setName(statement.getConstraintName()).setForeignKeyColumns(Column.listFromNames(statement.getBaseColumnNames())).setForeignKeyTable((Table) new Table().setName(statement.getBaseTableName()).setSchema(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName())); - } } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java index d92123a6..a8ae4ae3 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java @@ -1,16 +1,14 @@ package liquibase.ext.databricks.sqlgenerator; -import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; import liquibase.database.core.*; import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; -import liquibase.statement.core.AddPrimaryKeyStatement; -import liquibase.structure.core.PrimaryKey; -import liquibase.structure.core.Table; import liquibase.sqlgenerator.core.AddPrimaryKeyGenerator; +import liquibase.statement.core.AddPrimaryKeyStatement; public class AddPrimaryKeyGeneratorDatabricks extends AddPrimaryKeyGenerator { @@ -53,16 +51,13 @@ public ValidationErrors validate(AddPrimaryKeyStatement addPrimaryKeyStatement, @Override public Sql[] generateSql(AddPrimaryKeyStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; - sql = "ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " ADD CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName())+" PRIMARY KEY"; + sql = "ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " ADD CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName()) + " PRIMARY KEY"; sql += " (" + database.escapeColumnNameList(statement.getColumnNames()) + ")"; - return new Sql[] { + return new Sql[]{ new UnparsedSql(sql, getAffectedPrimaryKey(statement)) }; } - protected PrimaryKey getAffectedPrimaryKey(AddPrimaryKeyStatement statement) { - return new PrimaryKey().setTable((Table) new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName())); - } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java index 739470b6..cfda44f3 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java @@ -41,22 +41,22 @@ public ValidationErrors validate(CreateTableStatementDatabricks createStatement, public Sql[] generateSql(CreateTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { Sql[] sqls = super.generateSql(statement, database, sqlGeneratorChain); - String finalsql = sqls[0].toSql(); + StringBuilder finalsql = new StringBuilder(sqls[0].toSql()); if (statement instanceof CreateTableStatementDatabricks) { CreateTableStatementDatabricks thisStatement = (CreateTableStatementDatabricks) statement; if ((!StringUtils.isEmpty(thisStatement.getTableFormat()))) { - finalsql += " USING " + thisStatement.getTableFormat(); + finalsql.append(" USING ").append(thisStatement.getTableFormat()); } else if (thisStatement.getExtendedTableProperties() != null && StringUtils.isNoneEmpty(thisStatement.getExtendedTableProperties().getTblProperties())) { - finalsql += " TBLPROPERTIES (" + thisStatement.getExtendedTableProperties().getTblProperties() + ")"; + finalsql.append(" TBLPROPERTIES (").append(thisStatement.getExtendedTableProperties().getTblProperties()).append(")"); } else { - finalsql += " USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true)"; + finalsql.append(" USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true)"); } // Databricks can decide to have tables live in a particular location. If null, Databricks will handle the location automatically in DBFS if (!StringUtils.isEmpty(thisStatement.getTableLocation())) { - finalsql += " LOCATION '" + thisStatement.getTableLocation() + "'"; + finalsql.append(" LOCATION '").append(thisStatement.getTableLocation()).append("'"); } ArrayList clusterCols = thisStatement.getClusterColumns(); @@ -65,48 +65,43 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG // If there are any cluster columns, add the clause // ONLY if there are NOT cluster columns, then do partitions, but never both. - if (clusterCols.size() >= 1 ) { + if (!clusterCols.isEmpty()) { - finalsql += " CLUSTER BY ("; + finalsql.append(" CLUSTER BY ("); int val = 0; while (clusterCols.size() > val) { - finalsql += clusterCols.get(val); + finalsql.append(clusterCols.get(val)); val +=1; if (clusterCols.size() > val) { - finalsql += ", "; + finalsql.append(", "); } else { - finalsql += ")"; + finalsql.append(")"); } } - } else if (partitionCols.size() >=1) { - finalsql += " PARTITIONED BY ("; + } else if (!partitionCols.isEmpty()) { + finalsql.append(" PARTITIONED BY ("); int val = 0; while (partitionCols.size() > val) { - finalsql += partitionCols.get(val); + finalsql.append(partitionCols.get(val)); val +=1; if (partitionCols.size() > val) { - finalsql += ", "; + finalsql.append(", "); } else { - finalsql += ")"; + finalsql.append(")"); } } } - } else { - // Not a Delta Table - finalsql += ""; } - //} - - sqls[0] = new UnparsedSql(finalsql, sqls[0].getAffectedDatabaseObjects().toArray(new DatabaseObject[0])); + sqls[0] = new UnparsedSql(finalsql.toString(), sqls[0].getAffectedDatabaseObjects().toArray(new DatabaseObject[0])); return sqls; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java index be8c688b..eace19b4 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java @@ -1,18 +1,14 @@ package liquibase.ext.databricks.sqlgenerator; -import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; -import liquibase.database.core.*; -import liquibase.datatype.DataTypeFactory; -import liquibase.exception.DatabaseException; +import liquibase.database.core.MySQLDatabase; import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; -import liquibase.statement.core.RenameColumnStatement; -import liquibase.structure.core.Column; -import liquibase.structure.core.Table; import liquibase.sqlgenerator.core.RenameColumnGenerator; +import liquibase.statement.core.RenameColumnStatement; import org.apache.commons.lang3.StringUtils; public class RenameColumnGeneratorDatabricks extends RenameColumnGenerator { @@ -53,11 +49,4 @@ public Sql[] generateSql(RenameColumnStatement statement, Database database, Sql }; } - protected Column getAffectedOldColumn(RenameColumnStatement statement) { - return new Column().setName(statement.getOldColumnName()).setRelation(new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName())); - } - - protected Column getAffectedNewColumn(RenameColumnStatement statement) { - return new Column().setName(statement.getNewColumnName()).setRelation(new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName())); - } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java index 9561d62b..a0b2e655 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java @@ -26,14 +26,6 @@ public int getPriority() { } - @Override - public ValidationErrors validate(RenameTableStatement renameTableStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { - ValidationErrors validationErrors = new ValidationErrors(); - validationErrors.checkRequiredField("newTableName", renameTableStatement.getNewTableName()); - validationErrors.checkRequiredField("oldTableName", renameTableStatement.getOldTableName()); - return validationErrors; - } - @Override public Sql[] generateSql(RenameTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; @@ -48,11 +40,4 @@ public Sql[] generateSql(RenameTableStatement statement, Database database, SqlG }; } - protected Relation getAffectedNewTable(RenameTableStatement statement) { - return new Table().setName(statement.getNewTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName()); - } - - protected Relation getAffectedOldTable(RenameTableStatement statement) { - return new Table().setName(statement.getOldTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName()); - } } \ No newline at end of file diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java index 54827a58..fc7eac21 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java @@ -26,17 +26,6 @@ public int getPriority() { } - @Override - public ValidationErrors validate(RenameViewStatement renameViewStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { - ValidationErrors validationErrors = new ValidationErrors(); - validationErrors.checkRequiredField("oldViewName", renameViewStatement.getOldViewName()); - validationErrors.checkRequiredField("newViewName", renameViewStatement.getNewViewName()); - - validationErrors.checkDisallowedField("schemaName", renameViewStatement.getSchemaName(), database, OracleDatabase.class); - - return validationErrors; - } - @Override public Sql[] generateSql(RenameViewStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; @@ -52,11 +41,4 @@ public Sql[] generateSql(RenameViewStatement statement, Database database, SqlGe }; } - protected Relation getAffectedNewView(RenameViewStatement statement) { - return new View().setName(statement.getNewViewName()).setSchema(statement.getCatalogName(), statement.getSchemaName()); - } - - protected Relation getAffectedOldView(RenameViewStatement statement) { - return new View().setName(statement.getOldViewName()).setSchema(statement.getCatalogName(), statement.getSchemaName()); - } } \ No newline at end of file diff --git a/src/main/resources/META-INF/services/liquibase.executor.Executor b/src/main/resources/META-INF/services/liquibase.executor.Executor deleted file mode 100644 index 0b734acf..00000000 --- a/src/main/resources/META-INF/services/liquibase.executor.Executor +++ /dev/null @@ -1 +0,0 @@ -liquibase.ext.databricks.executor.DatabricksExecutor \ No newline at end of file