Impala + parquet文件

3
我已经创建了parquet文件,现在正在尝试将其导入Impala表中。
我按照以下方式创建了表:
CREATE EXTERNAL TABLE `user_daily` (
`user_id` BIGINT COMMENT 'User ID',
`master_id` BIGINT,
`walletAgency` BOOLEAN,
`zone_id` BIGINT COMMENT 'Zone ID',
`day` STRING COMMENT 'The stats are aggregated for single days',
`clicks` BIGINT COMMENT 'The number of clicks',
`impressions` BIGINT COMMENT 'The number of impressions',
`avg_position` BIGINT COMMENT 'The average position * 100',   
`money` BIGINT COMMENT 'The cost of the clicks, in hellers',
`web_id` BIGINT COMMENT 'Web ID',
`discarded_clicks` BIGINT COMMENT 'Number of discarded clicks from   column "clicks"',
`impression_money` BIGINT COMMENT 'The cost of the impressions, in hellers'
)
PARTITIONED BY (
 year BIGINT,
 month BIGINT
)
STORED AS PARQUET
LOCATION '/warehouse/impala/contextstat.db/user_daily/';

然后我使用以下模式将文件复制到那里:

parquet-tools schema user_daily/year\=2016/month\=8/part-r-00001-fd77e1cd-c824-4ebd-9328-0aca5a168d11.snappy.parquet 
message spark_schema {
  optional int32 user_id;
  optional int32 web_id (INT_16);
  optional int32 zone_id;
  required int32 master_id;
  required boolean walletagency;
  optional int64 impressions;
  optional int64 clicks;
  optional int64 money;
  optional int64 avg_position;
  optional double impression_money;
  required binary day (UTF8);
}

然后当我尝试查看带有的条目时。
SELECT * FROM user_daily;

我得到了。
File 'hdfs://.../warehouse/impala/contextstat.db/user_daily/year=2016/month=8/part-r-00000-fd77e1cd-c824-4ebd-9328-0aca5a168d11.snappy.parquet' 
has an incompatible Parquet schema for column 'contextstat.user_daily.user_id'. 
Column type: BIGINT, Parquet schema:
optional int32 user_id [i:0 d:1 r:0]

您知道如何解决这个问题吗?我认为BIGINT与int_32相同。我应该更改表的方案还是生成parquet文件的方式?

2个回答

3
BIGINT是int64,这就是为什么会出现错误的原因。但你不必自己弄清楚需要使用哪些不同的类型,Impala可以替你完成。只需使用CREATE TABLE LIKE PARQUET变体即可:
创建表的变体CREATE TABLE ... LIKE PARQUET 'hdfs_path_of_parquet_file'允许您跳过CREATE TABLE语句的列定义。根据指定Parquet数据文件的组织方式,列名和数据类型会自动配置,该文件必须已经驻留在HDFS中。

很遗憾,这种解决方案不符合我的需求。有一个特定的表格,其结构如上所示,我想坚持使用更改parquet文件的解决方案。顺便说一下:我尝试了一下...接下来出现了错误:ERROR: AnalysisException: Unsupported logical parquet type INT_16 (primitive type is INT32) for field web_id - United121
错误信息显示在表定义中没有类型可以与Parquet文件包含的内容兼容。如果您想遵循表定义并更改Parquet模式,则只需将所有int32实例更改为int64并删除(INT_16)部分即可。 - Zoltan
但是我该如何从该方案中删除(INT_16)部分呢?在调用parquet-tools scheme后,它会显示在已存在的文件中。是否有一种方法可以在已存在的文件中更改它? - United121
当你说“我想坚持改变Parquet文件的解决方案”时,我认为你是生成Parquet文件并想要更改该过程。如果你正在使用已经存在的Parquet文件,那么你无法更改它们的模式。 - Zoltan
是的,你说得对。更改parquet文件/模式的解决方案是可接受的。我希望更改它会很容易 :D。 - United121

0

我使用 CAST(... AS BIGINT),它将parquet架构从int32更改为int64。然后我必须重新排序列,因为它们无法按名称连接。然后它就可以工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接