15 package com.cloudera.impala.service;
17 import org.apache.hadoop.hive.metastore.api.FieldSchema;
18 import org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatUtils;
22 import com.cloudera.impala.thrift.TColumnValue;
23 import com.cloudera.impala.thrift.TDescribeTableOutputStyle;
24 import com.cloudera.impala.thrift.TDescribeTableResult;
25 import com.cloudera.impala.thrift.TResultRow;
26 import com.google.common.collect.Lists;
37 TDescribeTableOutputStyle outputFormat) {
38 switch (outputFormat) {
41 default:
throw new UnsupportedOperationException(
42 "Unknown TDescribeTableOutputStyle value: " + outputFormat);
51 TDescribeTableResult descResult =
new TDescribeTableResult();
52 descResult.results = Lists.newArrayList();
56 TColumnValue colNameCol =
new TColumnValue();
57 colNameCol.setString_val(column.getName());
58 TColumnValue dataTypeCol =
new TColumnValue();
59 dataTypeCol.setString_val(column.getType().toSql().toLowerCase());
60 TColumnValue commentCol =
new TColumnValue();
61 commentCol.setString_val(column.getComment() != null ? column.getComment() :
"");
62 descResult.results.add(
63 new TResultRow(Lists.newArrayList(colNameCol, dataTypeCol, commentCol)));
75 TDescribeTableResult descResult =
new TDescribeTableResult();
76 descResult.results = Lists.newArrayList();
78 org.apache.hadoop.hive.metastore.api.Table msTable =
79 table.getMetaStoreTable().deepCopy();
82 for (FieldSchema fs: msTable.getSd().getCols())
83 fs.setComment(table.getColumn(fs.getName()).getComment());
84 for (FieldSchema fs: msTable.getPartitionKeys()) {
85 fs.setComment(table.getColumn(fs.getName()).getComment());
91 org.apache.hadoop.hive.ql.metadata.Table hiveTable =
92 new org.apache.hadoop.hive.ql.metadata.Table();
93 hiveTable.setTTable(msTable);
94 StringBuilder sb =
new StringBuilder();
96 sb.append(MetaDataFormatUtils.getAllColumnsInformation(msTable.getSd().getCols(),
97 msTable.getPartitionKeys(),
true,
false,
true));
99 sb.append(MetaDataFormatUtils.getTableInformation(hiveTable));
101 for (String line: sb.toString().split(
"\n")) {
104 String[] columns = line.split(MetaDataFormatUtils.FIELD_DELIM);
105 TResultRow resultRow =
new TResultRow();
107 TColumnValue colVal =
new TColumnValue();
108 colVal.setString_val(null);
109 if (columns.length > i) {
111 colVal.setString_val(columns[i]);
113 resultRow.addToColVals(colVal);
115 descResult.results.add(resultRow);
ArrayList< Column > getColumnsInHiveOrder()
static TDescribeTableResult describeTableMinimal(Table table)
static TDescribeTableResult describeTableFormatted(Table table)
static TDescribeTableResult buildDescribeTableResult(Table table, TDescribeTableOutputStyle outputFormat)
static final int NUM_DESC_FORMATTED_RESULT_COLS