Skip to content

Commit

Permalink
Avoid ambiguity between user-provided UInt64 column type and PosLen
Browse files Browse the repository at this point in the history
Fixes #785 and alternative solution to #786. As opposed to the solution
in that PR, which caused other issues, in this PR, we change from
defining `const PosLen = UInt64` to `primitive type PosLen 64 end` and
define a few helper conversions. This makes `PosLen` its own proper
type, and avoids the dispatch ambiguity of the original issue.
  • Loading branch information
quinnj committed Nov 22, 2020
1 parent b57715f commit 7da816c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit 7da816c

Please sign in to comment.