Search in sources :

Example 1 with MapDifference

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();
}
Also used : AlreadyExistsException(org.apache.iceberg.exceptions.AlreadyExistsException) IcebergTables(org.apache.drill.metastore.iceberg.components.tables.IcebergTables) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IcebergConfigConstants(org.apache.drill.metastore.iceberg.config.IcebergConfigConstants) Maps(org.apache.drill.shaded.guava.com.google.common.collect.Maps) IcebergMetastoreException(org.apache.drill.metastore.iceberg.exceptions.IcebergMetastoreException) Configuration(org.apache.hadoop.conf.Configuration) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) IcebergTableSchema(org.apache.drill.metastore.iceberg.schema.IcebergTableSchema) Metastore(org.apache.drill.metastore.Metastore) MapDifference(org.apache.drill.shaded.guava.com.google.common.collect.MapDifference) Logger(org.slf4j.Logger) Views(org.apache.drill.metastore.components.views.Views) Config(com.typesafe.config.Config) Table(org.apache.iceberg.Table) HadoopTables(org.apache.iceberg.hadoop.HadoopTables) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) UpdateProperties(org.apache.iceberg.UpdateProperties) DrillConfig(org.apache.drill.common.config.DrillConfig) Tables(org.apache.drill.metastore.components.tables.Tables) Collections(java.util.Collections) UpdateProperties(org.apache.iceberg.UpdateProperties) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors (java.util.stream.Collectors)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 Metastore (org.apache.drill.metastore.Metastore)1 Tables (org.apache.drill.metastore.components.tables.Tables)1 Views (org.apache.drill.metastore.components.views.Views)1 IcebergTables (org.apache.drill.metastore.iceberg.components.tables.IcebergTables)1 IcebergConfigConstants (org.apache.drill.metastore.iceberg.config.IcebergConfigConstants)1 IcebergMetastoreException (org.apache.drill.metastore.iceberg.exceptions.IcebergMetastoreException)1 IcebergTableSchema (org.apache.drill.metastore.iceberg.schema.IcebergTableSchema)1 MapDifference (org.apache.drill.shaded.guava.com.google.common.collect.MapDifference)1 Maps (org.apache.drill.shaded.guava.com.google.common.collect.Maps)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1