Search in sources :

Example 1 with TextMetaDataTable

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;
}
Also used : TextMetaDataTable(org.apache.hadoop.hive.ql.metadata.formatting.TextMetaDataTable) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) DataOutputStream(java.io.DataOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) IOException(java.io.IOException) TextMetaDataTable(org.apache.hadoop.hive.ql.metadata.formatting.TextMetaDataTable)

Aggregations

DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1 TextMetaDataTable (org.apache.hadoop.hive.ql.metadata.formatting.TextMetaDataTable)1