Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable S3Paths to be (de)serialized to/from Arrow #231

Merged
merged 10 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "AWSS3"
uuid = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
version = "0.9.3"
version = "0.9.4"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -20,6 +21,7 @@ XMLDict = "228000da-037f-5747-90a9-8195ccbf91a5"

[compat]
AWS = "1.63.1"
ArrowTypes = "1.2"
Compat = "3.29.0"
EzXML = "0.9, 1"
FilePathsBase = "0.9.11"
Expand All @@ -35,9 +37,10 @@ XMLDict = "0.3, 0.4"
julia = "1.3"

[extras]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "JSON3", "Minio"]
test = ["Test", "Arrow", "JSON3", "Minio"]
1 change: 1 addition & 0 deletions src/AWSS3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export S3Path,

using AWS
using AWS.AWSServices: s3
using ArrowTypes
using FilePathsBase
using FilePathsBase: /, join
using HTTP
Expand Down
13 changes: 13 additions & 0 deletions src/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,16 @@ function FilePathsBase.mktmpdir(parent::S3Path)
fp = parent / string(uuid4(), "/")
return mkdir(fp)
end

const S3PATH_ARROW_NAME = Symbol("JuliaLang.AWSS3.S3Path")
ArrowTypes.arrowname(::Type{<:S3Path}) = S3PATH_ARROW_NAME
ArrowTypes.ArrowType(::Type{<:S3Path}) = String
ArrowTypes.JuliaType(::Val{S3PATH_ARROW_NAME}, ::Any) = S3Path
ArrowTypes.fromarrow(::Type{<:S3Path}, uri_string) = S3Path(uri_string)

function ArrowTypes.toarrow(path::S3Path)
if !isnothing(path.config)
throw(ArgumentError("`S3Path` config must be `nothing` to serialize to Arrow"))
end
return string(path)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using AWS
using AWS.AWSExceptions: AWSException
using AWS.AWSServices: s3
using AWSS3
using Arrow
using Test
using Dates
using Retry
Expand Down
13 changes: 13 additions & 0 deletions test/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ function s3path_tests(config)
rm(json_path)
end

@testset "Arrow <-> S3Path (de)serialization" begin
ver = String('A':'Z') * String('0':'5')
paths = [
jrevels marked this conversation as resolved.
Show resolved Hide resolved
S3Path("s3://$(bucket_name)/a"),
S3Path("s3://$(bucket_name)/b?versionId=$ver"),
# format trick: using this comment to force use of multiple lines
]
tbl = Arrow.Table(Arrow.tobuffer((; paths=paths)))
@test all(tbl.paths .== paths)
push!(paths, S3Path("s3://$(bucket_name)/c"; config=config))
@test_throws Arrow.tobuffer((; paths=paths)) ArgumentError
jrevels marked this conversation as resolved.
Show resolved Hide resolved
omus marked this conversation as resolved.
Show resolved Hide resolved
end

@testset "tryparse" begin
cfg = global_aws_config()
ver = String('A':'Z') * String('0':'5')
Expand Down