如何在 Hive 中将分区 table 的 TEXT 格式复制到 ORC 格式 Table

How to Copy TEXT format partitioned table to ORC format Table in Hive

我有一个文本格式配置单元 table,例如: 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 格式 table,比如 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>

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