diff --git a/.github/workflows/lth.yml b/.github/workflows/lth.yml index 3daf83d5..8b37fb38 100644 --- a/.github/workflows/lth.yml +++ b/.github/workflows/lth.yml @@ -1,11 +1,16 @@ name: Liquibase Test Harness - on: + workflow_dispatch: pull_request: push: branches: - main +# static value to the workflow group to ensure only one run of the workflow can be in progress at a time. +concurrency: + group: liquibase-test-harness + cancel-in-progress: false + jobs: liquibase-test-harness: name: Liquibase Test Harness @@ -57,7 +62,7 @@ jobs: run: mvn -B -ntp -Dmaven.test.skip package - name: Run ${{ matrix.liquibase-support-level }} Liquibase Test Harness # Run the Liquibase test harness at each test level - continue-on-error: true # Continue to run the action even if the previous steps fail + if: always() # Run the action even if the previous steps fail run: mvn -B -ntp -DdbPassword=${{env.TF_VAR_DBX_TOKEN}} -DdbUrl='${{env.DATABRICKS_URL}}' -Dtest=liquibase.ext.databricks.${{ matrix.liquibase-support-level }}ExtensionHarnessTestSuite test # Run the Liquibase test harness at each test level - name: Test Reporter # Generate a test report using the Test Reporter action @@ -72,4 +77,16 @@ jobs: - name: Stop test database if: always() # Always destroy, even if the previous steps fail working-directory: src/test/terraform - run: terraform destroy -auto-approve + run: | + set -e + TERRAFORM_OUTPUT=$(terraform show -json) + if [ -z "$TERRAFORM_OUTPUT" ]; then + echo "Terraform output is empty. Skipping removal." + else + SCHEMA_EXISTS=$(echo $TERRAFORM_OUTPUT | jq -r '.values.root_module.resources[] | select(.address == "databricks_schema.test_harness") | .values.name') + if [ "$SCHEMA_EXISTS" == "liquibase_harness_test_ds" ]; then + terraform destroy -auto-approve + else + echo "Schema does not exist. Skipping removal." + fi + fi \ No newline at end of file diff --git a/README.md b/README.md index 1f508c09..67f488c3 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ If hive_metastore is used, this is not tested and may not provide all the below 21. [x] Change Data Test: apply insert 22. [x] Change Data Test: apply loadData 23. [x] Change Data Test: apply loadDataUpdate -24. [ ] Add/Drop Check Constraints - TO DO: Need to create snapshot generator but the change type works +24. [x] Add/Drop Check Constraints - supported but not returned in snapshot ### Advanced 1. [x] addColumn snapshot @@ -58,16 +58,17 @@ If hive_metastore is used, this is not tested and may not provide all the below 5. [x] createTable snapshot 6. [x] createView snapshot 7. [x] generateChangelog - -2. [x] addUniqueConstraint - not supported -3. [x] createIndex - Not Supported, use changeClusterColumns change type for datbricks to Map to CLUSTER BY ALTER TABLE statements for Delta Tables - +8. [x] addUniqueConstraint - not supported +9. [x] createIndex - Not Supported, use changeClusterColumns change type for datbricks to Map to CLUSTER BY ALTER TABLE statements for Delta Tables +10. [x] alterTableProperties +11. [x] alterCluster ### Databricks Specific: 1. [x] OPTIMIZE - optimizeTable - optimize with zorderCols options - SUPPORTED in Contributed Harness 2. [x] CLUSTER BY (DDL) - createClusteredTable - createTable with clusterColumns as additional option for liquid - SUPPORTED in Contributed Harness 3. [x] ANALYZE TABLE - analyzeTable - change type with compute stats column options - SUPPORTED in Contributed Harness 4. [x] VACUUM - vacuumTable - change type with retentionHours parameter (default is 168) - SUPPORTED in Contributed Harness -5. [ ] ALTER CLUSTER KEY - changeClusterColumns - change type that will be used until index change types are mapped with CLUSTER BY columns for snapshot purposes - TO DO +5. [x] ALTER CLUSTER KEY - alterCluster - change type that will be used until index change types are mapped with CLUSTER BY columns for snapshot purposes ## Remaining Required Change Types to Finish in Base/Contributed @@ -88,16 +89,13 @@ The remaining other change types are not relevant to Databricks and have been ma 2. MERGE 3. RESTORE VERSION AS OF 4. ANALYZE TABLE - Code Complete - Adding Tests - Cody Davis -5. SET TBL PROPERTIES - (Defaults are in createTable change type with min required table props to support Liquibase) -6. CLONE -7. BLOOM FILTERS - Maybe do not support, CLUSTER BY should be the primary indexing mechanism long term -8. OPTIMIZE / ZORDER - Code Complete - Adding Tests - Cody Davis -9. VACUUM - Code Complete - Adding Tests - Cody Davis -10. SYNC IDENTITY -11. VOLUMES -12. GRANT / REVOKE statements -13. CLUSTER BY - Similar to Indexes, important to support as a create table / alter table set of change types (params in createTable change), addClusterKey new change type to ALTER TABle - +5. CLONE +6. BLOOM FILTERS - Maybe do not support, CLUSTER BY should be the primary indexing mechanism long term +7. OPTIMIZE / ZORDER - Code Complete - Adding Tests - Cody Davis +8. VACUUM - Code Complete - Adding Tests - Cody Davis +9. SYNC IDENTITY +10. VOLUMES +11. GRANT / REVOKE statements ## How to use the Liquibase-Databricks Extension diff --git a/pom.xml b/pom.xml index 36bf482f..0583a201 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 1.8 1.8 - 4.28.0 + 4.29.1 liquibase ${sonar.organization}_${project.artifactId} ${project.name} @@ -96,7 +96,7 @@ com.databricks databricks-jdbc - 2.6.38 + 2.6.40 test @@ -122,9 +122,15 @@ com.databricks databricks-jdbc - 2.6.38 + 2.6.40 compile + + org.projectlombok + lombok + 1.18.34 + provided + @@ -170,7 +176,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.7.0 + 3.8.0 true false @@ -210,7 +216,7 @@ org.codehaus.gmavenplus gmavenplus-plugin - 2.1.0 + 3.0.2 @@ -240,7 +246,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.11.0.3922 + 4.0.0.4121 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 8e5f0af4..ff0033f6 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintChangeDatabricks.java @@ -4,13 +4,14 @@ import liquibase.database.Database; import liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintChangeDatabricks; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; + import java.text.MessageFormat; -import liquibase.ext.databricks.database.DatabricksDatabase; @DatabaseChange(name = "addCheckConstraint", description = "Adds check constraint to Delta Table", - priority = DatabricksDatabase.PRIORITY_DEFAULT + 200, + priority = PrioritizedService.PRIORITY_DATABASE, appliesTo = {"column"} ) public class AddCheckConstraintChangeDatabricks extends AbstractChange { @@ -23,11 +24,17 @@ public class AddCheckConstraintChangeDatabricks extends AbstractChange { private String constraintBody; + + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } + public String getCatalogName() { return catalogName; } - public void setCatalogName (String catalogName) { + public void setCatalogName(String catalogName) { this.catalogName = catalogName; } @@ -35,7 +42,7 @@ public String getTableName() { return tableName; } - public void setTableName (String tableName) { + public void setTableName(String tableName) { this.tableName = tableName; } @@ -43,15 +50,12 @@ public String getSchemaName() { return schemaName; } - public void setSchemaName (String schemaName) { + public void setSchemaName(String schemaName) { this.schemaName = schemaName; } - // Name of Delta Table Constraint - @DatabaseChangeProperty( - description = "Name of the check constraint" - ) + @DatabaseChangeProperty(description = "Name of the check constraint") public String getConstraintName() { return this.constraintName; } @@ -60,9 +64,7 @@ public void setConstraintName(String name) { this.constraintName = name; } - - // The is the SQL expression involving the contraint - + // This is the SQL expression involving the constraint @DatabaseChangeProperty( serializationType = SerializationType.DIRECT_VALUE ) @@ -76,7 +78,8 @@ public void setConstraintBody(String body) { @Override public String getConfirmationMessage() { - return MessageFormat.format("{0}.{1}.{2} successfully Added check constraint {3}.", getCatalogName(), getSchemaName(), getTableName(), getConstraintName()); + return MessageFormat.format("{0}.{1}.{2} successfully Added check constraint {3}.", getCatalogName(), getSchemaName(), getTableName(), + getConstraintName()); } protected Change[] createInverses() { @@ -100,6 +103,6 @@ public SqlStatement[] generateStatements(Database database) { statement.setConstraintName(getConstraintName()); statement.setConstraintBody(getConstraintBody()); - return new SqlStatement[] {statement}; + return new SqlStatement[]{statement}; } } 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 f635feca..8d39489d 100644 --- a/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addCheckConstraint/AddCheckConstraintStatementDatabricks.java @@ -8,8 +8,6 @@ public class AddCheckConstraintStatementDatabricks extends AbstractSqlStatement private String tableName; private String constraintName; private String constraintBody; - private boolean validate = true; - private boolean disabled; public String getCatalogName() { diff --git a/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java index c4412667..ae55635d 100644 --- a/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addForeignKeyConstraint/AddForeignKeyConstraintChangeDatabricks.java @@ -1,11 +1,11 @@ package liquibase.ext.databricks.change.addForeignKeyConstraint; -import liquibase.ext.databricks.database.DatabricksDatabase; - 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; @@ -23,8 +23,9 @@ */ @DatabaseChange(name = "addForeignKeyConstraint", description = "Adds a foreign key constraint to an existing column", - priority = DatabricksDatabase.PRIORITY_DATABASE, + 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; @@ -46,6 +47,10 @@ public class AddForeignKeyConstraintChangeDatabricks extends AddForeignKeyConstr private String onUpdate; private String onDelete; + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } @Override protected String[] createSupportedDatabasesMetaData( 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 d65f7ca8..b9ba8f03 100644 --- a/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/addLookupTable/AddLookupTableChangeDatabricks.java @@ -6,37 +6,27 @@ import liquibase.change.core.*; import liquibase.ext.databricks.database.DatabricksDatabase; -import liquibase.ext.databricks.change.createTable.CreateTableStatementDatabricks; -import liquibase.ext.databricks.change.createTable.CreateTableChangeDatabricks; import liquibase.Scope; import liquibase.change.*; import liquibase.database.Database; -import liquibase.database.core.DB2Database; import liquibase.database.core.Db2zDatabase; -import liquibase.database.core.HsqlDatabase; -import liquibase.database.core.InformixDatabase; -import liquibase.database.core.MSSQLDatabase; import liquibase.database.core.OracleDatabase; -import liquibase.database.core.SybaseASADatabase; -import liquibase.datatype.DataTypeFactory; import liquibase.exception.ValidationErrors; +import liquibase.servicelocator.PrioritizedService; import liquibase.snapshot.SnapshotGeneratorFactory; -import liquibase.statement.NotNullConstraint; import liquibase.statement.SqlStatement; -import liquibase.statement.core.CreateTableStatement; import liquibase.statement.core.RawSqlStatement; -import liquibase.statement.core.ReorganizeTableStatement; 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. */ -@DatabaseChange(name = "addLookupTable", priority = DatabricksDatabase.PRIORITY_DATABASE + 500, appliesTo = "column", +//TODO this class need refactoring as it copies parent class instead of properly inheriting it. +@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 { diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java new file mode 100644 index 00000000..65f64084 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterChangeDatabricks.java @@ -0,0 +1,107 @@ +package liquibase.ext.databricks.change.alterCluster; + +import liquibase.change.AbstractChange; +import liquibase.change.DatabaseChange; +import liquibase.change.DatabaseChangeProperty; +import liquibase.database.Database; +import liquibase.exception.ValidationErrors; +import liquibase.servicelocator.PrioritizedService; +import liquibase.statement.SqlStatement; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +@DatabaseChange(name = "alterCluster", description = "Alter Cluster", priority = PrioritizedService.PRIORITY_DATABASE +500) +public class AlterClusterChangeDatabricks extends AbstractChange { + + private String tableName; + private String catalogName; + private String schemaName; + private List columns; + private List clusterBy; + + @Override + public ValidationErrors validate(Database database) { + ValidationErrors validationErrors = new ValidationErrors(); + validationErrors.addAll(super.validate(database)); + + if (columns == null && clusterBy == null) { + validationErrors.addError("Alter Cluster change require list of columns or element 'ClusterBy', please add at least one option."); + } + return validationErrors; + } + + public AlterClusterChangeDatabricks() { + super(); + columns = new ArrayList<>(); + clusterBy = new ArrayList<>(); + } + + @Override + public String getConfirmationMessage() { + return MessageFormat.format("{0}.{1}.{2} successfully altered.", getCatalogName(), getSchemaName(), getTableName()); + } + + @Override + public SqlStatement[] generateStatements(Database database) { + AlterClusterDatabricksStatement statement = new AlterClusterDatabricksStatement(tableName, catalogName, schemaName); + if (getColumns() != null && !getColumns().isEmpty()) { + statement.setColumns(getColumns()); + } else if (getClusterBy() != null && !getClusterBy().isEmpty()) { + statement.setClusterBy(getClusterBy()); + } + return new SqlStatement[]{statement}; + } + + @DatabaseChangeProperty + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + @DatabaseChangeProperty + public List getColumns() { + if (columns == null) { + return new ArrayList<>(); + } + 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) { + return new ArrayList<>(); + } + return clusterBy; + } + + public void setClusterBy(List clusterBy) { + this.clusterBy = clusterBy; + } +} diff --git a/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java new file mode 100644 index 00000000..3d644af4 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/AlterClusterDatabricksStatement.java @@ -0,0 +1,60 @@ +package liquibase.ext.databricks.change.alterCluster; + +import liquibase.statement.AbstractSqlStatement; + +import java.util.List; + +public class AlterClusterDatabricksStatement extends AbstractSqlStatement { + + private String tableName; + private String catalogName; + private String schemaName; + private List columns; + private List clusterBy; + + public AlterClusterDatabricksStatement(String tableName, String catalogName, String schemaName) { + this.tableName = tableName; + 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 new file mode 100644 index 00000000..ecf53504 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/ColumnConfig.java @@ -0,0 +1,26 @@ +package liquibase.ext.databricks.change.alterCluster; + +import liquibase.serializer.AbstractLiquibaseSerializable; + +public class ColumnConfig extends AbstractLiquibaseSerializable { + + private String name; + + @Override + public String getSerializedObjectName() { + return "column"; + } + + @Override + 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 new file mode 100644 index 00000000..448a4db6 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterCluster/NoneConfig.java @@ -0,0 +1,26 @@ +package liquibase.ext.databricks.change.alterCluster; + +import liquibase.serializer.AbstractLiquibaseSerializable; + +public class NoneConfig extends AbstractLiquibaseSerializable { + + private String none; + + @Override + public String getSerializedObjectName() { + return "clusterBy"; + } + + @Override + 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 new file mode 100644 index 00000000..15505575 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesChangeDatabricks.java @@ -0,0 +1,89 @@ +package liquibase.ext.databricks.change.alterTableProperties; + +import liquibase.change.AbstractChange; +import liquibase.change.DatabaseChange; +import liquibase.change.DatabaseChangeProperty; +import liquibase.database.Database; +import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; +import liquibase.statement.SqlStatement; +import lombok.Setter; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import static liquibase.statement.SqlStatement.EMPTY_SQL_STATEMENT; + +@Setter +@DatabaseChange(name = "alterTableProperties", description = "Alter Table Properties", priority = PrioritizedService.PRIORITY_DATABASE + 500) +public class AlterTablePropertiesChangeDatabricks extends AbstractChange { + + private String tableName; + private String catalogName; + private String schemaName; + private SetExtendedTableProperties setExtendedTableProperties; + private UnsetExtendedTableProperties unsetExtendedTableProperties; + + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } + + @Override + public ValidationErrors validate(Database database) { + ValidationErrors validationErrors = new ValidationErrors(); + validationErrors.addAll(super.validate(database)); + + if (setExtendedTableProperties == null && unsetExtendedTableProperties == null) { + validationErrors.addError("Alter Table Properties change require 'setExtendedTableProperties' or 'unsetExtendedTableProperties' element, please add at least one option."); + } + return validationErrors; + } + + @Override + public String getConfirmationMessage() { + return MessageFormat.format("{0}.{1}.{2} successfully altered.", getCatalogName(), getSchemaName(), getTableName()); + } + + @Override + public SqlStatement[] generateStatements(Database database) { + AlterTablePropertiesStatementDatabricks statement = new AlterTablePropertiesStatementDatabricks(getCatalogName(), getSchemaName(), getTableName()); + + if (setExtendedTableProperties != null) { + statement.setSetExtendedTableProperties(setExtendedTableProperties); + } else if (unsetExtendedTableProperties != null) { + statement.setUnsetExtendedTableProperties(unsetExtendedTableProperties); + } + + List statements = new ArrayList<>(); + statements.add(statement); + return statements.toArray(EMPTY_SQL_STATEMENT); + } + + @DatabaseChangeProperty + public String getCatalogName() { + return catalogName; + } + + @DatabaseChangeProperty + public String getSchemaName() { + return schemaName; + } + + @DatabaseChangeProperty + public String getTableName() { + return tableName; + } + + @DatabaseChangeProperty + public SetExtendedTableProperties getSetExtendedTableProperties() { + return setExtendedTableProperties; + } + + @DatabaseChangeProperty + public UnsetExtendedTableProperties getUnsetExtendedTableProperties() { + return unsetExtendedTableProperties; + } +} diff --git a/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesStatementDatabricks.java b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesStatementDatabricks.java new file mode 100644 index 00000000..b7170eed --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/AlterTablePropertiesStatementDatabricks.java @@ -0,0 +1,23 @@ +package liquibase.ext.databricks.change.alterTableProperties; + +import liquibase.statement.AbstractSqlStatement; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class AlterTablePropertiesStatementDatabricks extends AbstractSqlStatement { + + private String tableName; + private String catalogName; + private String schemaName; + private SetExtendedTableProperties setExtendedTableProperties; + private UnsetExtendedTableProperties unsetExtendedTableProperties; + + public AlterTablePropertiesStatementDatabricks(String catalogName, String schemaName, String tableName) { + this.tableName = tableName; + this.catalogName = catalogName; + this.schemaName = schemaName; + } + +} diff --git a/src/main/java/liquibase/ext/databricks/change/alterTableProperties/SetExtendedTableProperties.java b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/SetExtendedTableProperties.java new file mode 100644 index 00000000..d7571640 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/SetExtendedTableProperties.java @@ -0,0 +1,21 @@ +package liquibase.ext.databricks.change.alterTableProperties; + +import liquibase.serializer.AbstractLiquibaseSerializable; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SetExtendedTableProperties extends AbstractLiquibaseSerializable { + private String tblProperties; + + @Override + public String getSerializedObjectName() { + return "setExtendedTableProperties"; + } + + @Override + public String getSerializedObjectNamespace() { + return "http://www.liquibase.org/xml/ns/databricks"; + } +} diff --git a/src/main/java/liquibase/ext/databricks/change/alterTableProperties/UnsetExtendedTableProperties.java b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/UnsetExtendedTableProperties.java new file mode 100644 index 00000000..ef1bff71 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/alterTableProperties/UnsetExtendedTableProperties.java @@ -0,0 +1,21 @@ +package liquibase.ext.databricks.change.alterTableProperties; + +import liquibase.serializer.AbstractLiquibaseSerializable; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class UnsetExtendedTableProperties extends AbstractLiquibaseSerializable{ + private String tblProperties; + + @Override + public String getSerializedObjectName() { + return "unsetExtendedTableProperties"; + } + + @Override + public String getSerializedObjectNamespace() { + return "http://www.liquibase.org/xml/ns/databricks"; + } +} 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 95ff2753..f72b3082 100644 --- a/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/analyzeTable/AnalyzeTableChange.java @@ -3,17 +3,17 @@ 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; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import java.util.Collections; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Map; -@DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = ChangeMetaData.PRIORITY_DEFAULT) +@DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = PrioritizedService.PRIORITY_DATABASE) public class AnalyzeTableChange extends AbstractChange { private String catalogName; 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 a5ec4de7..a6d087af 100644 --- a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java @@ -5,11 +5,12 @@ import liquibase.change.core.CreateTableChange; import liquibase.database.Database; import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.servicelocator.PrioritizedService; import liquibase.statement.core.CreateTableStatement; -@DatabaseChange(name = "createTable", description = "Create Table", priority = PrioritizedService.PRIORITY_DATABASE +500) +@DatabaseChange(name = "createTable", description = "Create Table", priority = PrioritizedService.PRIORITY_DATABASE) public class CreateTableChangeDatabricks extends CreateTableChange { private String tableFormat; @@ -18,6 +19,10 @@ public class CreateTableChangeDatabricks extends CreateTableChange { private String partitionColumns; private ExtendedTableProperties extendedTableProperties; + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } @Override public ValidationErrors validate(Database database) { 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 56e498e2..88248af6 100644 --- a/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/dropCheckConstraint/DropCheckConstraintChangeDatabricks.java @@ -6,11 +6,12 @@ import liquibase.change.DatabaseChangeProperty; import liquibase.database.Database; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import java.text.MessageFormat; -@DatabaseChange(name = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = DatabricksDatabase.PRIORITY_DEFAULT + 200) +@DatabaseChange(name = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = PrioritizedService.PRIORITY_DATABASE) public class DropCheckConstraintChangeDatabricks extends AbstractChange { private String catalogName; @@ -43,6 +44,10 @@ public void setSchemaName (String schemaName) { this.schemaName = schemaName; } + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } // Name of Delta Table Constraint @DatabaseChangeProperty( 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 8ce3128d..54d9681f 100644 --- a/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/optimizeTable/OptimizeTableChange.java @@ -5,13 +5,15 @@ import liquibase.change.ChangeMetaData; import liquibase.change.DatabaseChange; import liquibase.database.Database; +import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import liquibase.change.Change; import java.text.MessageFormat; import java.util.ArrayList; -@DatabaseChange(name = "optimizeTable", description = "Optimize and ZOrder Table", priority = ChangeMetaData.PRIORITY_DEFAULT) +@DatabaseChange(name = "optimizeTable", description = "Optimize and ZOrder Table", priority = PrioritizedService.PRIORITY_DATABASE) public class OptimizeTableChange extends AbstractChange { private String catalogName; @@ -56,6 +58,11 @@ public String getConfirmationMessage() { return MessageFormat.format("{0}.{1}.{2} successfully optimized.", getCatalogName(), getSchemaName(), getTableName()); } + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } + @Override protected Change[] createInverses() { // No Op for Databricks optimize statement. there is no rolling this back. 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 976e705a..65177f3a 100644 --- a/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java +++ b/src/main/java/liquibase/ext/databricks/change/vacuumTable/VacuumTableChange.java @@ -6,11 +6,13 @@ import liquibase.change.ChangeMetaData; import liquibase.change.DatabaseChange; import liquibase.database.Database; +import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; import liquibase.statement.SqlStatement; import java.text.MessageFormat; -@DatabaseChange(name = "vacuumTable", description = "Vacuum Old Files from Table", priority = ChangeMetaData.PRIORITY_DEFAULT + 200) +@DatabaseChange(name = "vacuumTable", description = "Vacuum Old Files from Table", priority = PrioritizedService.PRIORITY_DATABASE) public class VacuumTableChange extends AbstractChange { private String catalogName; @@ -55,6 +57,11 @@ public String getConfirmationMessage() { return MessageFormat.format("{0}.{1}.{2} successfully vacuumed.", getCatalogName(), getSchemaName(), getTableName()); } + @Override + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; + } + @Override protected Change[] createInverses() { // No Op for Databricks optimize statement. there is no rolling this back. diff --git a/src/main/java/liquibase/ext/databricks/database/CheckConstraintDatabricks.java b/src/main/java/liquibase/ext/databricks/database/CheckConstraintDatabricks.java deleted file mode 100644 index 00a01733..00000000 --- a/src/main/java/liquibase/ext/databricks/database/CheckConstraintDatabricks.java +++ /dev/null @@ -1,78 +0,0 @@ -package liquibase.ext.databricks.database; - -import liquibase.license.LicenseServiceUtils; -import liquibase.structure.AbstractDatabaseObject; -import liquibase.structure.DatabaseObject; -import liquibase.structure.core.Schema; -import liquibase.structure.core.Table; -import liquibase.util.StringUtil; - - -public class CheckConstraintDatabricks extends AbstractDatabaseObject { - public CheckConstraintDatabricks() { - } - - public DatabaseObject[] getContainingObjects() { - return null; - } - - public boolean snapshotByDefault() { - return LicenseServiceUtils.isProLicenseValid(); - } - - public String getName() { - return (String)this.getAttribute("name", String.class); - } - - public CheckConstraintDatabricks setName(String var1) { - this.setAttribute("name", var1); - return this; - } - - public Schema getSchema() { - return this.getTable() == null ? null : this.getTable().getSchema(); - } - - public Table getTable() { - return (Table)this.getAttribute("table", Table.class); - } - - public CheckConstraintDatabricks setTable(Table var1) { - this.setAttribute("table", var1); - return this; - } - - public String getBody() { - return (String)this.getAttribute("body", String.class); - } - - public CheckConstraintDatabricks setBody(String var1) { - this.setAttribute("body", var1); - return this; - } - - public String toString() { - Table var1; - return (var1 = this.getTable()) == null ? this.getName() : this.getName() + " on " + var1.getName(); - } - - public int compareTo(Object var1) { - return this.equals(var1) ? 0 : super.compareTo(var1); - } - - public boolean equals(Object var1) { - if (this == var1) { - return true; - } else if (var1 != null && this.getClass() == var1.getClass()) { - CheckConstraintDatabricks var2 = (CheckConstraintDatabricks)var1; - return this.getSchema() != null && var2.getSchema() != null ? this.getSchema().toString().equalsIgnoreCase(var2.getSchema().toString()) : this.getName().equalsIgnoreCase(var2.getName()); - } else { - return false; - } - } - - public int hashCode() { - return StringUtil.trimToEmpty(this.getName()).toLowerCase().hashCode(); - } -} - diff --git a/src/main/java/liquibase/ext/databricks/database/DatabricksConnection.java b/src/main/java/liquibase/ext/databricks/database/DatabricksConnection.java index df6cba36..4a2c84ef 100644 --- a/src/main/java/liquibase/ext/databricks/database/DatabricksConnection.java +++ b/src/main/java/liquibase/ext/databricks/database/DatabricksConnection.java @@ -86,7 +86,7 @@ public boolean supports(String url) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override diff --git a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java index 18c3a469..ea58755d 100644 --- a/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java +++ b/src/main/java/liquibase/ext/databricks/database/DatabricksDatabase.java @@ -18,8 +18,6 @@ public class DatabricksDatabase extends AbstractJdbcDatabase { - - public static final int DATABRICKS_PRIORITY_DATABASE = 1515; // define env variables for database public static final String PRODUCT_NAME = "databricks"; // Set default catalog - must be unity Catalog Enabled @@ -30,7 +28,7 @@ public class DatabricksDatabase extends AbstractJdbcDatabase { private Set systemTablesAndViews = new HashSet<>(); //Define data type names enabled for auto-increment columns - currently only BIGINT - public static final List VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMES = Collections.unmodifiableList(Arrays.asList("BIGINT")); + public static final List VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMES = Collections.singletonList("BIGINT"); public DatabricksDatabase() { super.setCurrentDateTimeFunction("current_timestamp()"); @@ -92,7 +90,7 @@ public Integer getDefaultPort() { @Override public int getPriority() { - return DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override @@ -133,6 +131,11 @@ public boolean supportsTablespaces() { @Override public boolean supportsSequences() { return false; } + @Override + public boolean supportsDatabaseChangeLogHistory() { + return true; + } + @Override public String getAutoIncrementClause(final BigInteger startWith, final BigInteger incrementBy, final String generationType, final Boolean defaultOnNull) { if (!this.supportsAutoIncrement()) { diff --git a/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java index 90791681..f2bfe059 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java @@ -6,8 +6,9 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; -@DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE) +@DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class ArrayIntegerDataTypeDatabricks extends LiquibaseDataType { @@ -29,12 +30,6 @@ public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.STRING; diff --git a/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java index 2ce72df8..1a153e60 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java @@ -5,10 +5,10 @@ import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; -import liquibase.datatype.core.BigIntType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; -@DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE) +@DataTypeInfo(name = "array", minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class ArrayStringDataTypeDatabricks extends LiquibaseDataType { @@ -29,12 +29,6 @@ public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.STRING; diff --git a/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java index 2e69dc32..57dd17a0 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BigintDatatypeDatabricks.java @@ -7,10 +7,11 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; - -@DataTypeInfo(name = "bigint", aliases = {"java.sql.Types.BIGINT", "java.math.BigInteger", "java.lang.Long", "integer8", "bigserial", "serial8", "int8"}, minParameters = 0, maxParameters = 0, priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE) +@DataTypeInfo(name = "bigint", aliases = {"java.sql.Types.BIGINT", "java.math.BigInteger", "java.lang.Long", "integer8", "bigserial", "serial8", "int8"}, + minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class BigintDatatypeDatabricks extends BigIntType { private boolean autoIncrement; @@ -38,12 +39,6 @@ public boolean supports(Database database) { return database instanceof DatabricksDatabase; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; diff --git a/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java index 589316ff..25080e88 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BinaryDataTypeDatabricks.java @@ -1,14 +1,15 @@ 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.BlobType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; - +@DataTypeInfo(name = "binary", aliases = {"longblob", "java.sql.Types.BLOB", + "java.sql.Types.BINARY", "tinyblob", "mediumblob"}, minParameters = 0, maxParameters = 0 + , priority = PrioritizedService.PRIORITY_DATABASE) public class BinaryDataTypeDatabricks extends BlobType { @@ -22,12 +23,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { return super.toDatabaseDataType(database); } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - @Override public boolean supports(Database database) { return database instanceof DatabricksDatabase; diff --git a/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java index e912ac6c..768fe5ce 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/BooleanDatatypeDatabricks.java @@ -12,7 +12,8 @@ name = "boolean", minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + aliases = {"java.sql.Types.BOOLEAN", "java.lang.Boolean", "bit", "bool"}, + priority = PrioritizedService.PRIORITY_DATABASE ) public class BooleanDatatypeDatabricks extends LiquibaseDataType { @@ -39,11 +40,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.BOOLEAN; } diff --git a/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java index d59b14aa..478f9cfe 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/DatetimeDatatypeDatabricks.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "timestamp", aliases = {"java.sql.Types.DATETIME", "datetime"}, minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class DatetimeDatatypeDatabricks extends LiquibaseDataType { @@ -32,11 +33,6 @@ public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.DATE; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - @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 202071d6..8b944812 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/DoubleDatatypeDatabricks.java @@ -12,7 +12,8 @@ name = "double", minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + aliases = {"java.sql.Types.DOUBLE", "java.lang.Double"}, + priority = PrioritizedService.PRIORITY_DATABASE ) public class DoubleDatatypeDatabricks extends LiquibaseDataType { @@ -39,10 +40,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; } diff --git a/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java index e3c232ba..41c188bb 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/FloatDatatypeDatabricks.java @@ -13,7 +13,8 @@ name = "float", minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + aliases = {"java.sql.Types.FLOAT", "java.lang.Float"}, + priority = PrioritizedService.PRIORITY_DATABASE ) public class FloatDatatypeDatabricks extends LiquibaseDataType { public FloatDatatypeDatabricks() { @@ -39,10 +40,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; } diff --git a/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java index 113b0b08..bdf234f6 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/IntegerDatatypeDatabricks.java @@ -6,13 +6,15 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "int", minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + aliases = {"integer", "java.sql.Types.INTEGER", "java.lang.Integer"}, + priority = PrioritizedService.PRIORITY_DATABASE ) public class IntegerDatatypeDatabricks extends LiquibaseDataType { public IntegerDatatypeDatabricks() { @@ -37,6 +39,7 @@ public DatabaseDataType toDatabaseDataType(Database database) { } + @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; } diff --git a/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java index 6a833c6d..4c5a98f3 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/SmallintDatatypeDatabricks.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "smallint", aliases = {"java.sql.Types.SMALLINT", "short"}, minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class SmallintDatatypeDatabricks extends LiquibaseDataType { @@ -32,11 +33,6 @@ public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - @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 8001ebd6..21c969f5 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/StringDatatypeDatabricks.java @@ -4,23 +4,26 @@ import liquibase.database.Database; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; -import liquibase.datatype.LiquibaseDataType; +import liquibase.datatype.core.VarcharType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "string", minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE, + aliases = {"clob", "java.lang.String" } ) -public class StringDatatypeDatabricks extends LiquibaseDataType { +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) { @@ -36,11 +39,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.STRING; } diff --git a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java index 93b4114b..072c5df8 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/TimestampDatatypeDatabricks.java @@ -3,32 +3,40 @@ import liquibase.datatype.core.TimestampType; import liquibase.Scope; import liquibase.change.core.LoadDataChange; + import java.util.Locale; + import liquibase.GlobalConfiguration; import liquibase.database.Database; import liquibase.database.core.*; import liquibase.datatype.DataTypeInfo; import liquibase.datatype.DatabaseDataType; import liquibase.exception.DatabaseIncapableOfOperation; -import liquibase.util.StringUtil; +import liquibase.servicelocator.PrioritizedService; import liquibase.util.grammar.ParseException; import liquibase.ext.databricks.database.DatabricksDatabase; +import org.apache.commons.lang3.StringUtils; + /** * Data type support for TIMESTAMP data types in various DBMS. All DBMS are at least expected to support the * year, month, day, hour, minute and second parts. Optionally, fractional seconds and time zone information can be * specified as well. */ -@DataTypeInfo(name = "timestamp", aliases = {"java.sql.Types.TIMESTAMP", "java.sql.Types.TIMESTAMP_WITH_TIMEZONE", "java.sql.Timestamp", "timestamptz"}, minParameters = 0, maxParameters = 0, priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE) + +//TODO refactor to simplify this class +@DataTypeInfo(name = "timestamp", aliases = {"java.sql.Types.TIMESTAMP", "java.sql.Types.TIMESTAMP_WITH_TIMEZONE", "java.sql.Timestamp", "timestamptz"}, + minParameters = 0, maxParameters = 0, priority = PrioritizedService.PRIORITY_DATABASE) public class TimestampDatatypeDatabricks extends TimestampType { /** * Returns a DBMS-specific String representation of this TimestampType for use in SQL statements. + * * @param database the database for which the String must be generated * @return a String with the DBMS-specific type specification */ @Override public DatabaseDataType toDatabaseDataType(Database database) { - String originalDefinition = StringUtil.trimToEmpty(getRawDefinition()); + String originalDefinition = StringUtils.trimToEmpty(getRawDefinition()); // If a fractional precision is given, check is the DBMS supports the length if (getParameters().length > 0) { Integer desiredLength = null; @@ -58,41 +66,6 @@ public DatabaseDataType toDatabaseDataType(Database database) { } } - if (database instanceof MySQLDatabase) { - if (originalDefinition.contains(" ") || originalDefinition.contains("(")) { - return new DatabaseDataType(getRawDefinition()); - } - return super.toDatabaseDataType(database); - } - if (database instanceof MSSQLDatabase) { - if (Boolean.TRUE.equals(!GlobalConfiguration.CONVERT_DATA_TYPES.getCurrentValue()) - && originalDefinition.toLowerCase(Locale.US).startsWith("timestamp")) { - return new DatabaseDataType(database.escapeDataTypeName("timestamp")); - } - Object[] parameters = getParameters(); - if (parameters.length >= 1) { - final int paramValue = Integer.parseInt(parameters[0].toString()); - // If the scale for datetime2 is the database default anyway, omit it. - // If the scale is 8, omit it since it's not a valid value for datetime2 - if (paramValue > 7 || paramValue == (database.getDefaultScaleForNativeDataType("datetime2"))) { - parameters = new Object[0]; - - } - - } - return new DatabaseDataType(database.escapeDataTypeName("datetime2"), parameters); - } - if (database instanceof SybaseDatabase) { - return new DatabaseDataType(database.escapeDataTypeName("datetime")); - } - if (database instanceof AbstractDb2Database) { - Object[] parameters = getParameters(); - if ((parameters != null) && (parameters.length > 1)) { - parameters = new Object[] {parameters[1]}; - } - return new DatabaseDataType(database.escapeDataTypeName("timestamp"), parameters); - } - /* * From here on, we assume that we have a SQL standard compliant database that supports the * TIMESTAMP[(p)] [WITH TIME ZONE|WITHOUT TIME ZONE] syntax. p is the number of fractional digits, @@ -121,7 +94,7 @@ public DatabaseDataType toDatabaseDataType(Database database) { fractionalDigits = maxFractionalDigits; } // Do not return parameter p for Databricks - type = new DatabaseDataType("TIMESTAMP"); + type = new DatabaseDataType("TIMESTAMP"); } else { type = new DatabaseDataType("TIMESTAMP"); } @@ -149,7 +122,7 @@ public DatabaseDataType toDatabaseDataType(Database database) { || database instanceof OracleDatabase) || database instanceof H2Database || database instanceof HsqlDatabase - || database instanceof SybaseASADatabase){ + || database instanceof SybaseASADatabase) { String additionalInformation = this.getAdditionalInformation(); if (additionalInformation != null) { @@ -183,11 +156,10 @@ public DatabaseDataType toDatabaseDataType(Database database) { } @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + public boolean supports(Database database) { + return database instanceof DatabricksDatabase; } - @Override public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.DATE; diff --git a/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java b/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java index 13ed54c3..96e9b551 100644 --- a/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/datatype/TinyintDatatypeDatabricks.java @@ -6,13 +6,14 @@ import liquibase.datatype.DatabaseDataType; import liquibase.datatype.LiquibaseDataType; import liquibase.ext.databricks.database.DatabricksDatabase; +import liquibase.servicelocator.PrioritizedService; @DataTypeInfo( name = "tinyint", aliases = {"java.sql.Types.TINYINT", "byte"}, minParameters = 0, maxParameters = 0, - priority = DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE + priority = PrioritizedService.PRIORITY_DATABASE ) public class TinyintDatatypeDatabricks extends LiquibaseDataType { @@ -32,12 +33,6 @@ public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() { return LoadDataChange.LOAD_DATA_TYPE.NUMERIC; } - @Override - public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; - } - - @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 index dd06729f..a185e27a 100644 --- a/src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java +++ b/src/main/java/liquibase/ext/databricks/executor/DatabricksExecutor.java @@ -5,16 +5,16 @@ 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; -import static liquibase.ext.databricks.database.DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; public class DatabricksExecutor extends JdbcExecutor { @Override public int getPriority() { - return DATABRICKS_PRIORITY_DATABASE; + return PrioritizedService.PRIORITY_DATABASE; } @Override 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 87a65834..1ff5619f 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/IndexSnapshotGeneratorDatabricks.java @@ -20,8 +20,8 @@ public class IndexSnapshotGeneratorDatabricks extends IndexSnapshotGenerator { @Override public int getPriority(Class objectType, Database database) { - if (super.getPriority(objectType, database) > 0 && database instanceof DatabricksDatabase) { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + if (database instanceof DatabricksDatabase) { + return super.getPriority(objectType, database) + PRIORITY_DATABASE; } else { return PRIORITY_NONE; } diff --git a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ViewSnapshotGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ViewSnapshotGeneratorDatabricks.java index 05301ab9..376ef85f 100644 --- a/src/main/java/liquibase/ext/databricks/snapshot/jvm/ViewSnapshotGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/snapshot/jvm/ViewSnapshotGeneratorDatabricks.java @@ -14,13 +14,13 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.Schema; import liquibase.structure.core.View; -import liquibase.util.StringUtil; import java.sql.ResultSet; import java.util.List; import java.util.Map; import liquibase.ext.databricks.database.DatabricksDatabase; +import org.apache.commons.lang3.StringUtils; public class ViewSnapshotGeneratorDatabricks extends ViewSnapshotGenerator { @@ -99,7 +99,7 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot definition = definition.substring(0, length - 1); } - definition = StringUtil.trimToNull(definition); + definition = StringUtils.trimToNull(definition); if (definition == null) { definition = "[CANNOT READ VIEW DEFINITION]"; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddAutoIncrementGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddAutoIncrementGeneratorDatabricks.java index 918740fa..ddef3c61 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddAutoIncrementGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddAutoIncrementGeneratorDatabricks.java @@ -11,7 +11,7 @@ public class AddAutoIncrementGeneratorDatabricks extends AddAutoIncrementGenerat @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java index 1001a543..fa64ebeb 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddColumnGeneratorDatabricks.java @@ -11,7 +11,7 @@ import liquibase.statement.DatabaseFunction; import liquibase.statement.NotNullConstraint; import liquibase.statement.core.AddColumnStatement; -import liquibase.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import java.util.Iterator; @@ -19,7 +19,7 @@ public class AddColumnGeneratorDatabricks extends AddColumnGenerator { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override @@ -52,7 +52,7 @@ protected String generateSingleColumnSQL(AddColumnStatement statement, Database ColumnConstraint constraint = var8.next(); if (constraint instanceof NotNullConstraint) { NotNullConstraint notNullConstraint = (NotNullConstraint)constraint; - if (StringUtil.isNotEmpty(notNullConstraint.getConstraintName())) { + if (StringUtils.isNotEmpty(notNullConstraint.getConstraintName())) { alterTable.append(" CONSTRAINT ").append(database.escapeConstraintName(notNullConstraint.getConstraintName())); break; } @@ -75,7 +75,7 @@ protected String generateSingleColumnSQL(AddColumnStatement statement, Database } if (database instanceof MySQLDatabase && statement.getRemarks() != null) { - alterTable.append(" COMMENT '").append(database.escapeStringForDatabase(StringUtil.trimToEmpty(statement.getRemarks()))).append("' "); + alterTable.append(" COMMENT '").append(database.escapeStringForDatabase(StringUtils.trimToEmpty(statement.getRemarks()))).append("' "); } if (statement.getAddBeforeColumn() != null && !statement.getAddBeforeColumn().isEmpty()) { diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java index 320475a1..c1b3dfd7 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddDefaultValueGeneratorDatabricks.java @@ -17,7 +17,7 @@ public class AddDefaultValueGeneratorDatabricks extends AddDefaultValueGenerator { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java index c146ba94..1402f68c 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddForeignKeyConstraintGeneratorDatabricks.java @@ -23,7 +23,7 @@ public boolean supports(AddForeignKeyConstraintStatement statement, Database dat @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java index 236646dc..d92123a6 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddPrimaryKeyGeneratorDatabricks.java @@ -16,12 +16,12 @@ public class AddPrimaryKeyGeneratorDatabricks extends AddPrimaryKeyGenerator { @Override public boolean supports(AddPrimaryKeyStatement statement, Database database) { - return (database instanceof DatabricksDatabase); + return database instanceof DatabricksDatabase; } @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddUniqueConstraintGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddUniqueConstraintGeneratorDatabricks.java index 47a9692a..3ddd7eb4 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/AddUniqueConstraintGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AddUniqueConstraintGeneratorDatabricks.java @@ -12,7 +12,7 @@ public class AddUniqueConstraintGeneratorDatabricks extends AddUniqueConstraintG @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterClusterGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterClusterGeneratorDatabricks.java new file mode 100644 index 00000000..3d3a2f16 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterClusterGeneratorDatabricks.java @@ -0,0 +1,49 @@ +package liquibase.ext.databricks.sqlgenerator; + +import liquibase.database.Database; +import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.change.alterCluster.AlterClusterDatabricksStatement; +import liquibase.ext.databricks.change.alterCluster.ColumnConfig; +import liquibase.sql.Sql; +import liquibase.sql.UnparsedSql; +import liquibase.sqlgenerator.SqlGeneratorChain; +import liquibase.sqlgenerator.core.AbstractSqlGenerator; + +public class AlterClusterGeneratorDatabricks extends AbstractSqlGenerator { + @Override + public ValidationErrors validate(AlterClusterDatabricksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { + ValidationErrors validationErrors = new ValidationErrors(); + if (statement.getClusterBy() == null && statement.getColumns() == null){ + validationErrors.addError("WARNING! Alter Cluster change require list of columns or element 'ClusterBy', please add at least one option."); + } + if (statement.getClusterBy() != null && (statement.getClusterBy().isEmpty() || !statement.getClusterBy().get(0).getNone().equals("true"))) { + validationErrors.addError("WARNING! ClusterBy attribute require attribute 'none=\"true\"'"); + } + return validationErrors; + } + + @Override + public Sql[] generateSql(AlterClusterDatabricksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { + StringBuilder buffer = new StringBuilder(); + + buffer.append("ALTER TABLE "); + buffer.append(database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName())); + buffer.append(" CLUSTER BY "); + if (statement.getColumns() != null && !statement.getColumns().isEmpty()) { + buffer.append("("); + for (ColumnConfig column : statement.getColumns()) { + buffer.append(column.getName()); + buffer.append(","); + } + buffer.deleteCharAt(buffer.length() - 1); + buffer.append(")"); + } else if (statement.getClusterBy() != null && !statement.getClusterBy().isEmpty()) { + buffer.append("NONE"); + } + + return new Sql[]{ + new UnparsedSql(buffer.toString()) + }; + } + +} diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterTablePropertiesGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterTablePropertiesGeneratorDatabricks.java new file mode 100644 index 00000000..db048347 --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/AlterTablePropertiesGeneratorDatabricks.java @@ -0,0 +1,52 @@ +package liquibase.ext.databricks.sqlgenerator; + +import liquibase.database.Database; +import liquibase.exception.ValidationErrors; +import liquibase.ext.databricks.change.alterTableProperties.AlterTablePropertiesStatementDatabricks; +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 AlterTablePropertiesGeneratorDatabricks extends AbstractSqlGenerator { + + @Override + public boolean supports(AlterTablePropertiesStatementDatabricks statement, Database database) { + return super.supports(statement, database) && (database instanceof DatabricksDatabase); + } + + @Override + public int getPriority() { + return PRIORITY_DATABASE; + } + + @Override + public ValidationErrors validate(AlterTablePropertiesStatementDatabricks statement, Database database, SqlGeneratorChain sqlGeneratorChain) { + ValidationErrors validationErrors = new ValidationErrors(); + if (statement.getSetExtendedTableProperties() == null && statement.getUnsetExtendedTableProperties() == null){ + validationErrors.addError("WARNING! Alter Table Properties change require 'setExtendedTableProperties' or 'unsetExtendedTableProperties' element, please add at least one option."); + } + return validationErrors; + } + + @Override + public Sql[] generateSql(AlterTablePropertiesStatementDatabricks statement, Database database, SqlGeneratorChain sqlGeneratorChain) { + StringBuilder buffer = new StringBuilder(); + + buffer.append("ALTER TABLE "); + buffer.append(database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName())); + if (statement.getSetExtendedTableProperties() != null) { + buffer.append(" SET TBLPROPERTIES ("); + buffer.append(statement.getSetExtendedTableProperties().getTblProperties()); + } else if (statement.getUnsetExtendedTableProperties() != null) { + buffer.append(" UNSET TBLPROPERTIES ("); + buffer.append(statement.getUnsetExtendedTableProperties().getTblProperties()); + } + buffer.append(")"); + + return new Sql[]{ + new UnparsedSql(buffer.toString()) + }; + } +} diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java index c7784d8e..ae3b450a 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateIndexGeneratorDatabricks.java @@ -23,6 +23,7 @@ */ +//TODO not used - figure out -fix or delete public class CreateIndexGeneratorDatabricks extends CreateIndexGenerator { @Override @@ -32,7 +33,7 @@ public boolean supports(CreateIndexStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java index 05f9531c..ec7afd17 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java @@ -20,7 +20,7 @@ public class CreateTableGeneratorDatabricks extends CreateTableGenerator { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @Override diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/GetViewDefinitionGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/GetViewDefinitionGeneratorDatabricks.java index 7335cfa0..17812bd0 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/GetViewDefinitionGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/GetViewDefinitionGeneratorDatabricks.java @@ -18,7 +18,7 @@ public class GetViewDefinitionGeneratorDatabricks extends GetViewDefinitionGener @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java index 95f06e1a..7f2c69dc 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/InsertOrUpdateGeneratorDatabricks.java @@ -20,7 +20,7 @@ public boolean supports(InsertOrUpdateStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java index b57d161c..be8c688b 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameColumnGeneratorDatabricks.java @@ -12,8 +12,8 @@ import liquibase.statement.core.RenameColumnStatement; import liquibase.structure.core.Column; import liquibase.structure.core.Table; -import liquibase.util.StringUtil; import liquibase.sqlgenerator.core.RenameColumnGenerator; +import org.apache.commons.lang3.StringUtils; public class RenameColumnGeneratorDatabricks extends RenameColumnGenerator { @@ -24,7 +24,7 @@ public boolean supports(RenameColumnStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @@ -36,7 +36,7 @@ public ValidationErrors validate(RenameColumnStatement renameColumnStatement, Da validationErrors.checkRequiredField("newColumnName", renameColumnStatement.getNewColumnName()); if (database instanceof MySQLDatabase) { - validationErrors.checkRequiredField("columnDataType", StringUtil.trimToNull(renameColumnStatement.getColumnDataType())); + validationErrors.checkRequiredField("columnDataType", StringUtils.trimToNull(renameColumnStatement.getColumnDataType())); } return validationErrors; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java index 8e582913..9561d62b 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameTableGeneratorDatabricks.java @@ -22,7 +22,7 @@ public boolean supports(RenameTableStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java index 86a22587..54827a58 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/RenameViewGeneratorDatabricks.java @@ -22,7 +22,7 @@ public boolean supports(RenameViewStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java index 10e1b05d..3af7b9e6 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetColumnRemarksGeneratorDatabricks.java @@ -3,7 +3,6 @@ import liquibase.ext.databricks.database.DatabricksDatabase; import liquibase.database.Database; import liquibase.database.core.*; -import liquibase.datatype.DataTypeFactory; import liquibase.exception.ValidationErrors; import liquibase.exception.Warnings; import liquibase.sql.Sql; @@ -11,11 +10,9 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.SetColumnRemarksStatement; import liquibase.structure.core.Column; -import liquibase.structure.core.Data; import liquibase.structure.core.Table; -import liquibase.util.ColumnParentType; -import liquibase.util.StringUtil; import liquibase.sqlgenerator.core.SetColumnRemarksGenerator; +import org.apache.commons.lang3.StringUtils; public class SetColumnRemarksGeneratorDatabricks extends SetColumnRemarksGenerator { @@ -26,7 +23,7 @@ public boolean supports(SetColumnRemarksStatement statement, Database database) @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @@ -37,7 +34,7 @@ public ValidationErrors validate(SetColumnRemarksStatement setColumnRemarksState validationErrors.checkRequiredField("columnName", setColumnRemarksStatement.getColumnName()); validationErrors.checkDisallowedField("catalogName", setColumnRemarksStatement.getCatalogName(), database, MSSQLDatabase.class); if (database instanceof MySQLDatabase) { - validationErrors.checkRequiredField("columnDataType", StringUtil.trimToNull(setColumnRemarksStatement.getColumnDataType())); + validationErrors.checkRequiredField("columnDataType", StringUtils.trimToNull(setColumnRemarksStatement.getColumnDataType())); } return validationErrors; } @@ -55,7 +52,7 @@ public Warnings warn(SetColumnRemarksStatement statementType, Database database, @Override public Sql[] generateSql(SetColumnRemarksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { - String remarksEscaped = database.escapeStringForDatabase(StringUtil.trimToEmpty(statement.getRemarks())); + String remarksEscaped = database.escapeStringForDatabase(StringUtils.trimToEmpty(statement.getRemarks())); return new Sql[]{new UnparsedSql("ALTER TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java index 3cef538b..a7975159 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/SetTableRemarksGeneratorDatabricks.java @@ -9,8 +9,8 @@ import liquibase.statement.core.SetTableRemarksStatement; import liquibase.structure.core.Relation; import liquibase.structure.core.Table; -import liquibase.util.StringUtil; import liquibase.sqlgenerator.core.SetTableRemarksGenerator; +import org.apache.commons.lang3.StringUtils; public class SetTableRemarksGeneratorDatabricks extends SetTableRemarksGenerator { @@ -21,7 +21,7 @@ public boolean supports(SetTableRemarksStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } @@ -35,7 +35,7 @@ public ValidationErrors validate(SetTableRemarksStatement setTableRemarksStateme @Override public Sql[] generateSql(SetTableRemarksStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql; - String remarksEscaped = database.escapeStringForDatabase(StringUtil.trimToEmpty(statement.getRemarks())); + String remarksEscaped = database.escapeStringForDatabase(StringUtils.trimToEmpty(statement.getRemarks())); sql = "COMMENT ON TABLE " + database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()) + " IS '" + remarksEscaped + "'"; diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/UpdateGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/UpdateGeneratorDatabricks.java index 3f30be4d..a455ecfa 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/UpdateGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/UpdateGeneratorDatabricks.java @@ -27,7 +27,7 @@ public boolean supports(UpdateStatement statement, Database database) { @Override public int getPriority() { - return DatabricksDatabase.DATABRICKS_PRIORITY_DATABASE; + return PRIORITY_DATABASE; } diff --git a/src/main/resources/META-INF/services/liquibase.change.Change b/src/main/resources/META-INF/services/liquibase.change.Change index 129e740c..59a3a1e3 100644 --- a/src/main/resources/META-INF/services/liquibase.change.Change +++ b/src/main/resources/META-INF/services/liquibase.change.Change @@ -4,4 +4,6 @@ liquibase.ext.databricks.change.analyzeTable.AnalyzeTableChange liquibase.ext.databricks.change.vacuumTable.VacuumTableChange liquibase.ext.databricks.change.addLookupTable.AddLookupTableChangeDatabricks liquibase.ext.databricks.change.addCheckConstraint.AddCheckConstraintChangeDatabricks -liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintChangeDatabricks \ No newline at end of file +liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintChangeDatabricks +liquibase.ext.databricks.change.alterTableProperties.AlterTablePropertiesChangeDatabricks +liquibase.ext.databricks.change.alterCluster.AlterClusterChangeDatabricks \ No newline at end of file diff --git a/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType b/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType index 14bb01cc..eeed1de7 100644 --- a/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType +++ b/src/main/resources/META-INF/services/liquibase.datatype.LiquibaseDataType @@ -1,10 +1,13 @@ -liquibase.ext.databricks.datatype.DatetimeDatatypeDatabricks +liquibase.ext.databricks.datatype.ArrayIntegerDataTypeDatabricks +liquibase.ext.databricks.datatype.ArrayStringDataTypeDatabricks liquibase.ext.databricks.datatype.BigintDatatypeDatabricks -liquibase.ext.databricks.datatype.StringDatatypeDatabricks -liquibase.ext.databricks.datatype.IntegerDatatypeDatabricks +liquibase.ext.databricks.datatype.BinaryDataTypeDatabricks liquibase.ext.databricks.datatype.BooleanDatatypeDatabricks -liquibase.ext.databricks.datatype.FloatDatatypeDatabricks +liquibase.ext.databricks.datatype.DatetimeDatatypeDatabricks liquibase.ext.databricks.datatype.DoubleDatatypeDatabricks -liquibase.ext.databricks.datatype.TinyintDatatypeDatabricks +liquibase.ext.databricks.datatype.FloatDatatypeDatabricks +liquibase.ext.databricks.datatype.IntegerDatatypeDatabricks liquibase.ext.databricks.datatype.SmallintDatatypeDatabricks -liquibase.ext.databricks.datatype.BinaryDataTypeDatabricks \ No newline at end of file +liquibase.ext.databricks.datatype.StringDatatypeDatabricks +liquibase.ext.databricks.datatype.TimestampDatatypeDatabricks +liquibase.ext.databricks.datatype.TinyintDatatypeDatabricks \ No newline at end of file diff --git a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator index 46fb3529..ea7bbb24 100644 --- a/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator +++ b/src/main/resources/META-INF/services/liquibase.sqlgenerator.SqlGenerator @@ -17,4 +17,6 @@ liquibase.ext.databricks.sqlgenerator.AddUniqueConstraintGeneratorDatabricks liquibase.ext.databricks.sqlgenerator.InsertOrUpdateGeneratorDatabricks liquibase.ext.databricks.sqlgenerator.UpdateGeneratorDatabricks liquibase.ext.databricks.change.addCheckConstraint.AddCheckConstraintGeneratorDatabricks -liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintGeneratorDatabricks \ No newline at end of file +liquibase.ext.databricks.change.dropCheckConstraint.DropCheckConstraintGeneratorDatabricks +liquibase.ext.databricks.sqlgenerator.AlterTablePropertiesGeneratorDatabricks +liquibase.ext.databricks.sqlgenerator.AlterClusterGeneratorDatabricks \ No newline at end of file diff --git a/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-1.0.xsd b/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-1.0.xsd index 973f4e36..415abea9 100644 --- a/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-1.0.xsd +++ b/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-1.0.xsd @@ -11,4 +11,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd b/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd index 973f4e36..415abea9 100644 --- a/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd +++ b/src/main/resources/www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd @@ -11,4 +11,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/addColumn.xml b/src/test/resources/liquibase/harness/change/changelogs/databricks/addColumn.xml index b62bf0ef..ea63e630 100644 --- a/src/test/resources/liquibase/harness/change/changelogs/databricks/addColumn.xml +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/addColumn.xml @@ -6,7 +6,8 @@ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> - + + diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.json b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.json new file mode 100644 index 00000000..8445058c --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.json @@ -0,0 +1,55 @@ +{ + "databaseChangeLog": [ + { + "changeSet": { + "id": "1", + "author": "your.name", + "changes": [ + { + "createTable": { + "tableName": "test_table_alter_cluster", + "columns": [ + { + "column": { + "name":"test_id", + "type": "int" + } + } + ] + } + } + ] + } + }, + { + "changeSet": { + "id": "2", + "author": "your.name", + "changes": [ + { + "alterCluster": { + "tableName": "test_table_alter_cluster", + "columns": [ + { + "column": { + "name": "test_id" + } + } + ] + } + } + ], + "rollback": [ + { + "alterCluster": { + "tableName": "test_table_alter_cluster", + "clusterBy": { + "none": "true" + } + } + } + ] + } + } + ] +} diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.xml b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.xml new file mode 100644 index 00000000..706b58b8 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.yaml b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.yaml new file mode 100644 index 00000000..8482ff00 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterCluster.yaml @@ -0,0 +1,25 @@ +databaseChangeLog: + - changeSet: + id: 1 + author: your.name + changes: + - createTable: + tableName: test_table_alter_cluster + columns: + - column: + name: test_id + type: int + - changeSet: + id: 2 + author: your.name + changes: + - alterCluster: + tableName: test_table_alter_cluster + columns: + - column: + name: test_id + rollback: + - alterCluster: + tableName: test_table_alter_cluster + clusterBy: + none: "true" diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.json b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.json new file mode 100644 index 00000000..c53b746c --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.json @@ -0,0 +1,51 @@ +{ + "databaseChangeLog": [ + { + "changeSet": { + "id": "1", + "author": "your.name", + "changes": [ + { + "createTable": { + "tableName": "test_alter_table_properties", + "columns": [ + { + "column": { + "name":"test_id", + "type": "int" + } + } + ] + } + } + ] + } + }, + { + "changeSet": { + "id": "2", + "author": "your.name", + "changes": [ + { + "alterTableProperties": { + "tableName": "test_alter_table_properties", + "setExtendedTableProperties": { + "tblProperties": "'external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true" + } + } + } + ], + "rollback": [ + { + "alterTableProperties": { + "tableName": "test_alter_table_properties", + "unsetExtendedTableProperties": { + "tblProperties": "'external.location', 'this.is.my.key','this.is.my.key2'" + } + } + } + ] + } + } + ] +} diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.xml b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.xml new file mode 100644 index 00000000..c6e1c94c --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.yaml b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.yaml new file mode 100644 index 00000000..5262b6ef --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/alterTableProperties.yaml @@ -0,0 +1,24 @@ +databaseChangeLog: + - changeSet: + id: 1 + author: your.name + changes: + - createTable: + tableName: test_alter_table_properties + columns: + - column: + name: test_id + type: int + - changeSet: + id: 2 + author: your.name + changes: + - alterTableProperties: + tableName: test_alter_table_properties + setExtendedTableProperties: + tblProperties: "'external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true" + rollback: + - alterTableProperties: + tableName: test_alter_table_properties + unsetExtendedTableProperties: + tblProperties: "'external.location', 'this.is.my.key','this.is.my.key2'" diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/dropCheckConstraint.xml b/src/test/resources/liquibase/harness/change/changelogs/databricks/dropCheckConstraint.xml new file mode 100644 index 00000000..a382d688 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/dropCheckConstraint.xml @@ -0,0 +1,20 @@ + + + + + + id > 0 + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/addColumn.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/addColumn.json new file mode 100644 index 00000000..a79972ea --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/addColumn.json @@ -0,0 +1,47 @@ +{ + "snapshot": { + "objects": { + "liquibase.structure.core.Table": [ + { + "table": { + "name": "authors" + } + } + ], + "liquibase.structure.core.Column": [ + { + "column": { + "name": "varcharColumn", + "type": { + + "columnSize": "50.*", + "typeName": "VARCHAR" + } + } + }, + { + "column": { + "name": "stringColumn", + "type": { + "columnSize": "255.*", + "typeName": "STRING" + } + } + }, + { + "column": { + "name": "intColumn", + "type": { + "typeName": "INT" + } + } + }, + { + "column": { + "name": "dateColumn" + } + } + ] + } + } +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterCluster.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterCluster.json new file mode 100644 index 00000000..7a73a41b --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterCluster.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterTableProperties.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterTableProperties.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/alterTableProperties.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/dropCheckConstraint.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/dropCheckConstraint.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/dropCheckConstraint.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/renameColumn.json b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/renameColumn.json index 6e0661ad..90670ebf 100644 --- a/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/renameColumn.json +++ b/src/test/resources/liquibase/harness/change/expectedSnapshot/databricks/renameColumn.json @@ -7,7 +7,8 @@ "name": "first_name_renameColumn_test", "nullable": false, "type": { - "typeName": "STRING" + "typeName": "VARCHAR", + "columnSize": "50.*" } } } diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/addColumn.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/addColumn.sql index 206769e9..b8982be3 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/addColumn.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/addColumn.sql @@ -1,6 +1,8 @@ -ALTER TABLE main.liquibase_harness_test_ds.authors ADD COLUMN varcharColumn STRING +ALTER TABLE main.liquibase_harness_test_ds.authors ADD COLUMN stringColumn STRING +ALTER TABLE main.liquibase_harness_test_ds.authors ADD COLUMN varcharColumn VARCHAR(50) ALTER TABLE main.liquibase_harness_test_ds.authors ADD COLUMN intColumn INT ALTER TABLE main.liquibase_harness_test_ds.authors ADD COLUMN dateColumn date +UPDATE main.liquibase_harness_test_ds.authors SET stringColumn = 'INITIAL_VALUE' UPDATE main.liquibase_harness_test_ds.authors SET varcharColumn = 'INITIAL_VALUE' UPDATE main.liquibase_harness_test_ds.authors SET intColumn = 5 UPDATE main.liquibase_harness_test_ds.authors SET dateColumn = '2023-09-21' \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterCluster.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterCluster.sql new file mode 100644 index 00000000..f20e7b33 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterCluster.sql @@ -0,0 +1,3 @@ +CREATE TABLE main.liquibase_harness_test_ds.test_table_alter_cluster (test_id INT NOT NULL, test_new INT, CONSTRAINT PK_TEST_TABLE_ALTER_CLUSTER PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) +ALTER TABLE main.liquibase_harness_test_ds.test_table_alter_cluster CLUSTER BY (test_id) +ALTER TABLE main.liquibase_harness_test_ds.test_table_alter_cluster CLUSTER BY (test_id,test_new) diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterTableProperties.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterTableProperties.sql new file mode 100644 index 00000000..24b6d1fe --- /dev/null +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/alterTableProperties.sql @@ -0,0 +1,2 @@ +CREATE TABLE main.liquibase_harness_test_ds.test_alter_table_properties (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_ALTER_TABLE_PROPERTIES PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) +ALTER TABLE main.liquibase_harness_test_ds.test_alter_table_properties SET TBLPROPERTIES ('external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true) diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createClusteredTable.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createClusteredTable.sql index 246e0f1b..ff45baab 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createClusteredTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createClusteredTable.sql @@ -1 +1 @@ -CREATE TABLE main.liquibase_harness_test_ds.test_table_clustered (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_TABLE_CLUSTERED PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') CLUSTER BY (test_id) \ No newline at end of file +CREATE TABLE main.liquibase_harness_test_ds.test_table_clustered (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_TABLE_CLUSTERED PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) CLUSTER BY (test_id) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createPartitionedTable.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createPartitionedTable.sql index da63f56a..e166036c 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createPartitionedTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createPartitionedTable.sql @@ -1 +1 @@ -CREATE TABLE main.liquibase_harness_test_ds.test_table_partitioned (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, partition_column STRING NOT NULL, CONSTRAINT PK_TEST_TABLE_PARTITIONED PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') PARTITIONED BY (partition_column) \ No newline at end of file +CREATE TABLE main.liquibase_harness_test_ds.test_table_partitioned (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, partition_column STRING NOT NULL, CONSTRAINT PK_TEST_TABLE_PARTITIONED PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) PARTITIONED BY (partition_column) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql index 9dfe9570..3370079d 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql @@ -1,2 +1,2 @@ CREATE TABLE main.liquibase_harness_test_ds.test_table (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_TABLE PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) -CREATE TABLE main.liquibase_harness_test_ds.test_table_properties (test_id INT NOT NULL, CONSTRAINT PK_TEST_TABLE_PROPERTIES PRIMARY KEY (test_id)) TBLPROPERTIES ('external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true) +CREATE TABLE main.liquibase_harness_test_ds.test_table_properties (test_id INT NOT NULL, CONSTRAINT PK_TEST_TABLE_PROPERTIES PRIMARY KEY (test_id)) TBLPROPERTIES ('external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableDataTypeText.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableDataTypeText.sql index a2547722..9bca49bf 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableDataTypeText.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableDataTypeText.sql @@ -1 +1 @@ -CREATE TABLE main.liquibase_harness_test_ds.createTableDataTypeText (textCol STRING) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') \ No newline at end of file +CREATE TABLE main.liquibase_harness_test_ds.createTableDataTypeText (textCol STRING) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableTimestamp.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableTimestamp.sql index bc6140ef..3cb5d2a8 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableTimestamp.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTableTimestamp.sql @@ -1 +1 @@ -CREATE TABLE main.liquibase_harness_test_ds.lms_create_table_test (lms_test_id INT, lms_test_timestamp TIMESTAMP) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') \ No newline at end of file +CREATE TABLE main.liquibase_harness_test_ds.lms_create_table_test (lms_test_id INT, lms_test_timestamp TIMESTAMP) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropCheckConstraint.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropCheckConstraint.sql index 5524f87c..6dac7691 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropCheckConstraint.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropCheckConstraint.sql @@ -1,2 +1,2 @@ -INVALID TEST --- Databricks Supports Check Constraints, but Liquibase OSS does not have the change type to extend \ No newline at end of file +ALTER TABLE main.liquibase_harness_test_ds.posts ADD CONSTRAINT test_check_constraint CHECK (id > 0) +ALTER TABLE main.liquibase_harness_test_ds.posts DROP CONSTRAINT test_check_constraint \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropTable.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropTable.sql index 3c0abc40..05033848 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/dropTable.sql @@ -1,2 +1,2 @@ -CREATE TABLE main.liquibase_harness_test_ds.test_table (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_TABLE PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') +CREATE TABLE main.liquibase_harness_test_ds.test_table (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_TEST_TABLE PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) DROP TABLE main.liquibase_harness_test_ds.test_table \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/mergeColumns.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/mergeColumns.sql index dedfb14b..82c2a4b6 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/mergeColumns.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/mergeColumns.sql @@ -1,7 +1,7 @@ -CREATE TABLE main.liquibase_harness_test_ds.full_name_table (first_name VARCHAR(50), last_name VARCHAR(50)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') +CREATE TABLE main.liquibase_harness_test_ds.full_name_table (first_name VARCHAR(50), last_name VARCHAR(50)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) INSERT INTO main.liquibase_harness_test_ds.full_name_table (first_name) VALUES ('John') UPDATE main.liquibase_harness_test_ds.full_name_table SET last_name = 'Doe' WHERE first_name='John' -INSERT INTO main.liquibase_harness_test_ds.full_name_table (first_name) VALUES ('Jane') + INSERT INTO main.liquibase_harness_test_ds.full_name_table (first_name) VALUES ('Jane') UPDATE main.liquibase_harness_test_ds.full_name_table SET last_name = 'Doe' WHERE first_name='Jane' ALTER TABLE main.liquibase_harness_test_ds.full_name_table ADD COLUMN full_name VARCHAR(255) UPDATE main.liquibase_harness_test_ds.full_name_table SET full_name = first_name || ' ' || last_name diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/modifySql.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/modifySql.sql index 9a3d13d2..e0da1b2d 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/modifySql.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/modifySql.sql @@ -1 +1 @@ -/* prepend comment */ CREATE TABLE main.liquibase_harness_test_ds.test_table (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_cs_guaranteed_delivery PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') -- append comment \ No newline at end of file +/* prepend comment */ CREATE TABLE main.liquibase_harness_test_ds.test_table (test_id INT NOT NULL, test_column VARCHAR(50) NOT NULL, CONSTRAINT PK_cs_guaranteed_delivery PRIMARY KEY (test_id)) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) -- append comment \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/sql.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/sql.sql index b01e0822..3e980823 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/sql.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/sql.sql @@ -1,4 +1,4 @@ -CREATE TABLE main.liquibase_harness_test_ds.sqltest (id INT) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') +CREATE TABLE main.liquibase_harness_test_ds.sqltest (id INT) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) insert into sqltest (id) values (1) insert into sqltest (id) values (2) insert into sqltest (id) values (3) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/change/expectedSql/databricks/sqlFile.sql b/src/test/resources/liquibase/harness/change/expectedSql/databricks/sqlFile.sql index b01e0822..3e980823 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/sqlFile.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/sqlFile.sql @@ -1,4 +1,4 @@ -CREATE TABLE main.liquibase_harness_test_ds.sqltest (id INT) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name') +CREATE TABLE main.liquibase_harness_test_ds.sqltest (id INT) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) insert into sqltest (id) values (1) insert into sqltest (id) values (2) insert into sqltest (id) values (3) \ No newline at end of file diff --git a/src/test/resources/liquibase/harness/snapshot/expectedSnapshot/databricks/addColumn.json b/src/test/resources/liquibase/harness/snapshot/expectedSnapshot/databricks/addColumn.json index 96eda625..1531929f 100644 --- a/src/test/resources/liquibase/harness/snapshot/expectedSnapshot/databricks/addColumn.json +++ b/src/test/resources/liquibase/harness/snapshot/expectedSnapshot/databricks/addColumn.json @@ -23,7 +23,7 @@ "name": "varcharColumn", "nullable": true, "type": { - "typeName": "STRING" + "typeName": "VARCHAR" } } },