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);
}
}
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);
}
}
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;
}
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;
}
Aggregations