如何将TEXT格式分区表复制到Hive中的ORC格式表

时间:2016-08-09 03:08:21

标签: hadoop hive orc

我有一个Text Format配置单元表,如: CREATE EXTERNAL TABLE op_log ( time string, debug string,app_id string,app_version string, ...more fields) PARTITIONED BY (dt string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;

现在我创建一个具有相同字段的orc格式表,例如 CREATE TABLE op_log_orc ( time string, debug string,app_id string,app_version string, ...more fields) PARTITIONED BY (dt string) STORED AS ORC tblproperties ("orc.compress" = "SNAPPY");

当我从op_log复制到op_log_orc时,我收到了这个错误:

hive> insert into op_log_orc PARTITION(dt='2016-08-09') select * from op_log where dt='2016-08-09'; FAILED: SemanticException [Error 10044]: Line 1:12 Cannot insert into target table because column number/types are different ''2016-08-09'': Table insclause-0 has 62 columns, but query has 63 columns. hive>

1 个答案:

答案 0 :(得分:0)

源表中的分区键(dt)在结果集中返回,就像它是常规字段一样,因此您有额外的列。如果您要在分区键中指定其值,请从字段列表中排除dt字段(而不是*)。或者,只需指定dt作为分区的名称,而不提供值。请参阅此处示例中的CTAS(将表创建为选择...):https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableAsSelect(CTAS)