Search in sources :

Example 26 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 27 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 28 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 29 with IMetaStoreClient

use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project hive by apache.

the class SecureProxySupport method buildHcatDelegationToken.

private String buildHcatDelegationToken(String user) throws IOException, InterruptedException, TException {
    final HiveConf c = new HiveConf();
    final IMetaStoreClient client = HCatUtil.getHiveMetastoreClient(c);
    LOG.info("user: " + user + " loginUser: " + UserGroupInformation.getLoginUser().getUserName());
    final UserGroupInformation ugi = UgiFactory.getUgi(user);
    String s = ugi.doAs(new PrivilegedExceptionAction<String>() {

        public String run() throws IOException, MetaException, TException {
            String u = ugi.getUserName();
            return client.getDelegationToken(c.getUser(), u);
        }
    });
    return s;
}
Also used : TException(org.apache.thrift.TException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IOException(java.io.IOException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 30 with IMetaStoreClient

use of org.apache.hadoop.hive.metastore.IMetaStoreClient in project hive by apache.

the class PigHCatUtil method getTable.

/*
  * The job argument is passed so that configuration overrides can be used to initialize
  * the metastore configuration in the special case of an embedded metastore
  * (hive.metastore.uris = "").
  */
public Table getTable(String location, String hcatServerUri, String hcatServerPrincipal, Job job) throws IOException {
    Pair<String, String> loc_server = new Pair<String, String>(location, hcatServerUri);
    Table hcatTable = hcatTableCache.get(loc_server);
    if (hcatTable != null) {
        return hcatTable;
    }
    Pair<String, String> dbTablePair = PigHCatUtil.getDBTableNames(location);
    String dbName = dbTablePair.first;
    String tableName = dbTablePair.second;
    Table table = null;
    IMetaStoreClient client = null;
    try {
        client = getHiveMetaClient(hcatServerUri, hcatServerPrincipal, PigHCatUtil.class, job);
        table = HCatUtil.getTable(client, dbName, tableName);
    } catch (NoSuchObjectException nsoe) {
        // prettier error messages to frontend
        throw new PigException("Table not found : " + nsoe.getMessage(), PIG_EXCEPTION_CODE);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        HCatUtil.closeHiveClientQuietly(client);
    }
    hcatTableCache.put(loc_server, table);
    return table;
}
Also used : Table(org.apache.hadoop.hive.ql.metadata.Table) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) IOException(java.io.IOException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) PigException(org.apache.pig.PigException) HCatException(org.apache.hive.hcatalog.common.HCatException) PigException(org.apache.pig.PigException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Pair(org.apache.hive.hcatalog.data.Pair)

Aggregations

IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)41 TException (org.apache.thrift.TException)12 IOException (java.io.IOException)11 Path (org.apache.hadoop.fs.Path)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)11 HiveConf (org.apache.hadoop.hive.conf.HiveConf)10 HiveMetaStoreClient (org.apache.hadoop.hive.metastore.HiveMetaStoreClient)10 Table (org.apache.hadoop.hive.metastore.api.Table)10 Test (org.junit.Test)10 FileStatus (org.apache.hadoop.fs.FileStatus)9 FileSystem (org.apache.hadoop.fs.FileSystem)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)8 TxnStore (org.apache.hadoop.hive.metastore.txn.TxnStore)8 HiveEndPoint (org.apache.hive.hcatalog.streaming.HiveEndPoint)8 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)7 ArrayList (java.util.ArrayList)6 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