generated from liquibase/liquibase-extension-example
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAT-17952] Add support for ARRAY, MAP and Struct datatypes (#181)
* chore: Override the default implementation to ARRAY, MAP and STRUCT complex types as Liquibase core does not know how to handle values between <> in the data type. * chore: adding tests. * chore: fix tests * added expected json data --------- Co-authored-by: KushnirykOleh <[email protected]>
- Loading branch information
1 parent
e3ce197
commit 141294b
Showing
8 changed files
with
112 additions
and
65 deletions.
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
src/main/java/liquibase/ext/databricks/datatype/ArrayIntegerDataTypeDatabricks.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/liquibase/ext/databricks/datatype/ArrayStringDataTypeDatabricks.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/main/java/liquibase/ext/databricks/snapshot/jvm/ColumnSnapshotGeneratorDatabricks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package liquibase.ext.databricks.snapshot.jvm; | ||
|
||
import liquibase.database.Database; | ||
import liquibase.exception.DatabaseException; | ||
import liquibase.ext.databricks.database.DatabricksDatabase; | ||
import liquibase.snapshot.CachedRow; | ||
import liquibase.snapshot.SnapshotGenerator; | ||
import liquibase.snapshot.jvm.ColumnSnapshotGenerator; | ||
import liquibase.structure.DatabaseObject; | ||
import liquibase.structure.core.Column; | ||
import liquibase.structure.core.DataType; | ||
|
||
public class ColumnSnapshotGeneratorDatabricks extends ColumnSnapshotGenerator { | ||
|
||
@Override | ||
public int getPriority(Class<? extends DatabaseObject> objectType, Database database) { | ||
if (database instanceof DatabricksDatabase) { | ||
return super.getPriority(objectType, database) + PRIORITY_DATABASE; | ||
} else { | ||
return PRIORITY_NONE; | ||
} | ||
} | ||
|
||
@Override | ||
public Class<? extends SnapshotGenerator>[] replaces() { | ||
return new Class[] { ColumnSnapshotGenerator.class }; | ||
} | ||
|
||
/** | ||
* Override the default implementation to ARRAY, MAP and STRUCT complex types as | ||
* Liquibase core does not know how to handle values between <> in the data type. | ||
*/ | ||
@Override | ||
protected DataType readDataType(CachedRow columnMetadataResultSet, Column column, Database database) throws DatabaseException { | ||
String dataType = (String) columnMetadataResultSet.get("TYPE_NAME"); | ||
if (dataType != null && database instanceof DatabricksDatabase | ||
&& (dataType.toUpperCase().startsWith("ARRAY") | ||
|| dataType.toUpperCase().startsWith("MAP") | ||
|| dataType.toUpperCase().startsWith("STRUCT"))) { | ||
DataType type = new DataType(dataType); | ||
type.setDataTypeId(columnMetadataResultSet.getInt("DATA_TYPE")); | ||
return type; | ||
} | ||
return super.readDataType(columnMetadataResultSet, column, database); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...test/resources/liquibase/harness/change/changelogs/databricks/createComplexTypesTable.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | ||
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/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | ||
|
||
<changeSet id="1" author="filipe"> | ||
<ext:createTable tableName="test_table_complex_types"> | ||
<column name="my_arrs" type="ARRAY<STRING>"/> | ||
<column name="my_arrbi" type="ARRAY<BIGINT>"/> | ||
<column name="my_map" type="MAP<STRING, BIGINT>"/> | ||
<column name="my_struct" type="STRUCT<FIELD1: STRING NOT NULL, FIELD2: INT>"/> | ||
</ext:createTable> | ||
</changeSet> | ||
</databaseChangeLog> |
47 changes: 47 additions & 0 deletions
47
...sources/liquibase/harness/change/expectedSnapshot/databricks/createComplexTypesTable.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"snapshot": { | ||
"objects": { | ||
"liquibase.structure.core.Table": [ | ||
{ | ||
"table": { | ||
"name": "test_table_complex_types" | ||
} | ||
} | ||
], | ||
"liquibase.structure.core.Column": [ | ||
{ | ||
"column": { | ||
"name": "my_arrs", | ||
"type": { | ||
"typeName": "ARRAY<STRING>" | ||
} | ||
} | ||
}, | ||
{ | ||
"column": { | ||
"name": "my_arrbi", | ||
"type": { | ||
"typeName": "ARRAY<BIGINT>" | ||
} | ||
} | ||
}, | ||
{ | ||
"column": { | ||
"name": "my_map", | ||
"type": { | ||
"typeName": "MAP<STRING, BIGINT>" | ||
} | ||
} | ||
}, | ||
{ | ||
"column": { | ||
"name": "my_struct", | ||
"type": { | ||
"typeName": "STRUCT<FIELD1: STRING NOT NULL, FIELD2: INT>" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...est/resources/liquibase/harness/change/expectedSql/databricks/createComplexTypesTable.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE TABLE main.liquibase_harness_test_ds.test_table_complex_types (my_arrs ARRAY<STRING>, my_arrbi ARRAY<BIGINT>, my_map MAP<STRING, BIGINT>, my_struct STRUCT<FIELD1: STRING NOT NULL, FIELD2: INT>) USING delta TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) |