Skip to content

Commit

Permalink
support Legolas.Row (de)serialization as an Arrow column element (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels authored Jul 27, 2021
1 parent 28cbb27 commit f40368a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "Legolas"
uuid = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
authors = ["Beacon Biosignals, Inc."]
version = "0.2.1"
version = "0.2.2"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Arrow = "1.5"
Arrow = "1.6.2"
DataFrames = "1"
Tables = "1.4"
julia = "1.3"
Expand Down
16 changes: 16 additions & 0 deletions src/rows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,19 @@ macro row(schema_expr, fields...)
Legolas.Row{$schema_type}
end
end

# Support (de)serialization as an Arrow column value via Arrow.ArrowTypes overloads.
#
# Note that this only really works in relatively simple cases; rely on this at your own peril.
# See https://github.com/JuliaData/Arrow.jl/issues/230 for more details.
#
# Note also that the limited support here that DOES work participates in SemVer,
# e.g. if we break this in future Legolas versions we should treat it as a breaking
# change and bump version numbers accordingly.

const LEGOLAS_ROW_ARROW_NAME = Symbol("JuliaLang.Legolas.Row")
Arrow.ArrowTypes.arrowname(::Type{<:Legolas.Row}) = LEGOLAS_ROW_ARROW_NAME
Arrow.ArrowTypes.ArrowType(::Type{Legolas.Row{_,F}}) where {_,F} = Tuple{String,Int,F}
Arrow.ArrowTypes.toarrow(row::Legolas.Row{S}) where {S} = (String(Legolas.schema_name(S)), Legolas.schema_version(S), getfield(row, :fields))
Arrow.ArrowTypes.JuliaType(::Val{LEGOLAS_ROW_ARROW_NAME}, ::Any) = Legolas.Row
Arrow.ArrowTypes.fromarrow(::Type{<:Legolas.Row}, name, version, fields) = Legolas.Row(Legolas.Schema(name, version), fields)
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ end
@test r[1] === 3
@test string(r) == "Row(Schema(\"bar@1\"), (z = 3, x = 1, y = 2))"

tbl = Arrow.Table(Arrow.tobuffer((x=[r],)))
@test r === tbl.x[1]

long_row = Row(Schema("bar", 1), (x=1, y=2, z=zeros(100, 100)))
@test length(sprint(show, long_row; context=(:limit => true))) < 200
Expand Down

2 comments on commit f40368a

@jrevels
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/41607

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" f40368a8773852e65ea69811d4b138b3c65a505e
git push origin v0.2.2

Please sign in to comment.