use of org.apache.commons.exec.ExecuteException in project hive by apache.
the class HcatDelegator method descExtendedTable.
/**
* Return a json "show table extended like" with extra info from "desc exteded"
* This will return table with exact name match.
*/
public Response descExtendedTable(String user, String db, String table) throws HcatException, NotAuthorizedException, BusyException, ExecuteException, IOException {
String exec = String.format("use %s; show table extended like %s;", db, table);
try {
// get detailed "tableInfo" from query "desc extended tablename;"
Response res0 = descTable(user, db, table, true);
if (res0.getStatus() != HttpStatus.OK_200)
return res0;
Map m = (Map) res0.getEntity();
Map tableInfo = (Map) m.get("tableInfo");
String res = jsonRun(user, exec);
JsonBuilder jb = JsonBuilder.create(singleTable(res, table)).remove("tableName").put("database", db).put("table", table).put("retention", tableInfo.get("retention")).put("sd", tableInfo.get("sd")).put("parameters", tableInfo.get("parameters")).put("parametersSize", tableInfo.get("parametersSize")).put("tableType", tableInfo.get("tableType"));
// If we can get them from HDFS, add group and permission
String loc = (String) jb.getMap().get("location");
if (loc != null && loc.startsWith("hdfs://")) {
try {
FileSystem fs = FileSystem.get(appConf);
FileStatus status = fs.getFileStatus(new Path(new URI(loc)));
jb.put("group", status.getGroup());
jb.put("permission", status.getPermission().toString());
} catch (Exception e) {
LOG.warn(e.getMessage() + " Couldn't get permissions for " + loc);
}
}
return jb.build();
} catch (HcatException e) {
throw new HcatException("unable to show table: " + table, e.execBean, exec);
}
}
Aggregations