Search in sources :

Example 31 with IMetaStoreClient

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);
    }
}
Also used : SQLPrimaryKey(org.apache.hadoop.hive.metastore.api.SQLPrimaryKey) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) PrimaryKeysRequest(org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest)

Example 32 with IMetaStoreClient

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);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 33 with IMetaStoreClient

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);
}
Also used : IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) Test(org.junit.Test)

Example 34 with IMetaStoreClient

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);
}
Also used : Reference(java.lang.ref.Reference) WeakReference(java.lang.ref.WeakReference) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Supplier(com.google.common.base.Supplier) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient)

Example 35 with IMetaStoreClient

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();
}
Also used : HiveMetaStoreClient(org.apache.hadoop.hive.metastore.HiveMetaStoreClient) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)43 TException (org.apache.thrift.TException)12 IOException (java.io.IOException)11 Path (org.apache.hadoop.fs.Path)11 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)11 Test (org.junit.Test)11 HiveConf (org.apache.hadoop.hive.conf.HiveConf)10 Table (org.apache.hadoop.hive.metastore.api.Table)10 FileStatus (org.apache.hadoop.fs.FileStatus)9 FileSystem (org.apache.hadoop.fs.FileSystem)9 TxnStore (org.apache.hadoop.hive.metastore.txn.TxnStore)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)8 HiveEndPoint (org.apache.hive.hcatalog.streaming.HiveEndPoint)8 ArrayList (java.util.ArrayList)7 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)7 DelimitedInputWriter (org.apache.hive.hcatalog.streaming.DelimitedInputWriter)6 StreamingConnection (org.apache.hive.hcatalog.streaming.StreamingConnection)6 Table (org.apache.hadoop.hive.ql.metadata.Table)5