【发布时间】:2021-03-12 07:46:50
【问题描述】:
正如您在下面的代码中看到的那样,我在向保存在内存映射文件中的表中添加新行时遇到了麻烦。 我只想用新行再次写入文件。
import pyarrow as pa
source = pa.memory_map(path, 'r')
table = pa.ipc.RecordBatchFileReader(source).read_all()
schema = pa.ipc.RecordBatchFileReader(source).schema
new_table = create_arrow_table(schema.names) #new table from pydict with same schema and random new values
updated_table = pa.concat_tables([table, new_table], promote=True)
source.close()
with pa.MemoryMappedFile(path, 'w') as sink:
with pa.RecordBatchFileWriter(sink, updated_table.schema) as writer:
writer.write_table(table)
我收到一个异常,指出内存映射文件未关闭:
ValueError: I/O operation on closed file.
有什么建议吗?
【问题讨论】:
标签: python memory-mapped-files pyarrow memory-mapping apache-arrow