从Vertica读取镶木地板并导出时,架构不一致

时间:2019-02-04 13:53:09

标签: python export parquet vertica pyarrow

当从Vertica导出数据并稍后尝试使用镶木地板(python)读取数据时,我注意到了奇怪的行为。 假设我要将表转储到镶木地板中:

EXPORT TO PARQUET (directory = '/data/table_name') over (partition by event_date) 
AS select * from table;

它给了我下一个结构:

/data/table_name
 - event_date=2019-01-01
 - event_date=2019-01-02
 - event_date=2019-01-03
...

然后我想用pyarrow阅读它:

import pyarrow.parquet as pq
df = pq.read_table('/data/table_name')

但是我收到了模式不一致的错误:

ValueError: Schema in partition[event_date=0] ./event_date=2019-01-01/84087de6-node0001-139759025940222.parquet was different.
user_id: string
event_id: int64
event_name: string
install_date: int32
event_date: int32
site_id: string

vs

user_id: string
event_id: int64
event_name: string
install_date: int32
site_id: string

为什么?

P.S。 如果我分别读取每个目录,则可以正常工作。

df1 = pq.read_table('/data/table_name/event_date=2019-01-01')
df2 = pq.read_table('/data/table_name/event_date=2019-01-02')
df3 = pq.read_table('/data/table_name/event_date=2019-01-02')

df1.schema == df2.schema == df3.schema
> True

1 个答案:

答案 0 :(得分:2)

您需要从导出查询中排除分区列(event_date):

EXPORT TO PARQUET (directory = '/data/table_name') over (partition by event_date) 
AS SELECT user_id,
          event_id,
          event_name,
          install_date,
          site_id
FROM table;