use of org.apache.drill.shaded.guava.com.google.common.collect.MapDifference in project drill by apache.
the class IcebergMetastore method updateTableProperties.
/**
* Checks config table properties against current table properties.
* Adds properties that are absent, updates existing and removes absent.
* If properties are the same, does nothing.
*
* @param table Iceberg table instance
* @param tableProperties table properties from the config
*/
private void updateTableProperties(Table table, Map<String, String> tableProperties) {
Map<String, String> currentProperties = table.properties();
MapDifference<String, String> difference = Maps.difference(tableProperties, currentProperties);
if (difference.areEqual()) {
return;
}
UpdateProperties updateProperties = table.updateProperties();
// collect properties that are different
Map<String, String> propertiesToUpdate = difference.entriesDiffering().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().leftValue(), (o, n) -> n));
// add new properties
propertiesToUpdate.putAll(difference.entriesOnlyOnLeft());
logger.debug("Updating Iceberg table [{}] properties: {}", table.location(), updateProperties);
propertiesToUpdate.forEach(updateProperties::set);
logger.debug("Removing Iceberg table [{}] properties: {}", table.location(), difference.entriesOnlyOnRight());
difference.entriesOnlyOnRight().keySet().forEach(updateProperties::remove);
updateProperties.commit();
}
Aggregations