Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaykm committed Oct 12, 2020
1 parent d872c5e commit ae9cb66
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 228 deletions.
11 changes: 6 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include("get_parcompat.jl")
include("test_load.jl")
include("test_decode.jl")
include("test_codec.jl")
include("test_cursors.jl")
include("test_writer.jl")
@testset "parquet tests" begin
include("test_load.jl")
include("test_codec.jl")
include("test_cursors.jl")
include("test_writer.jl")
end
14 changes: 6 additions & 8 deletions test/test_codec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const decimal_encoding_testdata = [
]

function test_codec()
println("testing reading bitpacked run (old scheme)...")
@debug("testing reading bitpacked run (old scheme)")
let data = UInt8[0x05, 0x39, 0x77]
byte_width = Parquet.@bit2bytewidth(UInt8(3))
typ = Parquet.@byt2itype(byte_width)
Expand All @@ -93,9 +93,8 @@ function test_codec()
Parquet.read_bitpacked_run_old(inp, out, Int32(8), UInt8(3))
@test out.data == Int32[0:7;]
end
println("passed.")

println("testing reading bitpacked run...")
@debug("testing reading bitpacked run")
let data = UInt8[0x88, 0xc6, 0xfa]
byte_width = Parquet.@bit2bytewidth(UInt8(3))
typ = Parquet.@byt2itype(byte_width)
Expand All @@ -105,9 +104,8 @@ function test_codec()
Parquet.read_bitpacked_run(inp, out, 8, UInt8(3), byte_width)
@test out.data == Int32[0:7;]
end
println("passed.")

println("testing decimal decoding...")
@debug("testing decimal decoding")
for data in decimal_encoding_testdata
(d, f1) = Parquet.map_logical_decimal(Int32(data.precision), Int32(data.scale))
f2 = (bytes)->Parquet.logical_decimal(bytes, data.precision, data.scale)
Expand All @@ -123,8 +121,8 @@ function test_codec()
@test all(map(f3, data.byte_data) .== convert(Vector{Float64}, data.converted_data))
end
end

println("passed.")
end

test_codec()
@testset "codec" begin
test_codec()
end
57 changes: 23 additions & 34 deletions test/test_cursors.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
using Parquet
using Test

function test_col_cursor(file::String)
p = ParFile(file)
println("loaded ", file)

nr = nrows(p)
cnames = colnames(p)
for cname in cnames
rr = 1:nr
println("\tcolumn ", cname, " rows:", rr)
println("\tvalue, defn, repn, next idx")
t1 = time()
cc = Parquet.ColCursor(p, rr, cname)
num_read = 0
for (v,i) in enumerate(cc)
val,defn,repn = v
num_read += 1
end
println("\t\t", isnull(val) ? nothing : get(val), ", ", defn, ", ", repn, ", ", i)
println("\t\tread $num_read values in $(time()-t1) time")
end
end

function test_row_cursor(file::String)
p = ParFile(file)

Expand All @@ -31,10 +9,19 @@ function test_row_cursor(file::String)
cnames = colnames(p)
rc = RecordCursor(p)
rec = nothing
nread = 0
for i in rc
rec = i
nread += 1
end
@info("loaded", file, count=nr, last_record=rec, time_to_read=time()-t1)
@test nr == nread
@debug("loaded", file, count=nr, last_record=rec, time_to_read=time()-t1)

iob = IOBuffer()
show(iob, rc)
sb = take!(iob)
@test !isempty(sb)
@debug("row cursor show", file, showbuffer=String(sb))
end

function test_batchedcols_cursor(file::String)
Expand All @@ -45,18 +32,19 @@ function test_batchedcols_cursor(file::String)
cnames = colnames(p)
cc = BatchedColumnsCursor(p)
batch = nothing
nread = 0
for i in cc
batch = i
nread += length(first(batch))
end
@info("loaded", file, count=nr, ncols=length(propertynames(batch)), time_to_read=time()-t1)
end
@test nr == nread
@debug("loaded", file, count=nr, ncols=length(propertynames(batch)), time_to_read=time()-t1)

function test_col_cursor_all_files()
for encformat in ("SNAPPY", "GZIP", "NONE")
for fname in ("nation", "customer")
test_col_cursor(joinpath(@__DIR__, "parquet-compatibility", "parquet-testdata", "impala", "1.1.1-$encformat/$fname.impala.parquet"))
end
end
iob = IOBuffer()
show(iob, cc)
sb = take!(iob)
@test !isempty(sb)
@debug("batched column cursor show", file, showbuffer=String(sb))
end

function test_row_cursor_all_files()
Expand All @@ -75,6 +63,7 @@ function test_batchedcols_cursor_all_files()
end
end

#test_col_cursor_all_files()
test_row_cursor_all_files()
test_batchedcols_cursor_all_files()
@testset "cursors" begin
test_row_cursor_all_files()
test_batchedcols_cursor_all_files()
end
59 changes: 0 additions & 59 deletions test/test_decode.jl

This file was deleted.

0 comments on commit ae9cb66

Please sign in to comment.