Skip to content

Commit

Permalink
[FLINK-28913][hive] Fix failed to open HiveCatalog when it's for hive3 (
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyuxia authored Aug 15, 2022
1 parent 7661af0 commit cb4ead7
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public class HiveMetastoreClientWrapper implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(HiveMetastoreClientWrapper.class);

private final IMetaStoreClient client;
private final Hive hive;
private final HiveConf hiveConf;
private final HiveShim hiveShim;
private volatile Hive hive;

public HiveMetastoreClientWrapper(HiveConf hiveConf, String hiveVersion) {
this(hiveConf, HiveShimLoader.loadHiveShim(hiveVersion));
Expand All @@ -87,11 +87,6 @@ public HiveMetastoreClientWrapper(HiveConf hiveConf, HiveShim hiveShim) {
HiveCatalog.isEmbeddedMetastore(hiveConf)
? createMetastoreClient()
: HiveMetaStoreClient.newSynchronizedClient(createMetastoreClient());
try {
this.hive = Hive.get(hiveConf);
} catch (HiveException e) {
throw new FlinkHiveException(e);
}
}

@Override
Expand Down Expand Up @@ -349,6 +344,7 @@ public void unlock(long lockid) throws NoSuchLockException, TxnOpenException, TE

public void loadTable(Path loadPath, String tableName, boolean replace, boolean isSrcLocal)
throws HiveException {
initHive();
hiveShim.loadTable(hive, loadPath, tableName, replace, isSrcLocal);
}

Expand All @@ -359,7 +355,22 @@ public void loadPartition(
boolean isSkewedStoreAsSubdir,
boolean replace,
boolean isSrcLocal) {
initHive();
hiveShim.loadPartition(
hive, loadPath, tableName, partSpec, isSkewedStoreAsSubdir, replace, isSrcLocal);
}

private void initHive() {
if (this.hive == null) {
synchronized (this) {
if (this.hive == null) {
try {
this.hive = Hive.get(hiveConf);
} catch (HiveException e) {
throw new FlinkHiveException(e);
}
}
}
}
}
}

0 comments on commit cb4ead7

Please sign in to comment.