Skip to content

Commit

Permalink
Merge pull request #787 from JuliaData/jq/785.take2
Browse files Browse the repository at this point in the history
Avoid ambiguity between user-provided UInt64 column type and PosLen
  • Loading branch information
quinnj authored Nov 22, 2020
2 parents b57715f + 7da816c commit 00261df
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 00261df

Please sign in to comment.