beacon-biosignals/Legolas.jl

Issue with nested arrow serialization

ericphanson opened this issue · 0 comments

julia> using Legolas, Test

julia> using Legolas: @row

julia> const MyInnerRow = @row("my-inner-schema@1", b::Int=1)
Legolas.Row{Legolas.Schema{Symbol("my-inner-schema"), 1}}

julia> const MyOuterRow = @row("my-outer-schema@1",
                               a::String,
                               x::MyInnerRow=MyInnerRow(x))
Legolas.Row{Legolas.Schema{Symbol("my-outer-schema"), 1}}

julia> @testset "Nested arrow serialization" begin
           table = [MyOuterRow(; a="outer_a", x = MyInnerRow())]
           roundtripped_table = Legolas.read(Legolas.tobuffer(table, Legolas.Schema("my-outer-schema@1")))
           @test table == MyOuterRow.(Tables.rows(roundtripped_table))
       end
┌ Warning: provided table's `Tables.Schema` does not appear to match provided `Legolas.Schema`. Run `[Legolas.Row(Schema("my-outer-schema@1"), r) for r in Tables.rows(t)]` to try converting the table `t` to a compatible representation.
└ @ Legolas ~/.julia/packages/Legolas/G6pxI/src/tables.jl:48
Nested arrow serialization: Error During Test at REPL[10]:1
  Got exception outside of a @test
  ArgumentError: field `x` has unexpected type; expected <:Legolas.Row{Legolas.Schema{Symbol("my-inner-schema"), 1}}, found Legolas.Row
  Stacktrace:
    [1] validate_expected_field(schema::Tables.Schema{(:a, :x), Tuple{String, Legolas.Row}}, name::Symbol, #unused#::Type{Legolas.Row{Legolas.Schema{Symbol("my-inner-schema"), 1}}})
      @ Legolas ~/.julia/packages/Legolas/G6pxI/src/rows.jl:170
    [2] _validate
      @ ~/.julia/packages/Legolas/G6pxI/src/rows.jl:302 [inlined]
    [3] validate(tables_schema::Tables.Schema{(:a, :x), Tuple{String, Legolas.Row}}, legolas_schema::Legolas.Schema{Symbol("my-outer-schema"), 1})
      @ Main ~/.julia/packages/Legolas/G6pxI/src/rows.jl:313
    [4] validate(table::Arrow.Table, legolas_schema::Legolas.Schema{Symbol("my-outer-schema"), 1})
      @ Legolas ~/.julia/packages/Legolas/G6pxI/src/tables.jl:46
    [5] validate(table::Arrow.Table)
      @ Legolas ~/.julia/packages/Legolas/G6pxI/src/tables.jl:71
    [6] #read#17
      @ ~/.julia/packages/Legolas/G6pxI/src/tables.jl:89 [inlined]
    [7] read(io_or_path::IOBuffer)
      @ Legolas ~/.julia/packages/Legolas/G6pxI/src/tables.jl:88
    [8] macro expansion
      @ REPL[10]:3 [inlined]
    [9] macro expansion
      @ ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/Test/src/Test.jl:1283 [inlined]
   [10] top-level scope
      @ REPL[10]:2
   [11] eval
      @ ./boot.jl:373 [inlined]
   [12] eval_user_input(ast::Any, backend::REPL.REPLBackend)
      @ REPL ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150
   [13] repl_backend_loop(backend::REPL.REPLBackend)
      @ REPL ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/REPL/src/REPL.jl:246
   [14] start_repl_backend(backend::REPL.REPLBackend, consumer::Any)
      @ REPL ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/REPL/src/REPL.jl:231
   [15] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool)
      @ REPL ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/REPL/src/REPL.jl:364
   [16] run_repl(repl::REPL.AbstractREPL, consumer::Any)
      @ REPL ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/stdlib/v1.7/REPL/src/REPL.jl:351
   [17] (::Base.var"#930#932"{Bool, Bool, Bool})(REPL::Module)
      @ Base ./client.jl:394
   [18] #invokelatest#2
      @ ./essentials.jl:716 [inlined]
   [19] invokelatest
      @ ./essentials.jl:714 [inlined]
   [20] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
      @ Base ./client.jl:379
   [21] exec_options(opts::Base.JLOptions)
      @ Base ./client.jl:309
   [22] _start()
      @ Base ./client.jl:495
Test Summary:              | Error  Total
Nested arrow serialization |     1      1
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

Note that this is a separate issue from

julia> roundtripped_table = Tables.rowtable(Arrow.Table(Arrow.tobuffer(table)))
ERROR: MethodError: no method matching zero(::Type{NamedTuple{(:a, :b, :c)}})

reported in #16 (review)