Skip to content
Merged
Changes from 1 commit
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 Down Expand Up @@ -131,6 +136,15 @@ 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));
String columns = "";

Choose a reason for hiding this comment

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

Could it be wrapped into a helper function (to log column names from table sd) since the code-block seems to be identical ?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

try {
columns = tbl.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(),
tbl.getDbName(), tbl.getTableName(), throwable);
}
LOG.debug("Found table: {}.{} with columns: {}", tbl.getDbName(), tbl.getTableName(), columns);
} else {
final long currentTimeMillis = System.currentTimeMillis();
tbl = new Table(tableName,
Expand Down Expand Up @@ -165,6 +179,16 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
EnvironmentContext envContext = new EnvironmentContext(
ImmutableMap.of(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE)
);
String columns = "";
try {
columns = tbl.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(),
tbl.getDbName(), tbl.getTableName(), throwable);
}
LOG.debug("Updating the metadata location for: {}.{} containing columns: {} with metadata location: {}",
tbl.getDbName(), tbl.getTableName(), columns, tbl.getParameters().get(METADATA_LOCATION_PROP));
ALTER_TABLE.invoke(client, database, tableName, tbl, envContext);
return null;
});
Expand Down