Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


/**
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -131,6 +150,7 @@ 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));
logTable(tbl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we print one more line before each logTable call which provides some context so that the log lines are clearer?
Something along the lines of Fetched table from metastore and Updating table in metastore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

} else {
final long currentTimeMillis = System.currentTimeMillis();
tbl = new Table(tableName,
Expand Down Expand Up @@ -165,6 +185,8 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
EnvironmentContext envContext = new EnvironmentContext(
ImmutableMap.of(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE)
);
logTable(tbl);
LOG.debug("Metadata Location: {}", tbl.getParameters().get(METADATA_LOCATION_PROP));
ALTER_TABLE.invoke(client, database, tableName, tbl, envContext);
return null;
});
Expand Down