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

Avoid ambiguity between user-provided UInt64 column type and PosLen #787

Merged
merged 1 commit into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ end

## lazy strings
# bit patterns for missing value, int value, escaped string, position and len in lazy string parsing
const PosLen = UInt64

# primitive type PosLen 64 end
# PosLen(x::UInt64) = Core.bitcast(PosLen, x)
# UInt64(x::PosLen) = Core.bitcast(UInt64, x)
primitive type PosLen 64 end
PosLen(x::UInt64) = Core.bitcast(PosLen, x)
UInt64(x::PosLen) = Core.bitcast(UInt64, x)

Base.convert(::Type{PosLen}, x::UInt64) = PosLen(x)
Base.convert(::Type{UInt64}, x::PosLen) = UInt64(x)

const MISSING_BIT = 0x8000000000000000
missingvalue(x) = (UInt64(x) & MISSING_BIT) == MISSING_BIT
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end

buffer = b"heytheresailoresc\\\"aped"
e = UInt8('\\')
poslens = [
poslens = CSV.PosLen[
CSV.poslen(Int16(0), Int64(1), Int64(3)),
CSV.poslen(Int16(0), Int64(4), Int64(5)),
CSV.poslen(Int16(0), Int64(9), Int64(6)),
Expand All @@ -66,10 +66,10 @@ end
@test isequal(x, ["hey", "there", "sailor", "esc\"aped", missing])

poslens = ChainedVector([
[CSV.poslen(Int16(0), Int64(1), Int64(3))],
[CSV.poslen(Int16(0), Int64(4), Int64(5))],
[CSV.poslen(Int16(0), Int64(9), Int64(6))],
[CSV.poslen(Parsers.ESCAPED_STRING, Int64(15), Int64(8))]
CSV.PosLen[CSV.poslen(Int16(0), Int64(1), Int64(3))],
CSV.PosLen[CSV.poslen(Int16(0), Int64(4), Int64(5))],
CSV.PosLen[CSV.poslen(Int16(0), Int64(9), Int64(6))],
CSV.PosLen[CSV.poslen(Parsers.ESCAPED_STRING, Int64(15), Int64(8))]
])
x = CSV.LazyStringVector{String}(buffer, e, poslens)
@test x == ["hey", "there", "sailor", "esc\"aped"]
Expand Down