Search in sources :

Example 1 with TableMeta

use of org.apache.hadoop.hive.metastore.api.TableMeta in project hive by apache.

the class GetTablesOperation method runInternal.

@Override
public void runInternal() throws HiveSQLException {
    setState(OperationState.RUNNING);
    try {
        IMetaStoreClient metastoreClient = getParentSession().getMetaStoreClient();
        String schemaPattern = convertSchemaPattern(schemaName);
        List<String> matchingDbs = metastoreClient.getDatabases(schemaPattern);
        if (isAuthV2Enabled()) {
            List<HivePrivilegeObject> privObjs = HivePrivilegeObjectUtils.getHivePrivDbObjects(matchingDbs);
            String cmdStr = "catalog : " + catalogName + ", schemaPattern : " + schemaName;
            authorizeMetaGets(HiveOperationType.GET_TABLES, privObjs, cmdStr);
        }
        String tablePattern = convertIdentifierPattern(tableName, true);
        for (TableMeta tableMeta : metastoreClient.getTableMeta(schemaPattern, tablePattern, tableTypeList)) {
            rowSet.addRow(new Object[] { DEFAULT_HIVE_CATALOG, tableMeta.getDbName(), tableMeta.getTableName(), tableTypeMapping.mapToClientType(tableMeta.getTableType()), tableMeta.getComments(), null, null, null, null, null });
        }
        setState(OperationState.FINISHED);
    } catch (Exception e) {
        setState(OperationState.ERROR);
        throw new HiveSQLException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) TableMeta(org.apache.hadoop.hive.metastore.api.TableMeta) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 2 with TableMeta

use of org.apache.hadoop.hive.metastore.api.TableMeta in project hive by apache.

the class HBaseStore method getTableMeta.

@Override
public List<TableMeta> getTableMeta(String dbNames, String tableNames, List<String> tableTypes) throws MetaException {
    boolean commit = false;
    openTransaction();
    try {
        List<TableMeta> metas = new ArrayList<>();
        for (String dbName : getDatabases(dbNames)) {
            for (Table table : getTableObjectsByName(dbName, getTableNamesInTx(dbName, tableNames))) {
                if (tableTypes == null || tableTypes.contains(table.getTableType())) {
                    TableMeta metaData = new TableMeta(table.getDbName(), table.getTableName(), table.getTableType());
                    metaData.setComments(table.getParameters().get("comment"));
                    metas.add(metaData);
                }
            }
        }
        commit = true;
        return metas;
    } catch (Exception e) {
        LOG.error("Unable to get tables ", e);
        throw new MetaException("Unable to get tables, " + e.getMessage());
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) ArrayList(java.util.ArrayList) TableMeta(org.apache.hadoop.hive.metastore.api.TableMeta) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) TException(org.apache.thrift.TException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) IOException(java.io.IOException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 3 with TableMeta

use of org.apache.hadoop.hive.metastore.api.TableMeta in project hive by apache.

the class SessionHiveMetaStoreClient method getTableMeta.

@Override
public List<TableMeta> getTableMeta(String dbPatterns, String tablePatterns, List<String> tableTypes) throws MetaException {
    List<TableMeta> tableMetas = super.getTableMeta(dbPatterns, tablePatterns, tableTypes);
    Map<String, Map<String, Table>> tmpTables = getTempTables();
    if (tmpTables.isEmpty()) {
        return tableMetas;
    }
    List<Matcher> dbPatternList = new ArrayList<>();
    for (String element : dbPatterns.split("\\|")) {
        dbPatternList.add(Pattern.compile(element.replaceAll("\\*", ".*")).matcher(""));
    }
    List<Matcher> tblPatternList = new ArrayList<>();
    for (String element : tablePatterns.split("\\|")) {
        tblPatternList.add(Pattern.compile(element.replaceAll("\\*", ".*")).matcher(""));
    }
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, Map<String, Table>> outer : tmpTables.entrySet()) {
        if (!matchesAny(outer.getKey(), dbPatternList)) {
            continue;
        }
        for (Map.Entry<String, Table> inner : outer.getValue().entrySet()) {
            Table table = inner.getValue();
            String tableName = table.getTableName();
            String typeString = table.getTableType().name();
            if (tableTypes != null && !tableTypes.contains(typeString)) {
                continue;
            }
            if (!matchesAny(inner.getKey(), tblPatternList)) {
                continue;
            }
            TableMeta tableMeta = new TableMeta(table.getDbName(), tableName, typeString);
            tableMeta.setComments(table.getProperty("comment"));
            tableMetas.add(tableMeta);
        }
    }
    return tableMetas;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) TableMeta(org.apache.hadoop.hive.metastore.api.TableMeta) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with TableMeta

use of org.apache.hadoop.hive.metastore.api.TableMeta in project hive by apache.

the class ObjectStore method getTableMeta.

@Override
public List<TableMeta> getTableMeta(String dbNames, String tableNames, List<String> tableTypes) throws MetaException {
    boolean commited = false;
    Query query = null;
    List<TableMeta> metas = new ArrayList<TableMeta>();
    try {
        openTransaction();
        // Take the pattern and split it on the | to get all the composing
        // patterns
        StringBuilder builder = new StringBuilder();
        if (dbNames != null && !dbNames.equals("*")) {
            appendPatternCondition(builder, "database.name", dbNames);
        }
        if (tableNames != null && !tableNames.equals("*")) {
            appendPatternCondition(builder, "tableName", tableNames);
        }
        if (tableTypes != null && !tableTypes.isEmpty()) {
            appendSimpleCondition(builder, "tableType", tableTypes.toArray(new String[0]));
        }
        query = pm.newQuery(MTable.class, builder.toString());
        Collection<MTable> tables = (Collection<MTable>) query.execute();
        for (MTable table : tables) {
            TableMeta metaData = new TableMeta(table.getDatabase().getName(), table.getTableName(), table.getTableType());
            metaData.setComments(table.getParameters().get("comment"));
            metas.add(metaData);
        }
        commited = commitTransaction();
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    return metas;
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) Query(javax.jdo.Query) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TableMeta(org.apache.hadoop.hive.metastore.api.TableMeta)

Aggregations

TableMeta (org.apache.hadoop.hive.metastore.api.TableMeta)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Query (javax.jdo.Query)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)1 UnknownPartitionException (org.apache.hadoop.hive.metastore.api.UnknownPartitionException)1 UnknownTableException (org.apache.hadoop.hive.metastore.api.UnknownTableException)1 MTable (org.apache.hadoop.hive.metastore.model.MTable)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1