当我尝试加载一个多分区的parquet文件时,由于缺失数据而填充null,导致一些模式被错误地推断为无效。我认为在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'
但是我找不到任何关于如何构建pyarrow.parquet.Schema模式的文档,就像文档中描述的那样(https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetDataset.html),我只能创建一个pyarrow.lib.Schema,但这却导致了上述错误。