Skip to content

Commit

Permalink
Merge pull request #102 from liquibase/fix-databricks-override-databases
Browse files Browse the repository at this point in the history
Implement missing "supports" methods
  • Loading branch information
CodyAustinDavis authored Feb 5, 2024
2 parents a183323 + cc181d9 commit ed7e1bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AddForeignKeyConstraintGeneratorDatabricks extends AddForeignKeyCon
@Override
@SuppressWarnings({"SimplifiableIfStatement"})
public boolean supports(AddForeignKeyConstraintStatement statement, Database database) {
return ((database instanceof DatabricksDatabase));
return (database instanceof DatabricksDatabase);
}

@Override
Expand Down Expand Up @@ -69,6 +69,7 @@ public Sql[] generateSql(AddForeignKeyConstraintStatement statement, Database da
};
}

@Override
protected ForeignKey getAffectedForeignKey(AddForeignKeyConstraintStatement statement) {
return new ForeignKey().setName(statement.getConstraintName()).setForeignKeyColumns(Column.listFromNames(statement.getBaseColumnNames())).setForeignKeyTable((Table) new Table().setName(statement.getBaseTableName()).setSchema(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package liquibase.ext.databricks.sqlgenerator;

import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.sqlgenerator.core.CreateIndexGenerator;


Expand All @@ -24,6 +25,11 @@
*/
public class CreateIndexGeneratorDatabricks extends CreateIndexGenerator {

@Override
public boolean supports(CreateIndexStatement statement, Database database) {
return super.supports(statement, database) && (database instanceof DatabricksDatabase);
}

@Override
public ValidationErrors validate(CreateIndexStatement createIndexStatement, Database database,
SqlGeneratorChain sqlGeneratorChain) {
Expand Down Expand Up @@ -60,15 +66,13 @@ public Sql[] generateSql(CreateIndexStatement statement, Database database, SqlG

buffer.append("ALTER TABLE ");

//System.out.println("INDEX CREATE SQL: " + fullyQualifiedTableName);

buffer.append(database.escapeTableName(statement.getTableCatalogName(), statement.getTableSchemaName(), statement.getTableName())).append(" CLUSTER BY ");

// get columns to cluster by
Iterator<AddColumnConfig> iterator = Arrays.asList(statement.getColumns()).iterator();

// if no cluster columns, then cluster by NONE - un-clustered Delta Table
if (iterator.hasNext() == false) {
if (!iterator.hasNext()) {

buffer.append(" NONE ");
}
Expand All @@ -91,6 +95,7 @@ public Sql[] generateSql(CreateIndexStatement statement, Database database, SqlG
return new Sql[] {new UnparsedSql(buffer.toString(), getAffectedIndex(statement))};
}

@Override
protected Index getAffectedIndex(CreateIndexStatement statement) {
return new Index().setName(statement.getIndexName()).setRelation(new Table().setName(statement.getTableName()).setSchema(statement.getTableCatalogName(), statement.getTableSchemaName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public UpdateGeneratorDatabricks() {
super();
}

@Override
public boolean supports(UpdateStatement statement, Database database) {
return super.supports(statement, database) && (database instanceof DatabricksDatabase);
}

@Override
public int getPriority() {
return DatabricksDatabase.PRIORITY_DATABASE;
Expand All @@ -36,7 +41,7 @@ public Sql[] generateSql(UpdateStatement statement, Database database, SqlGenera
sql.append(" ")
.append(database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), column))
.append(" = ")
.append(this.convertToString(statement.getNewColumnValues().get(column), database))
.append(this.convertObjectToString(statement.getNewColumnValues().get(column), database))
.append(",");
}

Expand All @@ -54,7 +59,7 @@ public Sql[] generateSql(UpdateStatement statement, Database database, SqlGenera
};
}

private String convertToString(Object newValue, Database database) {
private String convertObjectToString(Object newValue, Database database) {
String sqlString;
if ((newValue == null) || "NULL".equalsIgnoreCase(newValue.toString())) {
sqlString = "NULL";
Expand All @@ -69,7 +74,7 @@ private String convertToString(Object newValue, Database database) {

sqlString = database.getDateLiteral(date);
} else if (newValue instanceof Boolean) {
if (((Boolean) newValue)) {
if ((Boolean) newValue) {
sqlString = DataTypeFactory.getInstance().getTrueBooleanValue(database);
} else {
sqlString = DataTypeFactory.getInstance().getFalseBooleanValue(database);
Expand Down

0 comments on commit ed7e1bd

Please sign in to comment.