Search in sources :

Example 1 with DescTableFormatter

use of org.apache.hadoop.hive.ql.ddl.table.info.desc.formatter.DescTableFormatter in project hive by apache.

the class DescTableOperation method execute.

@Override
public int execute() throws Exception {
    Table table = getTable();
    Partition part = getPartition(table);
    final String dbTableName = desc.getDbTableName();
    try (DataOutputStream outStream = ShowUtils.getOutputStream(new Path(desc.getResFile()), context)) {
        LOG.debug("DDLTask: got data for {}", dbTableName);
        List<FieldSchema> cols = new ArrayList<>();
        List<ColumnStatisticsObj> colStats = new ArrayList<>();
        Deserializer deserializer = getDeserializer(table);
        if (desc.getColumnPath() == null) {
            getColumnsNoColumnPath(table, part, cols);
        } else {
            if (desc.isFormatted()) {
                getColumnDataColPathSpecified(table, part, cols, colStats, deserializer);
            } else {
                cols.addAll(Hive.getFieldsFromDeserializer(desc.getColumnPath(), deserializer));
            }
        }
        fixDecimalColumnTypeName(cols);
        setConstraintsAndStorageHandlerInfo(table);
        handleMaterializedView(table);
        // 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();
        DescTableFormatter formatter = DescTableFormatter.getFormatter(context.getConf());
        formatter.describeTable(context.getConf(), outStream, desc.getColumnPath(), dbTableName, table, part, cols, desc.isFormatted(), desc.isExtended(), isOutputPadded, colStats);
        LOG.debug("DDLTask: written data for {}", dbTableName);
    } catch (SQLException e) {
        throw new HiveException(e, ErrorMsg.GENERIC_ERROR, dbTableName);
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) Partition(org.apache.hadoop.hive.ql.metadata.Partition) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) SQLException(java.sql.SQLException) DataOutputStream(java.io.DataOutputStream) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) Deserializer(org.apache.hadoop.hive.serde2.Deserializer) DescTableFormatter(org.apache.hadoop.hive.ql.ddl.table.info.desc.formatter.DescTableFormatter)

Aggregations

DataOutputStream (java.io.DataOutputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Path (org.apache.hadoop.fs.Path)1 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 DescTableFormatter (org.apache.hadoop.hive.ql.ddl.table.info.desc.formatter.DescTableFormatter)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 Partition (org.apache.hadoop.hive.ql.metadata.Partition)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1 Deserializer (org.apache.hadoop.hive.serde2.Deserializer)1