Skip to content

Commit

Permalink
Merge branch 'main' into DAT-18204
Browse files Browse the repository at this point in the history
  • Loading branch information
sayaliM0412 authored Jul 29, 2024
2 parents ce980ee + b13ceed commit f3607e1
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<liquibase.version>4.28.0</liquibase.version>
<liquibase.version>4.29.0</liquibase.version>
<sonar.organization>liquibase</sonar.organization>
<sonar.projectKey>${sonar.organization}_${project.artifactId}</sonar.projectKey>
<sonar.projectName>${project.name}</sonar.projectName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CreateTableChangeDatabricks extends CreateTableChange {
private String tableLocation;
private String clusterColumns;
private String partitionColumns;
private ExtendedTableProperties extendedTableProperties;


@Override
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CreateTableStatementDatabricks extends CreateTableStatement {

Expand All @@ -16,6 +15,8 @@ public class CreateTableStatementDatabricks extends CreateTableStatement {

private ArrayList<String> partitionColumns;

private ExtendedTableProperties extendedTableProperties;


public CreateTableStatementDatabricks(String catalogName, String schemaName, String tableName) {
super(catalogName, schemaName, tableName);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() + "'";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:databricks="http://www.liquibase.org/xml/ns/databricks"

xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/databricks
http://www.liquibase.org/xml/ns/databricks/liquibase-databricks-latest.xsd">

<changeSet id="1" author="oleh">
<createTable tableName="test_table">
<column name="test_id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="test_column" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet id="2" author="as">
<createTable tableName="test_table_properties">
<column name="test_id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<databricks:extendedTableProperties tblProperties="'external.location'='s3://mybucket/mytable','this.is.my.key'=12,'this.is.my.key2'=true"/>
</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -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', 'delta.enableDeletionVectors' = true)
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)

0 comments on commit f3607e1

Please sign in to comment.