Skip to content

Commit

Permalink
[DAT-18149] Add cluster columns (#177)
Browse files Browse the repository at this point in the history
* Add databricks:clusterColumns element

* Add YAML and JSON cluster columns examples

* Add drop clustered column example

* Update changelogs to be identical to XML
  • Loading branch information
vitaliimak authored Sep 3, 2024
1 parent bc9387f commit 9148023
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
<xsd:enumeration value="true"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="clusterColumns" type="xsd:string"/>

</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
<xsd:enumeration value="true"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="clusterColumns" type="xsd:string"/>

</xsd:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"databaseChangeLog": [
{
"changeSet": {
"id": "1",
"author": "your.name",
"changes": [
{
"createTable": {
"tableName": "test_table_clustered_new",
"columns": [
{
"column": {
"name": "test_id",
"type": "int"
}
},
{
"column": {
"name": "test_new",
"type": "int"
}
}
],
"clusterColumns": "test_id,test_new"
}
}
],
"rollback": [
{
"dropTable": {
"tableName": "test_table_clustered_new"
}
}
]
}
},
{
"changeSet":{
"id": 2,
"author":"your.name",
"changes":[
{
"alterCluster": {
"tableName": "test_table_clustered_new",
"columns": [
{
"column": {
"name": "test_id"
}
}
]
}
}
],
"rollback": [
{
"empty": {
}
}
]
}
},
{
"changeSet": {
"id": 3,
"author": "your.name",
"changes": [
{
"dropColumn": {
"columnName": "test_new",
"tableName": "test_table_clustered_new"
}
}
],
"rollback": [
{
"empty": {
}
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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="as">
<createTable tableName="test_table_clustered_new" >
<column name="test_id" type="int" />
<column name="test_new" type="int"/>
<databricks:clusterColumns>test_id,test_new</databricks:clusterColumns>
</createTable>
<rollback>
<!-- The dropTable will drop a full table whether it has clustered columns or not. -->
<dropTable tableName="test_table_clustered_new"/>
</rollback>
</changeSet>
<changeSet id="2" author="your.name">
<databricks:alterCluster tableName="test_table_clustered_new">
<databricks:column name="test_id"/>
</databricks:alterCluster>
<rollback/>
</changeSet>
<changeSet id="3" author="your.name">
<!-- The Databricks does not allow clustered columns to be dropped, so they should be unclustered before the dropColumn in the alterCluster. -->
<dropColumn tableName="test_table_clustered_new" columnName="test_new"/>
<rollback/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
databaseChangeLog:
- changeSet:
id: 1
author: your.name
changes:
- createTable:
tableName: test_table_clustered_new
columns:
- column:
name: test_id
type: int
- column:
name: test_new
type: int
clusterColumns: test_id, test_new
rollback:
dropTable:
tableName: test_table_clustered_new
- changeSet:
id: 2
author: your.name
changes:
- alterCluster:
tableName: test_table_clustered_new
columns:
- column:
name: test_id
rollback:
empty
- changeSet:
id: 3
author: your.name
changes:
- dropColumn:
columnName: test_new
tableName: test_table_clustered_new
rollback:
empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE main.liquibase_harness_test_ds.test_table_clustered_new (test_id INT, test_new INT) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) CLUSTER BY (test_id, test_new)
ALTER TABLE main.liquibase_harness_test_ds.test_table_clustered_new CLUSTER BY (test_id)
ALTER TABLE main.liquibase_harness_test_ds.test_table_clustered_new DROP COLUMN test_new

0 comments on commit 9148023

Please sign in to comment.