diff --git a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetadataPreservingTableOperations.java b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetadataPreservingTableOperations.java index c0e8101b1c..4d9f80d25f 100644 --- a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetadataPreservingTableOperations.java +++ b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveMetadataPreservingTableOperations.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.common.StatsSetupConst; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; @@ -38,6 +39,8 @@ import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -52,6 +55,8 @@ * updated. */ public class HiveMetadataPreservingTableOperations extends HiveTableOperations { + private static final Logger LOG = LoggerFactory.getLogger(HiveMetadataPreservingTableOperations.class); + private final HiveClientPool metaClients; private final String database; private final String tableName; @@ -70,6 +75,20 @@ protected HiveMetadataPreservingTableOperations(Configuration conf, HiveClientPo this.tableName = table; } + private static void logTable(Table table) { + String columns = ""; + try { + columns = table.getSd().getCols().stream().map(column -> column.getName() + " " + column.getType()) + .collect(Collectors.joining("\n")); + } catch (Throwable throwable) { + LOG.debug("Encountered {} while fetching columns for {}.{}", throwable.getMessage(), + table.getDbName(), table.getTableName(), throwable); + return; + } + LOG.debug("Table: {}.{}", table.getDbName(), table.getTableName()); + LOG.debug("Columns: \n{}", columns); + } + @Override protected void doRefresh() { String metadataLocation = null; @@ -131,6 +150,8 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) { boolean tableExists = metaClients.run(client -> client.tableExists(database, tableName)); if (tableExists) { tbl = metaClients.run(client -> client.getTable(database, tableName)); + LOG.debug("Following table has been fetched from metastore:"); + logTable(tbl); } else { final long currentTimeMillis = System.currentTimeMillis(); tbl = new Table(tableName, @@ -165,6 +186,9 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) { EnvironmentContext envContext = new EnvironmentContext( ImmutableMap.of(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE) ); + LOG.debug("Updating the metadata location of the following table:"); + logTable(tbl); + LOG.debug("Metadata Location: {}", tbl.getParameters().get(METADATA_LOCATION_PROP)); ALTER_TABLE.invoke(client, database, tableName, tbl, envContext); return null; });