Skip to content

Commit

Permalink
chore: Override the default implementation to ARRAY, MAP and STRUCT c…
Browse files Browse the repository at this point in the history
…omplex types as Liquibase core does not know how to handle values between <> in the data type.
  • Loading branch information
filipelautert committed Sep 9, 2024
1 parent 0c6e3a5 commit 8798462
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 76 deletions.

This file was deleted.

This file was deleted.

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);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
liquibase.ext.databricks.datatype.ArrayIntegerDataTypeDatabricks
liquibase.ext.databricks.datatype.ArrayStringDataTypeDatabricks
liquibase.ext.databricks.datatype.BigintDatatypeDatabricks
liquibase.ext.databricks.datatype.BinaryDataTypeDatabricks
liquibase.ext.databricks.datatype.BooleanDatatypeDatabricks
Expand All @@ -10,4 +8,4 @@ liquibase.ext.databricks.datatype.IntegerDatatypeDatabricks
liquibase.ext.databricks.datatype.SmallintDatatypeDatabricks
liquibase.ext.databricks.datatype.StringDatatypeDatabricks
liquibase.ext.databricks.datatype.TimestampDatatypeDatabricks
liquibase.ext.databricks.datatype.TinyintDatatypeDatabricks
liquibase.ext.databricks.datatype.TinyintDatatypeDatabricks
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ liquibase.ext.databricks.snapshot.jvm.ForeignKeySnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.UniqueConstraintSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.IndexSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.ViewSnapshotGeneratorDatabricks
liquibase.ext.databricks.snapshot.jvm.ColumnSnapshotGeneratorDatabricks

0 comments on commit 8798462

Please sign in to comment.