Skip to content

Commit

Permalink
Merge pull request #209 from liquibase/DAT-18966
Browse files Browse the repository at this point in the history
fix(DAT-18966): hide delta properties for tables/views
  • Loading branch information
PavloTytarchuk authored Nov 5, 2024
2 parents 0804823 + e1183ad commit fbae6b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static AbstractAlterPropertiesChangeDatabricks[] getAlterTablePropertiesChangeDa

static AbstractAlterPropertiesChangeDatabricks[] getAbstractTablePropertiesChangeDatabricks(AbstractDatabaseObject changedObject, DiffOutputControl control, Difference difference, Class<? extends AbstractAlterPropertiesChangeDatabricks> clazz) {
AbstractAlterPropertiesChangeDatabricks[] changes = new AbstractAlterPropertiesChangeDatabricks[0];
Map<String, String> referencedValuesMap = convertToMap(difference.getReferenceValue());
Map<String, String> comparedValuesMap = convertToMap(difference.getComparedValue());
Map<String, String> referencedValuesMap = convertToMapExcludingDeltaParameters(difference.getReferenceValue());
Map<String, String> comparedValuesMap = convertToMapExcludingDeltaParameters(difference.getComparedValue());

Map<String, String> addPropertiesMap = new HashMap<>();
//first we add the missing or changed properties
Expand Down Expand Up @@ -89,7 +89,10 @@ static AbstractAlterPropertiesChangeDatabricks[] getAbstractTablePropertiesChang
return changes;
}

private static Map<String, String> convertToMap(Object referenceValueObject) {
/**
* Convert the reference value to a map excluding delta parameters
*/
private static Map<String, String> convertToMapExcludingDeltaParameters(Object referenceValueObject) {
String referenceValue = referenceValueObject == null ? "" : referenceValueObject.toString();
return Arrays.stream(referenceValue.split(SPLIT_ON_COMMAS))
.map(s -> s.split(SPLIT_ON_EQUALS))
Expand All @@ -99,6 +102,14 @@ private static Map<String, String> convertToMap(Object referenceValueObject) {
.collect(Collectors.toMap(a -> a[0], a -> a[1]));
}

/**
* Get the extended properties excluding delta parameters
*/
public static String getExtendedProperties(String tblProperties) {
Map<String, String> properties = convertToMapExcludingDeltaParameters(tblProperties);
return properties.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(","));
}

private static AbstractAlterPropertiesChangeDatabricks getAbstractAlterPropertiesChangeDatabricks(AbstractDatabaseObject changedObject, DiffOutputControl control, Class<? extends AbstractAlterPropertiesChangeDatabricks> clazz) {
AbstractAlterPropertiesChangeDatabricks change;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Table;

import static liquibase.ext.databricks.diff.output.changelog.ChangedTblPropertiesUtil.getExtendedProperties;

public class MissingTableChangeGeneratorDatabricks extends MissingTableChangeGenerator {

@Override
Expand All @@ -33,7 +35,7 @@ public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl contr
//so far we intentionally omit tableLocation in generated changelog
ExtendedTableProperties extendedTableProperties = new ExtendedTableProperties(
null,
missingObject.getAttribute("tblProperties", String.class));
getExtendedProperties(missingObject.getAttribute("tblProperties", String.class)));
String clusterColumns = missingObject.getAttribute("clusteringColumns", "");

changes[0] = getCreateTableChangeDatabricks(extendedTableProperties, changes, clusterColumns);
Expand Down Expand Up @@ -65,4 +67,4 @@ private CreateTableChangeDatabricks getCreateTableChangeDatabricks(ExtendedTable
protected CreateTableChange createCreateTableChange() {
return new CreateTableChangeDatabricks();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.View;

import static liquibase.ext.databricks.diff.output.changelog.ChangedTblPropertiesUtil.getExtendedProperties;

/**
* Custom implementation of {@link MissingViewChangeGenerator} for Databricks.
*/
Expand All @@ -31,7 +33,7 @@ public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl contr
if (changes == null || changes.length == 0) {
return changes;
}
changes[0] = getCreateViewChangeDatabricks(missingObject.getAttribute("tblProperties", String.class), changes);
changes[0] = getCreateViewChangeDatabricks(getExtendedProperties(missingObject.getAttribute("tblProperties", String.class)), changes);
return changes;
}

Expand Down

0 comments on commit fbae6b5

Please sign in to comment.