我特别不熟悉 Avro 和 Avro.jl。我在编写记录然后以稍后可以阅读的方式附加第二条记录时遇到困难。我还需要能够读取 python 和 Julia 中的文件。
我选择使用 Avro,因为它是基于行的,并且我需要在模拟运行时一次添加一行(即记录)。CSV 不起作用,因为我的数据没有固定的列。
——
更新:我在这里插入我遇到的问题的简化版本。
以下代码尝试将多条记录写入一个文件,然后读取它们。在 Julia 中,它只读取第一条记录。在python中,我可以读取所有记录。我曾尝试使用 Avro.writetable 但没有取得多大成功。
import Avro,StructTypes,Tables,JSON3,Base
import Random
District=Dict{String,Int}
Districting=Dict{String,District}
Base.@kwdef struct Map
name::String
districting::Districting
desc::String=""
numLevels::Int=1
end
#
#
districting=Districting()
d=District()
t=()
#
keys=["P1","P2","P3","C1","B1"]
io=open("map1Test.avro","w")
#
rng = Random.MersenneTwister(1234);
#
for i=1:4
for j=1:3
for k in keys
d[k]=convert(Int,floor(100*Random.rand(rng)))
end
districting[string("D",j)]=d
end
t=(name=string("map",i),levels=1,districting=districting)
print("write : ",t,"\n")
Avro.write(io,t)
write(io,"\n")
end
close(io)
#
print("\n\n")
#
asc=Avro.schematype(typeof(t))
tType=typeof(t)
JSON3.write(asc)
io=open("mapAutoGen.avsc","w")
print("avsc: ",JSON3.write(asc),"\n")
print("type: ",tType,"\n")
write(io,JSON3.write(asc))
close(io)
# …Run Code Online (Sandbox Code Playgroud)