英文:
Is there a way to seek in an Avro Python?
问题
在编写多个Avro记录并通过DataFileWriter.sync存储它们的文件偏移量后,我想能够读取特定偏移量处的记录。
DataFileWriter.sync的文档中写道:
> 返回当前位置作为一个值,可以传递给DataFileReader.seek(long)
但这似乎是不正确的,因为DataFileReader没有名为seek的方法。我正在使用Avro Python库版本1.11.1。
英文:
After writing a number of Avro records and storing their file offsets via DataFileWriter.sync, I'd like to be able to read the record at a particular offset.
The documentation for DataFileWriter.sync states:
> Return the current position as a value that may be passed to
> DataFileReader.seek(long)
But this seems incorrect as DataFileReader has no method named seek. I am using the Avro Python library version 1.11.1.
答案1
得分: 0
以下是您要翻译的内容:
寻找底层文件对象的方法。
def read(path, offset):
with DataFileReader(open(path, 'rb'), DatumReader()) as reader:
reader.reader.seek(offset)
result = next(reader)
return result
英文:
Seeking the underlying file object works.
def read(path, offset):
with DataFileReader(open(path, 'rb'), DatumReader()) as reader:
reader.reader.seek(offset)
result = next(reader)
return result
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论