当我试图跨多个分区的parquet文件加载时,一些模式会被推断为无效,因为缺少了用空值填充模式的数据。我认为在pyarrow.parquet.ParquetDataset中指定模式会解决这个问题,但我不知道如何构造正确的pyarrow.parquet.Schema类型的模式。一些示例代码:
import pyarrow as pa
import pa.parquet as pq
test_schema = pa.schema([pa.field('field1', pa.string()), pa.field('field2', pa.float64())])
paths = ['test_root/partition1/file1.parquet', 'test_root/partition2/file2.parquet']
dataset = pq.ParquetDataset(paths, schema=schema)而错误是:
AttributeError: 'pyarrow.lib.Schema' object has no attribute 'to_arrow_schema'但是,我找不到关于如何像docs (https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetDataset.html)那样构造pyarrow.parquet.Schema模式的任何文档,并且只创建了一个pyarrow.lib.Schema,这会导致上述错误。
发布于 2018-12-11 18:32:12
目前还没有在Python中构建Parquet模式的API。不过,您可以使用从特定文件读取的文件(请参阅pq.ParquetFile(...).schema)。
您能否在箭头JIRA项目上打开一个问题,以请求在Python中构造Parquet模式的特性?
发布于 2022-07-12 21:13:14
因此,谢谢你(无论你是谁),如果有机票和修正箭头JIRA的这一点。
我能够合并dataset中的文件模式和读取dataset:
import pyarrow as pa
import pa.parquet as pq
merged_schema = pa.schema([])
for filename in os.listdir(dataset_folder):
schema_ = pq.read_table(os.path.join(dataset_folder, filename)).schema
merged_schema = pa.unify_schemas([schema_, merged_schema])读取数据集:
dset = pq.ParquetDataset(
'my_dataset_folder',
schema=merged_schema,
use_legacy_dataset=False
).read()https://stackoverflow.com/questions/53725691
复制相似问题