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 da5f4296..e8041465 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java @@ -51,6 +51,7 @@ public String getConfirmationMessage() { getConstraintName()); } + @Override protected Change[] createInverses() { DropCheckConstraintChangeDatabricks inverse = new DropCheckConstraintChangeDatabricks(); inverse.setTableName(getTableName()); 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 58729505..cc5fca13 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintGeneratorDatabricks.java @@ -35,7 +35,7 @@ public Sql[] generateSql(AddCheckConstraintStatementDatabricks statement, Databa sql.append(" ADD CONSTRAINT "); - // Constrinat Name + // Constraint Name sql.append(statement.getConstraintName()); sql.append(" CHECK (").append(statement.getConstraintBody()).append(")"); 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 d6f08175..5205ee56 100644 --- a/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java @@ -24,6 +24,7 @@ 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 { + @Override public String getFinalConstraintName() { if (getConstraintName() == null) { return ("fk_" + getExistingTableName() + "_" + getNewTableName()).toLowerCase(); diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java index b2b832d7..ff4b163f 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java @@ -7,6 +7,7 @@ import liquibase.exception.ValidationErrors; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; +import lombok.Setter; import java.text.MessageFormat; import java.util.ArrayList; @@ -14,6 +15,7 @@ import static liquibase.ext.databricks.parser.NamespaceDetailsDatabricks.DATABRICKS_NAMESPACE; +@Setter @DatabaseChange(name = "alterCluster", description = "Alter Cluster", priority = PrioritizedService.PRIORITY_DATABASE +500) public class AlterClusterChangeDatabricks extends AbstractChange { @@ -61,10 +63,6 @@ public String getTableName() { return tableName; } - public void setTableName(String tableName) { - this.tableName = tableName; - } - @DatabaseChangeProperty public List getColumns() { if (columns == null) { @@ -73,28 +71,16 @@ public List getColumns() { return columns; } - public void setColumns(List columns) { - this.columns = columns; - } - @DatabaseChangeProperty public String getCatalogName() { return catalogName; } - public void setCatalogName(String catalogName) { - this.catalogName = catalogName; - } - @DatabaseChangeProperty public String getSchemaName() { return schemaName; } - public void setSchemaName(String schemaName) { - this.schemaName = schemaName; - } - @DatabaseChangeProperty public List getClusterBy() { if (clusterBy == null) { @@ -103,10 +89,6 @@ public List getClusterBy() { return clusterBy; } - public void setClusterBy(List clusterBy) { - this.clusterBy = clusterBy; - } - @Override public String getSerializedObjectNamespace() { return DATABRICKS_NAMESPACE; diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java index 3d644af4..e4f4d70c 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java @@ -1,9 +1,13 @@ package liquibase.ext.databricks.change.alterCluster; import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; import java.util.List; +@Getter +@Setter public class AlterClusterDatabricksStatement extends AbstractSqlStatement { private String tableName; @@ -17,44 +21,4 @@ public AlterClusterDatabricksStatement(String tableName, String catalogName, Str this.catalogName = catalogName; this.schemaName = schemaName; } - - public String getTableName() { - return tableName; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - public List getColumns() { - return columns; - } - - public void setColumns(List columns) { - this.columns = columns; - } - - public String getCatalogName() { - return catalogName; - } - - public void setCatalogName(String catalogName) { - this.catalogName = catalogName; - } - - public String getSchemaName() { - return schemaName; - } - - public void setSchemaName(String schemaName) { - this.schemaName = schemaName; - } - - public List getClusterBy() { - return clusterBy; - } - - public void setClusterBy(List clusterBy) { - this.clusterBy = clusterBy; - } } diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/ColumnConfig.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/ColumnConfig.java index ecf53504..07af9bf3 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterCluster/ColumnConfig.java +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/ColumnConfig.java @@ -1,7 +1,11 @@ package liquibase.ext.databricks.change.alterCluster; import liquibase.serializer.AbstractLiquibaseSerializable; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter public class ColumnConfig extends AbstractLiquibaseSerializable { private String name; @@ -15,12 +19,4 @@ public String getSerializedObjectName() { public String getSerializedObjectNamespace() { return "http://www.liquibase.org/xml/ns/databricks"; } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/NoneConfig.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/NoneConfig.java index 448a4db6..7b05dcba 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterCluster/NoneConfig.java +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/NoneConfig.java @@ -1,7 +1,11 @@ package liquibase.ext.databricks.change.alterCluster; import liquibase.serializer.AbstractLiquibaseSerializable; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter public class NoneConfig extends AbstractLiquibaseSerializable { private String none; @@ -16,11 +20,4 @@ public String getSerializedObjectNamespace() { return "http://www.liquibase.org/xml/ns/databricks"; } - public String getNone() { - return none; - } - - public void setNone(String none) { - this.none = none; - } } diff --git a/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesChangeDatabricks.java index 295a559a..fe6b3096 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesChangeDatabricks.java @@ -4,7 +4,6 @@ import liquibase.change.DatabaseChangeProperty; import liquibase.database.Database; import liquibase.ext.databricks.change.AbstractAlterPropertiesChangeDatabricks; -import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import lombok.Setter; @@ -16,11 +15,6 @@ public class AlterTablePropertiesChangeDatabricks extends AbstractAlterPropertie private static final String CHANGE_TYPE_SUBJECT = "Table"; private String tableName; - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } - @Override protected String getNoPropertiesErrorMessage() { return applySubjectToErrorPattern(CHANGE_TYPE_SUBJECT); diff --git a/src/main/java/liquibase/ext/databricks/change/alterViewProperties/AlterViewPropertiesChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/alterViewProperties/AlterViewPropertiesChangeDatabricks.java index 0f74ca33..cb7adff7 100644 --- a/src/main/java/liquibase/ext/databricks/change/alterViewProperties/AlterViewPropertiesChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/alterViewProperties/AlterViewPropertiesChangeDatabricks.java @@ -4,7 +4,6 @@ import liquibase.change.DatabaseChangeProperty; import liquibase.database.Database; import liquibase.ext.databricks.change.AbstractAlterPropertiesChangeDatabricks; -import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import lombok.Setter; @@ -16,11 +15,6 @@ public class AlterViewPropertiesChangeDatabricks extends AbstractAlterProperties private static final String CHANGE_TYPE_SUBJECT = "View"; private String viewName; - @Override - public boolean supports(Database database) { - return database instanceof DatabricksDatabase; - } - @Override protected String getNoPropertiesErrorMessage() { return applySubjectToErrorPattern(CHANGE_TYPE_SUBJECT); diff --git a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java index f72b3082..76c992c6 100644 --- a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java @@ -8,11 +8,17 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; +import lombok.Getter; +import lombok.Setter; + import java.util.Collections; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.List; import java.util.Map; +@Getter +@Setter @DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = PrioritizedService.PRIORITY_DATABASE) public class AnalyzeTableChange extends AbstractChange { @@ -21,39 +27,7 @@ public class AnalyzeTableChange extends AbstractChange { private String tableName; private Map partition = Collections.emptyMap(); - private ArrayList analyzeColumns = 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 Map getPartition () {return this.partition;} - - public ArrayList getAnalyzeColumns () {return this.analyzeColumns;} - - public void setPartition (Map partition) {this.partition = partition;} - - public void setAnalyzeColumns (ArrayList analyzeColumns) {this.analyzeColumns = analyzeColumns;} + private List analyzeColumns = new ArrayList<>(); @Override public boolean supports(Database database) { @@ -67,7 +41,7 @@ public String getConfirmationMessage() { @Override protected Change[] createInverses() { - // No Op for Databricks ANALYZE statement. there is no rolling this back. Its just a stats collection operation + // No Op for Databricks ANALYZE statement. there is no rolling this back. It's just a stats collection operation return new Change[]{ }; } @@ -88,14 +62,13 @@ public SqlStatement[] generateStatements(Database database) { } if (getAnalyzeColumns() == null) { - ArrayList noColsArray = new ArrayList<> (); + List noColsArray = new ArrayList<> (); statement.setAnalyzeColumns(noColsArray); } else { statement.setAnalyzeColumns(getAnalyzeColumns()); } - SqlStatement[] builtStatement = new SqlStatement[] {statement}; - return builtStatement; + return new SqlStatement[] {statement}; } } diff --git a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableGenerator.java b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableGenerator.java index 5bd28b8c..58d2ebc7 100644 --- a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableGenerator.java +++ b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableGenerator.java @@ -27,7 +27,7 @@ public ValidationErrors validate(AnalyzeTableStatement statement, Database datab validationErrors.checkRequiredField("tableName", statement.getTableName()); // if analyzeColumns columns if null, dont add to sql statement - just use defaults (all columns) - // If parititon is null, skip + // If partition is null, skip return validationErrors; } @@ -46,13 +46,13 @@ public Sql[] generateSql(AnalyzeTableStatement statement, Database database, Sql String partitionColumnValue = partitionMap.getValue(); // append partition column for each map element, but there should only be one - sql.append(" PARTITION (" + partitionColumnName + " = '" + partitionColumnValue + "') "); + sql.append(" PARTITION (").append(partitionColumnName).append(" = '").append(partitionColumnValue).append("') "); } if (!statement.getAnalyzeColumns().isEmpty()) { - sql.append("COMPUTE STATISTICS FOR COLUMNS (" + String.join(", ", statement.getAnalyzeColumns()) + ")"); + sql.append("COMPUTE STATISTICS FOR COLUMNS (").append(String.join(", ", statement.getAnalyzeColumns())).append(")"); } else { sql.append(" COMPUTE STATISTICS"); diff --git a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableStatement.java b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableStatement.java index f16e8911..5d4586d5 100644 --- a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableStatement.java @@ -1,39 +1,22 @@ package liquibase.ext.databricks.change.analyzeTable; import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; + import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Collections; +@Getter +@Setter public class AnalyzeTableStatement extends AbstractSqlStatement { private String catalogName; - private String schemaName; - private String tableName; - - private ArrayList analyzeColumns = new ArrayList<>(); - + private List analyzeColumns = new ArrayList<>(); private Map partition = Collections.emptyMap(); - public String getCatalogName() {return catalogName;} - - public String getSchemaName() {return schemaName;} - - public String getTableName() {return tableName;} - - public ArrayList getAnalyzeColumns() {return analyzeColumns;} - - public Map getPartition() {return partition;} - 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 setAnalyzeColumns(ArrayList analyzeColumns) {this.analyzeColumns = analyzeColumns;} - - public void setPartition(Map partition) {this.partition = partition;} - } diff --git a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java index c8b9af1a..47bebc5e 100644 --- a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java @@ -2,19 +2,21 @@ import liquibase.statement.core.CreateTableStatement; +import lombok.Getter; +import lombok.Setter; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +@Getter +@Setter public class CreateTableStatementDatabricks extends CreateTableStatement { private String tableFormat; private String tableLocation; - - private ArrayList clusterColumns; - - private ArrayList partitionColumns; - + private List clusterColumns; + private List partitionColumns; private ExtendedTableProperties extendedTableProperties; @@ -22,23 +24,7 @@ public CreateTableStatementDatabricks(String catalogName, String schemaName, Str super(catalogName, schemaName, tableName); } - public void setTableFormat(String tableFormat) {this.tableFormat = tableFormat;} - - public String getTableFormat() {return this.tableFormat;} - - public void setTableLocation(String tableLocation) { this.tableLocation = tableLocation;} - - public String getTableLocation() {return this.tableLocation;} - public ArrayList getClusterColumns () { - return clusterColumns; - } - - public ArrayList getPartitionColumns () { - return partitionColumns; - } - - - public void setPartitionColumns (String partitionColumns) { + public void setPartitionColumns(String partitionColumns) { if (partitionColumns == null) { this.partitionColumns = new ArrayList<>(); return; @@ -46,21 +32,11 @@ public void setPartitionColumns (String partitionColumns) { this.partitionColumns = new ArrayList<>(Arrays.asList(partitionColumns.split("\\s*,\\s*"))); } - - - public void setClusterColumns (String clusterColumns) { + public void setClusterColumns(String clusterColumns) { if (clusterColumns == null) { this.clusterColumns = new ArrayList<>(); return; } this.clusterColumns = new ArrayList<>(Arrays.asList(clusterColumns.split("\\s*,\\s*"))); } - - 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 2139d10c..d957a6a6 100644 --- a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java @@ -8,42 +8,21 @@ 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 = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = PrioritizedService.PRIORITY_DATABASE) public class DropCheckConstraintChangeDatabricks extends AbstractChange { private String catalogName; private String schemaName; private String tableName; - private String constraintName; - 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; - } - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; @@ -57,10 +36,6 @@ public String getConstraintName() { return this.constraintName; } - public void setConstraintName(String name) { - this.constraintName = name; - } - @Override public String getConfirmationMessage() { 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 47c89d40..5b68973d 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java @@ -2,7 +2,6 @@ import liquibase.change.AbstractChange; -import liquibase.change.ChangeMetaData; import liquibase.change.DatabaseChange; import liquibase.database.Database; import liquibase.ext.databricks.database.DatabricksDatabase; @@ -59,9 +58,8 @@ public SqlStatement[] generateStatements(Database database) { } else { statement.setZorderColumns(getZorderColumns()); } - SqlStatement[] builtStatement = new SqlStatement[] {statement}; - return builtStatement; + return new SqlStatement[] {statement}; } } diff --git a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableGenerator.java b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableGenerator.java index 4aae0b88..36d0fa00 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableGenerator.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableGenerator.java @@ -11,7 +11,6 @@ public class OptimizeTableGenerator extends AbstractSqlGenerator { @Override - //check support for optimizer operation public boolean supports(OptimizeTableStatement statement, Database database) { return database instanceof DatabricksDatabase; } @@ -37,7 +36,7 @@ public Sql[] generateSql(OptimizeTableStatement statement, Database database, Sq if (!statement.getZorderColumns().isEmpty()) { - sql.append(" ZORDER BY (" + String.join(", ", statement.getZorderColumns()) + ")"); + sql.append(" ZORDER BY (").append(String.join(", ", statement.getZorderColumns())).append(")"); } return new Sql[] { new UnparsedSql(sql.toString()) }; 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 24805429..c966cc05 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableStatement.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.List; @Setter @@ -16,7 +17,7 @@ public class OptimizeTableStatement extends AbstractSqlStatement { private String catalogName; private String schemaName; private String tableName; - private ArrayList zorderColumns = new ArrayList<>(); + private List zorderColumns = new ArrayList<>(); public void setZorderColumns(ArrayList zorderColumns) { this.zorderColumns = zorderColumns; 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 e93af016..b38f3542 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java @@ -3,7 +3,6 @@ import liquibase.change.AbstractChange; import liquibase.change.Change; -import liquibase.change.ChangeMetaData; import liquibase.change.DatabaseChange; import liquibase.database.Database; import liquibase.ext.databricks.database.DatabricksDatabase; diff --git a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableGenerator.java b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableGenerator.java index 9ab3a863..13f09fc2 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableGenerator.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableGenerator.java @@ -39,7 +39,7 @@ public Sql[] generateSql(VacuumTableStatement statement, Database database, SqlG if (statement.getRetentionHours() != null) { - sql.append(" RETAIN " + statement.getRetentionHours().toString() + " HOURS "); + sql.append(" RETAIN ").append(statement.getRetentionHours().toString()).append(" HOURS "); } return new Sql[] { new UnparsedSql(sql.toString()) }; 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 57280663..5e7a013d 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableStatement.java @@ -10,12 +10,8 @@ public class VacuumTableStatement extends AbstractSqlStatement { private String catalogName; - private String schemaName; - private String tableName; - private Integer retentionHours; - } diff --git a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java index 60833af7..e82ff42d 100644 --- a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java +++ b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java @@ -176,21 +176,6 @@ private String buildAutoIncrementClause(final BigInteger startWith, final BigInt return clauseBuilder.toString(); } - @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; diff --git a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java index bd685c4b..63211ffb 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java @@ -73,8 +73,8 @@ public DatabaseDataType toDatabaseDataType(Database database) { */ DatabaseDataType type; - if (getParameters().length > 0 && !(database instanceof SybaseASADatabase)) { - int fractionalDigits = 0; + if (getParameters().length > 0) { + int fractionalDigits; String fractionalDigitsInput = getParameters()[0].toString(); try { fractionalDigits = Integer.parseInt(fractionalDigitsInput); @@ -91,13 +91,10 @@ public DatabaseDataType toDatabaseDataType(Database database) { "%d digits. Because of this, the number of digits was reduced to %d.", fractionalDigits, database.getDatabaseProductName(), maxFractionalDigits, maxFractionalDigits) ); - fractionalDigits = maxFractionalDigits; } // Do not return parameter p for Databricks - type = new DatabaseDataType("TIMESTAMP"); - } else { - type = new DatabaseDataType("TIMESTAMP"); } + type = new DatabaseDataType("TIMESTAMP"); if (originalDefinition.startsWith("java.sql.Types.TIMESTAMP_WITH_TIMEZONE") && (database instanceof PostgresDatabase 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 d15b3642..8c5d15df 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ForeignKeySnapshotGeneratorDatabricks.java @@ -53,7 +53,7 @@ public Class[] replaces() { @Override - protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException { if (!snapshot.getSnapshotControl().shouldInclude(ForeignKey.class)) { return; } @@ -85,7 +85,7 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro } @Override - protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { + protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException { Database database = snapshot.getDatabase(); @@ -102,9 +102,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot for (CachedRow row : importedKeyMetadataResultSet) { String fk_name = cleanNameFromDatabase(row.getString("FK_NAME"), database); if (snapshot.getDatabase().isCaseSensitive()) { - if (!fk_name.equals(example.getName())) { - continue; - } else if (!fk_name.equalsIgnoreCase(example.getName())) { + if (!fk_name.equalsIgnoreCase(example.getName())) { continue; } } @@ -217,7 +215,7 @@ private void setValidateOptionIfAvailable(Database database, ForeignKey foreignK } } - + @Override protected ForeignKeyConstraintType convertToForeignKeyConstraintType(Integer jdbcType, Database database) throws DatabaseException { if (jdbcType == null) { return ForeignKeyConstraintType.importedKeyNoAction; diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ResultSetCacheDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ResultSetCacheDatabricks.java index b502eb8f..442e9b25 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ResultSetCacheDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ResultSetCacheDatabricks.java @@ -11,7 +11,7 @@ public RowData(String catalog, String schema, Database database, String... param } public abstract static class SingleResultSetExtractor extends ResultSetCache.SingleResultSetExtractor { - public SingleResultSetExtractor(Database database) { + protected SingleResultSetExtractor(Database database) { super(database); } } diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/SequenceSnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/SequenceSnapshotGeneratorDatabricks.java deleted file mode 100644 index c3273a43..00000000 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/SequenceSnapshotGeneratorDatabricks.java +++ /dev/null @@ -1,55 +0,0 @@ -package liquibase.ext.databricks.snapshot.jvm; - -import liquibase.Scope; -import liquibase.database.Database; -import liquibase.exception.DatabaseException; -import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.snapshot.DatabaseSnapshot; -import liquibase.snapshot.SnapshotGenerator; -import liquibase.snapshot.jvm.SequenceSnapshotGenerator; -import liquibase.statement.SqlStatement; -import liquibase.statement.core.RawSqlStatement; -import liquibase.structure.DatabaseObject; -import liquibase.structure.core.Schema; - -public class SequenceSnapshotGeneratorDatabricks extends SequenceSnapshotGenerator { - - @Override - public int getPriority(Class objectType, Database database) { - if (database instanceof DatabricksDatabase) { - return super.getPriority(objectType, database) + PRIORITY_DATABASE; - } else { - return PRIORITY_NONE; - } - } - - @Override - public Class[] replaces() { - return new Class[]{SequenceSnapshotGenerator.class}; - } - - @Override - protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException { - Scope.getCurrentScope().getLog(this.getClass()).info("Sequences are not supported by Databricks"); - return null; - } - - - @Override - protected SqlStatement getSelectSequenceStatement(Schema schema, Database database) { - if (database instanceof DatabricksDatabase) { - // Databricks does not support sequences - - String databricksSequenceSql = "SELECT NULL AS SEQUENCE_NAME, NULL AS START_VALUE, NULL AS MIN_VALUE, NULL AS MAX_VALUE, NULL AS INCREMENT_BY, NULL AS WILL_CYCLE " + - "FROM " + schema.getCatalogName() + ".information_schema.columns " + - "WHERE " + - "table_catalog = '" + schema.getCatalogName() + "' " + - "AND table_schema = '" + schema.getName() +"' " + - "AND 1=0"; - - return new RawSqlStatement(databricksSequenceSql); - } - - return getSelectSequenceStatement(schema, database); - } -} diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/UniqueConstraintSnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/UniqueConstraintSnapshotGeneratorDatabricks.java index adbf5121..9e83ab25 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/UniqueConstraintSnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/UniqueConstraintSnapshotGeneratorDatabricks.java @@ -9,7 +9,7 @@ import liquibase.snapshot.DatabaseSnapshot; import liquibase.snapshot.SnapshotGenerator; import liquibase.snapshot.jvm.UniqueConstraintSnapshotGenerator; -import liquibase.statement.core.RawSqlStatement; +import liquibase.statement.core.RawParameterizedSqlStatement; import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; import java.sql.SQLException; @@ -61,5 +61,5 @@ protected List listConstraints(Table table, DatabaseSnapshot snapshot sql = sql + "AND CONSTRAINT_NAME='" + constraintName + "'"; } - return Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).queryForList(new RawSqlStatement(sql)); + return Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).queryForList(new RawParameterizedSqlStatement(sql)); }} diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java index c1b3dfd7..8e200eb4 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java @@ -3,7 +3,6 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.Scope; import liquibase.database.Database; -import liquibase.database.core.MySQLDatabase; import liquibase.datatype.DataTypeFactory; import liquibase.exception.DatabaseException; import liquibase.exception.ValidationErrors; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java index 79e0f840..114d98f6 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java @@ -8,9 +8,6 @@ import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.AddForeignKeyConstraintStatement; -import liquibase.structure.core.Column; -import liquibase.structure.core.ForeignKey; -import liquibase.structure.core.Table; import liquibase.sqlgenerator.core.AddForeignKeyConstraintGenerator; public class AddForeignKeyConstraintGeneratorDatabricks extends AddForeignKeyConstraintGenerator { diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java index a8ae4ae3..dd9b39de 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java @@ -1,7 +1,6 @@ package liquibase.ext.databricks.sqlgenerator; import liquibase.database.Database; -import liquibase.database.core.*; import liquibase.exception.ValidationErrors; import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.sql.Sql; @@ -29,20 +28,8 @@ public ValidationErrors validate(AddPrimaryKeyStatement addPrimaryKeyStatement, validationErrors.checkRequiredField("columnNames", addPrimaryKeyStatement.getColumnNames()); validationErrors.checkRequiredField("tableName", addPrimaryKeyStatement.getTableName()); - if (addPrimaryKeyStatement.isClustered() != null) { - if (database instanceof PostgresDatabase) { - if (addPrimaryKeyStatement.isClustered() && addPrimaryKeyStatement.getConstraintName() == null) { - validationErrors.addError("Postgresql requires constraintName on addPrimaryKey when clustered=true"); - } - } else if (database instanceof MSSQLDatabase || database instanceof MockDatabase) { - //clustered is fine - } else if (addPrimaryKeyStatement.isClustered()) { - validationErrors.addError("Cannot specify clustered=true on "+database.getShortName()); - } - } - - if (!((database instanceof OracleDatabase) || (database instanceof AbstractDb2Database))) { - validationErrors.checkDisallowedField("forIndexName", addPrimaryKeyStatement.getForIndexName(), database); + if (Boolean.TRUE.equals(addPrimaryKeyStatement.isClustered())) { + validationErrors.addError("Cannot specify clustered=true on " + database.getShortName()); } return validationErrors; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java index ae3b450a..ed10869a 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java @@ -102,8 +102,4 @@ public Sql[] generateSql(CreateIndexStatement statement, Database database, SqlG return new Sql[] {new UnparsedSql(buffer.toString(), getAffectedIndex(statement))}; } - @Override - protected Index getAffectedIndex(CreateIndexStatement statement) { - return new Index().setName(statement.getIndexName()).setRelation(new Table().setName(statement.getTableName()).setSchema(statement.getTableCatalogName(), statement.getTableSchemaName())); - } } \ 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 e820cddb..dec95811 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java @@ -13,7 +13,7 @@ import liquibase.structure.DatabaseObject; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; +import java.util.List; public class CreateTableGeneratorDatabricks extends CreateTableGenerator { @@ -63,8 +63,8 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG finalsql.append(" LOCATION '").append(thisStatement.getExtendedTableProperties().getTableLocation()).append("'"); } - ArrayList clusterCols = thisStatement.getClusterColumns(); - ArrayList partitionCols = thisStatement.getPartitionColumns(); + List clusterCols = thisStatement.getClusterColumns(); + List partitionCols = thisStatement.getPartitionColumns(); // If there are any cluster columns, add the clause diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java index 7f2c69dc..0712093e 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java @@ -9,6 +9,7 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.InsertOrUpdateStatement; import liquibase.sqlgenerator.core.InsertOrUpdateGenerator; + import java.util.Date; public class InsertOrUpdateGeneratorDatabricks extends InsertOrUpdateGenerator { @@ -19,81 +20,77 @@ public boolean supports(InsertOrUpdateStatement statement, Database database) { } @Override - public int getPriority() { - return PRIORITY_DATABASE; + protected String getInsertStatement(InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { + StringBuilder columns = new StringBuilder(); + StringBuilder values = new StringBuilder(); + + for (String columnKey : insertOrUpdateStatement.getColumnValues().keySet()) { + columns.append(","); + columns.append(columnKey); + values.append(","); + values.append(convertToString(insertOrUpdateStatement.getColumnValue(columnKey), database)); + } + columns.deleteCharAt(0); + values.deleteCharAt(0); + return "INSERT (" + columns + ") VALUES (" + values + ")"; } - @Override - protected String getInsertStatement(InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { - StringBuilder columns = new StringBuilder(); - StringBuilder values = new StringBuilder(); - - for (String columnKey : insertOrUpdateStatement.getColumnValues().keySet()) { - columns.append(","); - columns.append(columnKey); - values.append(","); - values.append(convertToString(insertOrUpdateStatement.getColumnValue(columnKey), database)); + protected String getUpdateStatement(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause, + SqlGeneratorChain sqlGeneratorChain) { + //We don't need 'whereClause' param here, for Snowflake it's only needed in getRecordCheck() method + StringBuilder sql = new StringBuilder("UPDATE SET "); + + for (String columnKey : insertOrUpdateStatement.getColumnValues().keySet()) { + + // Databricks does not support updating an identity column, so don't update if the column is part of the key you're merging on + if ((insertOrUpdateStatement.getAllowColumnUpdate(columnKey)) && (!whereClause.contains(columnKey))) { + sql.append("target.").append(columnKey).append(" = "); + sql.append(convertToString(insertOrUpdateStatement.getColumnValue(columnKey), database)); + sql.append(","); } - columns.deleteCharAt(0); - values.deleteCharAt(0); - return "INSERT (" + columns + ") VALUES (" + values + ")"; } - - @Override - protected String getUpdateStatement(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause, SqlGeneratorChain sqlGeneratorChain) { - //We don't need 'whereClause' param here, for Snowflake it's only needed in getRecordCheck() method - StringBuilder sql = new StringBuilder("UPDATE SET "); - - for (String columnKey : insertOrUpdateStatement.getColumnValues().keySet()) { - - // Databricks does not support updating an identity column, so dont update if the column is part of the key youre merging on - if ((insertOrUpdateStatement.getAllowColumnUpdate(columnKey)) & (!whereClause.contains(columnKey))) { - sql.append("target." + columnKey).append(" = "); - sql.append(convertToString(insertOrUpdateStatement.getColumnValue(columnKey), database)); - sql.append(","); - } - } - int lastComma = sql.lastIndexOf(","); - if (lastComma > -1) { - sql.deleteCharAt(lastComma); - } - - return sql.toString(); + int lastComma = sql.lastIndexOf(","); + if (lastComma > -1) { + sql.deleteCharAt(lastComma); } - @Override - protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { - return "MERGE INTO " + insertOrUpdateStatement.getTableName() + " AS target USING (SELECT 1) AS source ON target." + whereClause + " WHEN MATCHED THEN "; - } + return sql.toString(); + } - @Override - protected String getElse(Database database) { - return " WHEN NOT MATCHED THEN "; - } + @Override + protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { + return "MERGE INTO " + insertOrUpdateStatement.getTableName() + " AS target USING (SELECT 1) AS source ON target." + whereClause + " WHEN MATCHED " + + "THEN "; + } + + @Override + protected String getElse(Database database) { + return " WHEN NOT MATCHED THEN "; + } - // Copied from liquibase.sqlgenerator.core.InsertOrUpdateGeneratorHsql - private String convertToString(Object newValue, Database database) { - String sqlString; - if ((newValue == null) || "".equals(newValue.toString()) || "NULL".equalsIgnoreCase(newValue.toString())) { - sqlString = "NULL"; - } else if ((newValue instanceof String) && !looksLikeFunctionCall(((String) newValue), database)) { - sqlString = "'" + database.escapeStringForDatabase(newValue.toString()) + "'"; - } else if (newValue instanceof Date) { - sqlString = database.getDateLiteral(((Date) newValue)); - } else if (newValue instanceof Boolean) { - if (Boolean.TRUE.equals(newValue)) { - sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database); - } else { - sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database); - } + // Copied from liquibase.sqlgenerator.core.InsertOrUpdateGeneratorHsql + private String convertToString(Object newValue, Database database) { + String sqlString; + if ((newValue == null) || "".equals(newValue.toString()) || "NULL".equalsIgnoreCase(newValue.toString())) { + sqlString = "NULL"; + } else if ((newValue instanceof String) && !looksLikeFunctionCall(((String) newValue), database)) { + sqlString = "'" + database.escapeStringForDatabase(newValue.toString()) + "'"; + } else if (newValue instanceof Date) { + sqlString = database.getDateLiteral(((Date) newValue)); + } else if (newValue instanceof Boolean) { + if (Boolean.TRUE.equals(newValue)) { + sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database); } else { - sqlString = newValue.toString(); + sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database); } - return sqlString; + } else { + sqlString = newValue.toString(); } + return sqlString; + } - // Databricks orders its merge statement a bit differently (WHEN MATCHED must come first) and aliases are important + // Databricks orders its merge statement a bit differently (WHEN MATCHED must come first) and aliases are important @Override public Sql[] generateSql(InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { StringBuilder completeSql = new StringBuilder(); @@ -106,15 +103,12 @@ public Sql[] generateSql(InsertOrUpdateStatement insertOrUpdateStatement, Databa completeSql.append(updateStatement); // Add insert statement to MERGE if not ONLY an update statement - if (!insertOrUpdateStatement.getOnlyUpdate()) { + if (Boolean.FALSE.equals(insertOrUpdateStatement.getOnlyUpdate())) { // Run getElse to add the INSERT when not matched clause completeSql.append(getElse(database)); completeSql.append(getInsertStatement(insertOrUpdateStatement, database, sqlGeneratorChain)); - } - - if (!insertOrUpdateStatement.getOnlyUpdate()) { completeSql.append(getPostUpdateStatements(database)); } @@ -122,4 +116,4 @@ public Sql[] generateSql(InsertOrUpdateStatement insertOrUpdateStatement, Databa new UnparsedSql(completeSql.toString(), "", getAffectedTable(insertOrUpdateStatement)) }; } - } \ No newline at end of file +} \ 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 a0b2e655..0637fa1d 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java @@ -2,15 +2,11 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; -import liquibase.database.core.*; -import liquibase.exception.ValidationErrors; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.RenameTableStatement; -import liquibase.structure.core.Relation; import liquibase.structure.core.Table; -import liquibase.sqlgenerator.core.AbstractSqlGenerator; import liquibase.sqlgenerator.core.RenameTableGenerator; public class RenameTableGeneratorDatabricks extends RenameTableGenerator { diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java index fc7eac21..e2bfcbc2 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java @@ -2,13 +2,10 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; -import liquibase.database.core.*; -import liquibase.exception.ValidationErrors; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.RenameViewStatement; -import liquibase.structure.core.Relation; import liquibase.structure.core.View; import liquibase.sqlgenerator.core.RenameViewGenerator; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java index 3af7b9e6..a401a21b 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java @@ -9,8 +9,6 @@ import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.SetColumnRemarksStatement; -import liquibase.structure.core.Column; -import liquibase.structure.core.Table; import liquibase.sqlgenerator.core.SetColumnRemarksGenerator; import org.apache.commons.lang3.StringUtils; @@ -61,7 +59,4 @@ public Sql[] generateSql(SetColumnRemarksStatement statement, Database database, } - protected Column getAffectedColumn(SetColumnRemarksStatement statement) { - return new Column().setName(statement.getColumnName()).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/SetTableRemarksGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java index a7975159..dec89815 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java @@ -2,13 +2,10 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; -import liquibase.exception.ValidationErrors; import liquibase.sql.Sql; import liquibase.sql.UnparsedSql; import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.SetTableRemarksStatement; -import liquibase.structure.core.Relation; -import liquibase.structure.core.Table; import liquibase.sqlgenerator.core.SetTableRemarksGenerator; import org.apache.commons.lang3.StringUtils; @@ -25,13 +22,6 @@ public int getPriority() { } - @Override - public ValidationErrors validate(SetTableRemarksStatement setTableRemarksStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { - ValidationErrors validationErrors = new ValidationErrors(); - validationErrors.checkRequiredField("tableName", setTableRemarksStatement.getTableName()); - return validationErrors; - } - @Override public Sql[] generateSql(SetTableRemarksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; @@ -43,7 +33,4 @@ public Sql[] generateSql(SetTableRemarksStatement statement, Database database, return new Sql[] { new UnparsedSql(sql, getAffectedTable(statement)) }; } - protected Relation getAffectedTable(SetTableRemarksStatement statement) { - return new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName()); - } } \ No newline at end of file diff --git a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator index 9a020738..50b9d940 100644 --- a/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator +++ b/src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator @@ -1,5 +1,4 @@ liquibase.ext.databricks.snapshot.jvm.SchemaSnapshotGeneratorDatabricks -liquibase.ext.databricks.snapshot.jvm.SequenceSnapshotGeneratorDatabricks liquibase.ext.databricks.snapshot.jvm.ForeignKeySnapshotGeneratorDatabricks liquibase.ext.databricks.snapshot.jvm.UniqueConstraintSnapshotGeneratorDatabricks liquibase.ext.databricks.snapshot.jvm.IndexSnapshotGeneratorDatabricks