在创建Hive表时,如何向使用serde创建的表添加列?

时间:2017-05-25 01:55:22

标签: sql hadoop hive

  • table desc info
hive> desc log23;
OK
col_name        data_type       comment
17/05/25 10:49:12 INFO mapred.FileInputFormat: Total input files to process : 1
host                    string                  from deserializer
remote_host             string                  from deserializer
remote_logname          string                  from deserializer
remote_user             string                  from deserializer
request_time            string                  from deserializer
request_method          string                  from deserializer
request_url             string                  from deserializer
first_line              string                  from deserializer
http_status             string                  from deserializer
bytes                   string                  from deserializer
referer                 string                  from deserializer
agent                   string                  from deserializer
Time taken: 0.049 seconds, Fetched: 12 row(s)
  • apache日志格式序列化
serializationLib:org.apache.hadoop.hive.contrib.serde2.RegexSerDe, parameters:{output.format.string=%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s %12$s, serialization.format=1, input.regex=([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) (-|\[[^\]]*\]) "(.[A-Z]*) (.*) (.*)" (-|[0-9]*) (-|[0-9]*) "(.*)" "(.*)"})
  • 使用Alter query
  • 添加列
hive> alter table log23 add columns (code string);

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. 
Error: type expected at the position 0 of derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:derived from deserializer:<derived from deserializer:derived from deserializer:string but>'<' is found.`

我收到如上所述的错误失败。如何添加列??

4 个答案:

答案 0 :(得分:1)

不幸的是,如果您使用了serde,则无法添加列。这是一个众所周知的问题: https://issues.apache.org/jira/browse/HIVE-17713

答案 1 :(得分:0)

ADD COLUMNS允许您将新列添加到现有列的末尾但在分区列之前。对于Hive 0.14及更高版本的Avro支持的表,也支持此功能。

REPLACE COLUMNS删除所有现有列并添加新的列集。这只能用于具有本机SerDe(DynamicSerDe,MetadataTypedColumnsetSerDe,LazySimpleSerDe和ColumnarSerDe)的表。有关更多信息,请参阅Hive SerDe。 REPLACE COLUMNS也可用于删除列。例如,“ALTER TABLE test_change REPLACE COLUMNS(int,b int);”将从test_change的架构中删除列'c'。

答案 2 :(得分:0)

我尝试了同样但我能够创建一个表并在最后添加列:

create table log23(host String,remote_host String); alter table log23 add columns(code String);

使用文本文件格式。如果您使用不同的文件格式,请告诉我,以便我尝试复制使用。

答案 3 :(得分:0)

我能够轻松地使用beeline进行这项工作-