如何获取现有Hive表的SerDe属性

时间:2013-10-31 19:46:56

标签: hadoop hive hiveql

我的同事在蜂巢中创建了一个表格,并添加了一个棘手的SerDe Regex。我想看看正则表达式是什么,但“SHOW CREATE TABLE”命令没有它。

是否有其他方法可以查看使用?

创建表的SERDEPROPERTIES

示例:

hive> CREATE TABLE foo (
  bar STRING
) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES ( "input.regex" = "(.*)", "output.format.string" = "%1$s" );

OK
Time taken: 0.078 seconds

hive> SHOW CREATE TABLE foo;
OK
CREATE  TABLE foo(
  bar string COMMENT 'from deserializer')
ROW FORMAT DELIMITED
STORED AS INPUTFORMAT
  'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  'maprfs:/user/hive/warehouse/foo'
TBLPROPERTIES (
  'transient_lastDdlTime'='1383248078')
Time taken: 0.091 seconds, Fetched: 11 row(s)

我正在使用hive 0.11。谢谢!

1 个答案:

答案 0 :(得分:8)

你可以做一个describe extended,它会显示你桌面的所有信息,包括你提到的serde属性。

例如你的桌子:

$ hive -e "describe extended foo"
Detailed Table Information  Table(tableName:foo, dbName:default, owner:cloudera, createTime:1383250992, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:bar, type:string, comment:null)], location:hdfs://localhost.localdomain:8020/user/hive/warehouse/foo, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.contrib.serde2.RegexSerDe, parameters:{output.format.string=%1$s, serialization.format=1, input.regex=(.*)}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[], parameters:{transient_lastDdlTime=1383250992}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE)

如果查看返回的对象,可以看到下面有趣的部分:

serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.contrib.serde2.RegexSerDe, parameters:{output.format.string=%1$s, serialization.format=1, input.regex=(.*)})