Skip to content

Commit

Permalink
Add reflection support for new data types (#107)
Browse files Browse the repository at this point in the history
* Add reflection support for new data types

Add snapshot reflection support for the following databricks data types:
-- Float
-- Double
-- Bool

* chore(sonar): fix sonar warnings

---------

Co-authored-by: filipe <[email protected]>
  • Loading branch information
CodyAustinDavis and filipelautert authored Feb 15, 2024
1 parent 855da70 commit 150757d
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-databricks</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.3-SNAPSHOT</version>

<name>Liquibase Extension: Databricks support</name>
<description>Liquibase Extension for Databricks.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package liquibase.ext.databricks.datatype;

import liquibase.change.core.LoadDataChange;
import liquibase.database.Database;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;

@DataTypeInfo(
name = "boolean",
minParameters = 0,
maxParameters = 0,
priority = PrioritizedService.PRIORITY_DATABASE
)
public class BooleanDatatypeDatabricks extends LiquibaseDataType {

public BooleanDatatypeDatabricks() {
// empty constructor
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DatabricksDatabase) {

DatabaseDataType type = new DatabaseDataType("BOOLEAN", this.getParameters());
type.setType("BOOLEAN");
return type;
} else {
return super.toDatabaseDataType(database);
}

}

public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
return LoadDataChange.LOAD_DATA_TYPE.BOOLEAN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package liquibase.ext.databricks.datatype;

import liquibase.change.core.LoadDataChange;
import liquibase.database.Database;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;

@DataTypeInfo(
name = "double",
minParameters = 0,
maxParameters = 0,
priority = PrioritizedService.PRIORITY_DATABASE
)
public class DoubleDatatypeDatabricks extends LiquibaseDataType {

public DoubleDatatypeDatabricks() {
// empty constructor
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DatabricksDatabase) {

DatabaseDataType type = new DatabaseDataType("DOUBLE", this.getParameters());
type.setType("DOUBLE");
return type;
} else {
return super.toDatabaseDataType(database);
}

}

public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
return LoadDataChange.LOAD_DATA_TYPE.NUMERIC;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package liquibase.ext.databricks.datatype;

import liquibase.change.core.LoadDataChange;
import liquibase.database.Database;
import liquibase.datatype.DataTypeInfo;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "float",
minParameters = 0,
maxParameters = 0,
priority = PrioritizedService.PRIORITY_DATABASE
)
public class FloatDatatypeDatabricks extends LiquibaseDataType {
public FloatDatatypeDatabricks() {
// empty constructor
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DatabricksDatabase) {

DatabaseDataType type = new DatabaseDataType("FLOAT", this.getParameters());
type.setType("FLOAT");
return type;
} else {
return super.toDatabaseDataType(database);
}

}

public LoadDataChange.LOAD_DATA_TYPE getLoadTypeName() {
return LoadDataChange.LOAD_DATA_TYPE.NUMERIC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.LiquibaseDataType;
import liquibase.ext.databricks.database.DatabricksDatabase;

import static liquibase.ext.databricks.database.DatabricksDatabase.PRIORITY_DATABASE;
import liquibase.servicelocator.PrioritizedService;


@DataTypeInfo(
name = "int",
minParameters = 0,
maxParameters = 0,
priority = PRIORITY_DATABASE
priority = PrioritizedService.PRIORITY_DATABASE
)
public class IntegerDatatypeDatabricks extends LiquibaseDataType {
public IntegerDatatypeDatabricks() {
// empty constructor
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof DatabricksDatabase) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ liquibase.ext.databricks.datatype.DatetimeDatatypeDatabricks
liquibase.ext.databricks.datatype.BigintDatatypeDatabricks
liquibase.ext.databricks.datatype.StringDatatypeDatabricks
liquibase.ext.databricks.datatype.IntegerDatatypeDatabricks
liquibase.ext.databricks.datatype.BooleanDatatypeDatabricks
liquibase.ext.databricks.datatype.FloatDatatypeDatabricks
liquibase.ext.databricks.datatype.DoubleDatatypeDatabricks

0 comments on commit 150757d

Please sign in to comment.