use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project hive by apache.
the class GetPrimaryKeysOperation method runInternal.
@Override
public void runInternal() throws HiveSQLException {
setState(OperationState.RUNNING);
try {
IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient();
PrimaryKeysRequest sqlReq = new PrimaryKeysRequest(schemaName, tableName);
List<SQLPrimaryKey> pks = metastoreClient.getPrimaryKeys(sqlReq);
if (pks == null) {
return;
}
for (SQLPrimaryKey pk : pks) {
rowSet.addRow(new Object[] { catalogName, pk.getTable_db(), pk.getTable_name(), pk.getColumn_name(), pk.getKey_seq(), pk.getPk_name() });
}
setState(OperationState.FINISHED);
} catch (Exception e) {
setState(OperationState.ERROR);
throw new HiveSQLException(e);
}
}
use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project hive by apache.
the class GetSchemasOperation method runInternal.
@Override
public void runInternal() throws HiveSQLException {
setState(OperationState.RUNNING);
if (isAuthV2Enabled()) {
String cmdStr = "catalog : " + catalogName + ", schemaPattern : " + schemaName;
authorizeMetaGets(HiveOperationType.GET_SCHEMAS, null, cmdStr);
}
try {
IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient();
String schemaPattern = convertSchemaPattern(schemaName);
for (String dbName : metastoreClient.getDatabases(schemaPattern)) {
rowSet.addRow(new Object[] { dbName, DEFAULT_HIVE_CATALOG });
}
setState(OperationState.FINISHED);
} catch (Exception e) {
setState(OperationState.ERROR);
throw new HiveSQLException(e);
}
}
use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project hive by apache.
the class TestHiveClientCache method testCacheMiss.
@Test
public void testCacheMiss() throws IOException, MetaException, LoginException {
HiveClientCache cache = new HiveClientCache(1000);
IMetaStoreClient client = cache.get(hiveConf);
assertNotNull(client);
// Set different uri as it is one of the criteria deciding whether to return the same client or not
// URIs are checked for string equivalence, even spaces make them different
hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, " ");
IMetaStoreClient client2 = cache.get(hiveConf);
assertNotNull(client2);
assertNotSame(client, client2);
}
use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project cdap by caskdata.
the class BaseHiveExploreService method startUp.
@Override
protected void startUp() throws Exception {
LOG.info("Starting {}...", BaseHiveExploreService.class.getSimpleName());
HiveConf hiveConf = getHiveConf();
setupSparkConf();
cliService.init(hiveConf);
cliService.start();
metastoreClientsExecutorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
Reference<? extends Supplier<IMetaStoreClient>> ref = metastoreClientReferenceQueue.poll();
while (ref != null) {
IMetaStoreClient client = metastoreClientReferences.remove(ref);
if (client != null) {
closeMetastoreClient(client);
}
ref = metastoreClientReferenceQueue.poll();
}
}
}, METASTORE_CLIENT_CLEANUP_PERIOD, METASTORE_CLIENT_CLEANUP_PERIOD, TimeUnit.SECONDS);
// Schedule the cache cleanup
scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
runCacheCleanup();
}
}, cleanupJobSchedule, cleanupJobSchedule, TimeUnit.SECONDS);
}
use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project cdap by caskdata.
the class BaseHiveExploreService method getMetaStoreClient.
private IMetaStoreClient getMetaStoreClient() throws ExploreException {
if (metastoreClientLocal.get() == null) {
try {
IMetaStoreClient client = new HiveMetaStoreClient(getHiveConf());
Supplier<IMetaStoreClient> supplier = Suppliers.ofInstance(client);
metastoreClientLocal.set(supplier);
// We use GC of the supplier as a signal for us to know that a thread is gone
// The supplier is set into the thread local, which will get GC'ed when the thread is gone.
// Since we use a weak reference key to the supplier that points to the client
// (in the metastoreClientReferences map), it won't block GC of the supplier instance.
// We can use the weak reference, which is retrieved through polling the ReferenceQueue,
// to get back the client and call close() on it.
metastoreClientReferences.put(new WeakReference<>(supplier, metastoreClientReferenceQueue), client);
} catch (MetaException e) {
throw new ExploreException("Error initializing Hive Metastore client", e);
}
}
return metastoreClientLocal.get().get();
}
Aggregations