From 059c719231d35df2a76e4f1a21e48359442e0e91 Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 18 Jul 2024 11:08:48 +0300 Subject: [PATCH 1/3] Add tblProperties --- .../CreateTableChangeDatabricks.java | 11 ++++++ .../CreateTableStatementDatabricks.java | 9 ++++- .../createTable/ExtendedTableProperties.java | 34 +++++++++++++++++++ .../CreateTableGeneratorDatabricks.java | 8 +++-- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/main/java/liquibase/ext/databricks/change/createTable/ExtendedTableProperties.java 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 471dee9a..a5ec4de7 100644 --- a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableChangeDatabricks.java @@ -16,6 +16,7 @@ public class CreateTableChangeDatabricks extends CreateTableChange { private String tableLocation; private String clusterColumns; private String partitionColumns; + private ExtendedTableProperties extendedTableProperties; @Override @@ -66,7 +67,17 @@ protected CreateTableStatement generateCreateTableStatement() { ctas.setTableLocation(this.getTableLocation()); ctas.setClusterColumns(this.getClusterColumns()); ctas.setPartitionColumns(this.getPartitionColumns()); + ctas.setExtendedTableProperties(this.getExtendedTableProperties()); return ctas; } + + @DatabaseChangeProperty + public ExtendedTableProperties getExtendedTableProperties() { + return extendedTableProperties; + } + + public void setExtendedTableProperties(ExtendedTableProperties extendedTableProperties) { + this.extendedTableProperties = extendedTableProperties; + } } diff --git a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java index 949040df..c8b9af1a 100644 --- a/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/change/createTable/CreateTableStatementDatabricks.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class CreateTableStatementDatabricks extends CreateTableStatement { @@ -16,6 +15,8 @@ public class CreateTableStatementDatabricks extends CreateTableStatement { private ArrayList partitionColumns; + private ExtendedTableProperties extendedTableProperties; + public CreateTableStatementDatabricks(String catalogName, String schemaName, String tableName) { super(catalogName, schemaName, tableName); @@ -55,5 +56,11 @@ public void setClusterColumns (String clusterColumns) { this.clusterColumns = new ArrayList<>(Arrays.asList(clusterColumns.split("\\s*,\\s*"))); } + public ExtendedTableProperties getExtendedTableProperties() { + return extendedTableProperties; + } + public void setExtendedTableProperties(ExtendedTableProperties extendedTableProperties) { + this.extendedTableProperties = extendedTableProperties; + } } diff --git a/src/main/java/liquibase/ext/databricks/change/createTable/ExtendedTableProperties.java b/src/main/java/liquibase/ext/databricks/change/createTable/ExtendedTableProperties.java new file mode 100644 index 00000000..3d3a681a --- /dev/null +++ b/src/main/java/liquibase/ext/databricks/change/createTable/ExtendedTableProperties.java @@ -0,0 +1,34 @@ +package liquibase.ext.databricks.change.createTable; + +import liquibase.serializer.AbstractLiquibaseSerializable; + +public class ExtendedTableProperties extends AbstractLiquibaseSerializable{ + private String tableLocation; + private String tblProperties; + + @Override + public String getSerializedObjectName() { + return "extendedTableProperties"; + } + + @Override + public String getSerializedObjectNamespace() { + return "http://www.liquibase.org/xml/ns/databricks"; + } + + public String getTableLocation() { + return tableLocation; + } + + public void setTableLocation(String tableLocation) { + this.tableLocation = tableLocation; + } + + public String getTblProperties() { + return tblProperties; + } + + public void setTblProperties(String tblProperties) { + this.tblProperties = tblProperties; + } +} diff --git a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java index f95118cf..5413ed9d 100644 --- a/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java +++ b/src/main/java/liquibase/ext/databricks/sqlgenerator/CreateTableGeneratorDatabricks.java @@ -11,7 +11,7 @@ import liquibase.sqlgenerator.SqlGeneratorChain; import liquibase.statement.core.CreateTableStatement; import liquibase.structure.DatabaseObject; -import liquibase.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -46,14 +46,16 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG if (statement instanceof CreateTableStatementDatabricks) { CreateTableStatementDatabricks thisStatement = (CreateTableStatementDatabricks) statement; - if ((!StringUtil.isEmpty(thisStatement.getTableFormat()))) { + if ((!StringUtils.isEmpty(thisStatement.getTableFormat()))) { finalsql += " USING " + thisStatement.getTableFormat(); + } else if (thisStatement.getExtendedTableProperties() != null && StringUtils.isNoneEmpty(thisStatement.getExtendedTableProperties().getTblProperties())) { + finalsql += " TBLPROPERTIES (" + thisStatement.getExtendedTableProperties().getTblProperties() + ")"; } else { finalsql += " USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true)"; } // Databricks can decide to have tables live in a particular location. If null, Databricks will handle the location automatically in DBFS - if (!StringUtil.isEmpty(thisStatement.getTableLocation())) { + if (!StringUtils.isEmpty(thisStatement.getTableLocation())) { finalsql += " LOCATION '" + thisStatement.getTableLocation() + "'"; } From 25b00d8a78759d29b9b706cd8224851d8c37baeb Mon Sep 17 00:00:00 2001 From: Vitalii Makarchenkov Date: Thu, 18 Jul 2024 11:18:50 +0300 Subject: [PATCH 2/3] Add tests for tblProperties --- .../changelogs/databricks/createTable.xml | 31 +++++++++++++++++++ .../expectedSql/databricks/createTable.sql | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/liquibase/harness/change/changelogs/databricks/createTable.xml diff --git a/src/test/resources/liquibase/harness/change/changelogs/databricks/createTable.xml b/src/test/resources/liquibase/harness/change/changelogs/databricks/createTable.xml new file mode 100644 index 00000000..3ad109c8 --- /dev/null +++ b/src/test/resources/liquibase/harness/change/changelogs/databricks/createTable.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + \ 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 9138aad6..9dfe9570 100644 --- a/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql +++ b/src/test/resources/liquibase/harness/change/expectedSql/databricks/createTable.sql @@ -1 +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') \ No newline at end of file +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) From e9a144f17ff2e76aba6ac970168d79cf2a7051e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:40:36 +0000 Subject: [PATCH 3/3] chore(deps): bump liquibase.version from 4.28.0 to 4.29.0 Bumps `liquibase.version` from 4.28.0 to 4.29.0. Updates `org.liquibase:liquibase-core` from 4.28.0 to 4.29.0 - [Release notes](https://github.com/liquibase/liquibase/releases) - [Changelog](https://github.com/liquibase/liquibase/blob/master/changelog.txt) - [Commits](https://github.com/liquibase/liquibase/compare/v4.28.0...v4.29.0) Updates `org.liquibase:liquibase-commercial` from 4.28.0 to 4.29.0 Updates `org.liquibase:liquibase-maven-plugin` from 4.28.0 to 4.29.0 - [Release notes](https://github.com/liquibase/liquibase/releases) - [Changelog](https://github.com/liquibase/liquibase/blob/master/changelog.txt) - [Commits](https://github.com/liquibase/liquibase/compare/v4.28.0...v4.29.0) --- updated-dependencies: - dependency-name: org.liquibase:liquibase-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.liquibase:liquibase-commercial dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.liquibase:liquibase-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3103ffdc..3f8b1da1 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 1.8 1.8 - 4.28.0 + 4.29.0 liquibase ${sonar.organization}_${project.artifactId} ${project.name}