use of org.apache.hadoop.hive.ql.metadata.formatting.TextMetaDataTable in project hive by apache.
the class DDLTask method showColumns.
/**
* Write a list of the columns in the table to a file.
*
* @param db
* The database in context.
* @param showCols
* A ShowColumnsDesc for columns we're interested in.
* @return Returns 0 when execution succeeds.
* @throws HiveException
* Throws this exception if an unexpected error occurs.
*/
public int showColumns(Hive db, ShowColumnsDesc showCols) throws HiveException {
Table table = db.getTable(showCols.getTableName());
// write the results in the file
DataOutputStream outStream = getOutputStream(showCols.getResFile());
try {
List<FieldSchema> allCols = table.getCols();
allCols.addAll(table.getPartCols());
List<FieldSchema> cols = getColumnsByPattern(allCols, showCols.getPattern());
// In case the query is served by HiveServer2, don't pad it with spaces,
// as HiveServer2 output is consumed by JDBC/ODBC clients.
boolean isOutputPadded = !SessionState.get().isHiveServerQuery();
TextMetaDataTable tmd = new TextMetaDataTable();
for (FieldSchema fieldSchema : cols) {
tmd.addRow(MetaDataFormatUtils.extractColumnValues(fieldSchema));
}
outStream.writeBytes(tmd.renderTable(isOutputPadded));
} catch (IOException e) {
throw new HiveException(e, ErrorMsg.GENERIC_ERROR);
} finally {
IOUtils.closeStream(outStream);
}
return 0;
}
Aggregations