generated from liquibase/liquibase-extension-example
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DAT-19308 - feat(databricks): ensure essential table properties Delta.* #233
Merged
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8262a31
DAT-19308 - feat(databricks): ensure essential table properties are p…
CharlesQueiroz 4a79ace
DAT-19308 - feat(databricks): just to trigger the tests
CharlesQueiroz 7c1c4ad
DAT-19308 - Removing default values you don't need
CharlesQueiroz 8e9480b
DAT-19308 - To validate pipeline tests
CharlesQueiroz 45c9317
DAT-19308 - To validate pipeline tests
CharlesQueiroz 31994be
DAT-19308 - To validate pipeline tests
CharlesQueiroz 42de58d
DAT-19308 - Fixing tests
CharlesQueiroz 89d915b
DAT-19308 - Fixing tests
CharlesQueiroz 4c9ec5a
DAT-19308 - Fixing tests
CharlesQueiroz a17da30
DAT-19308 - cleanup the logic.
CharlesQueiroz 4e814e0
DAT-19308 - fixing tests
CharlesQueiroz 6dd2ef1
DAT-19308 - fixing tests
CharlesQueiroz 4b44ccb
DAT-19308 - fixing tests
CharlesQueiroz 97fd5a5
DAT-19308 - fixing tests
CharlesQueiroz 96ee659
DAT-19308 - fixing tests
CharlesQueiroz b4dd494
DAT-19308 - fixing tests
CharlesQueiroz 50bc107
DAT-19308 - fixing tests
CharlesQueiroz d40231d
DAT-19308 - fixing tests
CharlesQueiroz dc84426
brought back java 8
KushnirykOleh ba0f5b1
reverted test changes
KushnirykOleh 92b5816
reverted personal schema
KushnirykOleh d15e929
more rollbacks
KushnirykOleh 40cc1b2
more rollbacks
KushnirykOleh 59326f3
disabled external location IT test
KushnirykOleh 4e6c755
reverted chnages for local createTable testing
KushnirykOleh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
package liquibase.ext.databricks.sqlgenerator; | ||
|
||
|
||
import liquibase.database.Database; | ||
import liquibase.exception.ValidationErrors; | ||
import liquibase.ext.databricks.change.createTable.CreateTableStatementDatabricks; | ||
import liquibase.ext.databricks.database.DatabricksDatabase; | ||
import liquibase.sqlgenerator.core.CreateTableGenerator; | ||
import liquibase.database.Database; | ||
import liquibase.sql.Sql; | ||
import liquibase.sql.UnparsedSql; | ||
import liquibase.sqlgenerator.SqlGeneratorChain; | ||
import liquibase.sqlgenerator.core.CreateTableGenerator; | ||
import liquibase.statement.core.CreateTableStatement; | ||
import liquibase.structure.DatabaseObject; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class CreateTableGeneratorDatabricks extends CreateTableGenerator { | ||
|
||
private static final String[] PROPERTY_ORDER = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is still some spare time to fix we could get rid of this array and replace it by the keys from DEFAULT_VALUES . |
||
"'delta.feature.allowColumnDefaults'", | ||
"'delta.columnMapping.mode'", | ||
"'delta.enableDeletionVectors'" | ||
}; | ||
|
||
private static final Map<String, String> DEFAULT_VALUES = Stream.of( | ||
new AbstractMap.SimpleEntry<>("'delta.feature.allowColumnDefaults'", "'supported'"), | ||
new AbstractMap.SimpleEntry<>("'delta.columnMapping.mode'", "'name'"), | ||
new AbstractMap.SimpleEntry<>("'delta.enableDeletionVectors'", "true") | ||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
@Override | ||
public int getPriority() { | ||
return PRIORITY_DATABASE; | ||
|
@@ -29,16 +43,55 @@ public boolean supports(CreateTableStatement statement, Database database) { | |
|
||
public ValidationErrors validate(CreateTableStatementDatabricks createStatement, Database database, SqlGeneratorChain sqlGeneratorChain) { | ||
ValidationErrors validationErrors = new ValidationErrors(); | ||
if (!(createStatement.getPartitionColumns().isEmpty()) && !(createStatement.getClusterColumns().isEmpty())){ | ||
if (!(createStatement.getPartitionColumns().isEmpty()) && !(createStatement.getClusterColumns().isEmpty())) { | ||
validationErrors.addError("WARNING! Databricks does not supported creating tables with PARTITION and CLUSTER columns, please one supply one option."); | ||
} | ||
return validationErrors; | ||
} | ||
|
||
private String mergeTableProperties(String customProperties) { | ||
Map<String, String> properties = new LinkedHashMap<>(DEFAULT_VALUES); | ||
|
||
// If there are custom properties, parse and add them | ||
if (StringUtils.isNotEmpty(customProperties)) { | ||
Arrays.stream(customProperties.split(",")) | ||
.map(String::trim) | ||
.filter(prop -> !prop.isEmpty()) | ||
.forEach(prop -> { | ||
String[] parts = prop.split("=", 2); | ||
if (parts.length == 2) { | ||
properties.put(parts[0].trim(), parts[1].trim()); | ||
} | ||
}); | ||
} | ||
|
||
StringBuilder result = new StringBuilder(); | ||
|
||
for (String key : PROPERTY_ORDER) { | ||
if (properties.containsKey(key)) { | ||
if (result.length() > 0) { | ||
result.append(", "); | ||
} | ||
result.append(key).append(" = ").append(properties.get(key)); | ||
properties.remove(key); | ||
} | ||
} | ||
|
||
// Then add any remaining custom properties | ||
for (Map.Entry<String, String> entry : properties.entrySet()) { | ||
if (entry.getValue() != null && !entry.getValue().equals("null")) { | ||
if (result.length() > 0) { | ||
result.append(", "); | ||
} | ||
result.append(entry.getKey()).append(" = ").append(entry.getValue()); | ||
} | ||
} | ||
|
||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public Sql[] generateSql(CreateTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { | ||
|
||
Sql[] sqls = super.generateSql(statement, database, sqlGeneratorChain); | ||
StringBuilder finalsql = new StringBuilder(sqls[0].toSql()); | ||
|
||
|
@@ -50,13 +103,13 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG | |
} else { | ||
finalsql.append(" USING delta"); | ||
} | ||
if (thisStatement.getExtendedTableProperties() != null && StringUtils.isNotEmpty(thisStatement.getExtendedTableProperties().getTblProperties())) { | ||
finalsql.append(" TBLPROPERTIES (").append(thisStatement.getExtendedTableProperties().getTblProperties()).append(")"); | ||
} else { | ||
finalsql.append(" TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported', 'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true)"); | ||
|
||
String properties = null; | ||
if (thisStatement.getExtendedTableProperties() != null) { | ||
properties = thisStatement.getExtendedTableProperties().getTblProperties(); | ||
} | ||
finalsql.append(" TBLPROPERTIES(").append(mergeTableProperties(properties)).append(")"); | ||
|
||
// Databricks can decide to have tables live in a particular location. If null, Databricks will handle the location automatically in DBFS | ||
if (!StringUtils.isEmpty(thisStatement.getTableLocation())) { | ||
finalsql.append(" LOCATION '").append(thisStatement.getTableLocation()).append("'"); | ||
} else if (thisStatement.getExtendedTableProperties() != null && StringUtils.isNotEmpty(thisStatement.getExtendedTableProperties().getTableLocation())) { | ||
|
@@ -66,49 +119,34 @@ public Sql[] generateSql(CreateTableStatement statement, Database database, SqlG | |
List<String> clusterCols = thisStatement.getClusterColumns(); | ||
List<String> partitionCols = thisStatement.getPartitionColumns(); | ||
|
||
|
||
// If there are any cluster columns, add the clause | ||
// ONLY if there are NOT cluster columns, then do partitions, but never both. | ||
if (!clusterCols.isEmpty()) { | ||
|
||
finalsql.append(" CLUSTER BY ("); | ||
|
||
int val = 0; | ||
while (clusterCols.size() > val) { | ||
finalsql.append(clusterCols.get(val)); | ||
|
||
val +=1; | ||
val += 1; | ||
if (clusterCols.size() > val) { | ||
finalsql.append(", "); | ||
} | ||
else { | ||
} else { | ||
finalsql.append(")"); | ||
} | ||
} | ||
} else if (!partitionCols.isEmpty()) { | ||
finalsql.append(" PARTITIONED BY ("); | ||
|
||
int val = 0; | ||
while (partitionCols.size() > val) { | ||
finalsql.append(partitionCols.get(val)); | ||
|
||
val +=1; | ||
val += 1; | ||
if (partitionCols.size() > val) { | ||
finalsql.append(", "); | ||
} | ||
else { | ||
} else { | ||
finalsql.append(")"); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
sqls[0] = new UnparsedSql(finalsql.toString(), sqls[0].getAffectedDatabaseObjects().toArray(new DatabaseObject[0])); | ||
|
||
return sqls; | ||
|
||
} | ||
|
||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/test/java/liquibase/ext/databricks/AdvancedExtensionHarnessTestSuite.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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension should work on java 8, never mockito requires java 11