pyarrow parquet-将数组编码为记录列表

我正在使用Pandas和pyarrow创建Parquet文件,然后使用Java(org.apache.parquet.avro.AvroParquetReader)读取这些文件的架构。

我发现,使用pandas + pyarrow创建的拼花文件始终使用具有单个字段的记录数组来编码原始类型的数组。

使用PySpark时,我观察到相同的行为。这里有类似的问题Spark writing Parquet array<string> converts to a different datatype when loading into BigQuery

这是创建镶木地板文件的python脚本:

import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq


df = pd.DataFrame(
  {
    'organizationId' : ['org1','org2','org3'],'entityType' : ['customer','customer','customer'],'entityId' : ['cust_1','cust_2','cust_3'],'customerProducts' : [['p1','p2'],['p4','p5'],['p1','p3']]
  }
)

table = pa.Table.from_pandas(df)
pq.write_table(table,'output.parquet')

当我尝试读取该实木复合地板文件的Avro模式时,在“ customerProducts”字段中看到以下模式:

{"type":"array","items":{"type":"record","name":"list","fields":[{"name":"item","type":["null","string"],"default":null}]}}

但是我期望这样:

{"type":"array","default":null}]}}

任何人都知道是否有一种方法可以确保创建的具有原始类型数组的镶木地板文件将具有最简单的方案吗?

谢谢

kittyxnwei 回答:pyarrow parquet-将数组编码为记录列表

据我所知,parquet data model follows the capacitor data model允许列成为以下三种类型之一:

  1. 必需
  2. 可选
  3. 重复。

为了表示列表,需要使用嵌套类型来添加额外的间接级别,以区分空列表和仅包含空值的列表。

本文链接:https://www.f2er.com/2856183.html

大家都在问