Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krynju committed Aug 14, 2022
1 parent caf9351 commit de93a0e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/table/dtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ mutable struct DTable
chunks::VTYPE
tabletype
schema::Union{Nothing,Tables.Schema}
DTable(chunks::VTYPE, tabletype) = new(chunks, tabletype, nothing)
end

DTable(chunks::Vector{Dagger.EagerThunk}, args...) = DTable(VTYPE(chunks), args...)
DTable(chunks::Vector{Dagger.Chunk}, args...) = DTable(VTYPE(chunks), args...)
DTable(chunks::Vector, tabletype) = DTable(VTYPE(chunks), tabletype, nothing)
DTable(chunks::Vector, tabletype, schema) = DTable(VTYPE(chunks), tabletype, schema)



"""
DTable(table; tabletype=nothing) -> DTable
Expand Down
20 changes: 14 additions & 6 deletions src/table/dtable_column.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ function getcolumn_chunk(chunk_contents, col::Int)
end

function DTableColumn(d::DTable, col::Int)
column_eltype = Tables.schema(Tables.columns(d)).types[col]
iterator_type = fetch(Dagger.spawn(
(ch, _col) -> typeof(iterate(getcolumn_chunk(ch, _col))),
d.chunks[1],
col
))
schema = Tables.schema(Tables.columns(d))

column_eltype = schema.types[col]

iterator_type = Nothing
c_idx = 1
while iterator_type === Nothing && c_idx <= nchunks(d)
iterator_type = fetch(Dagger.spawn(
(ch, _col) -> typeof(iterate(getcolumn_chunk(ch, _col))),
d.chunks[c_idx],
col
))
c_idx += 1
end

DTableColumn{column_eltype,iterator_type}(
d,
Expand Down
2 changes: 1 addition & 1 deletion src/table/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function filter(f, d::DTable)
m = TableOperations.filter(_f, _chunk)
Tables.materializer(_chunk)(m)
end
DTable(map(c -> Dagger.spawn(chunk_wrap, c, f), d.chunks), d.tabletype)
DTable(map(c -> Dagger.spawn(chunk_wrap, c, f), d.chunks), d.tabletype, d.schema)
end


Expand Down
19 changes: 16 additions & 3 deletions test/column.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
@testset "DTableColumn" begin
col_a = collect(1:100_000).%10_000
col_b = rand(100_000)
S = 10_000
col_a = collect(1:S)
col_b = rand(S)
nt = (a=col_a, b=col_b)
d = DTable(nt, 10_000)
d = DTable(nt, S ÷ 10)

@test collect(DTableColumn(d, 1)) == col_a
@test collect(DTableColumn(d, "a")) == col_a
@test collect(DTableColumn(d, :a)) == col_a
@test collect(DTableColumn(d, 2)) == col_b
@test collect(DTableColumn(d, "b")) == col_b
@test collect(DTableColumn(d, :b)) == col_b

d2 = filter(x -> x.a <= S / 2, d)
@test collect(DTableColumn(d2, 1)) == col_a[1:Int(S / 2)]
@test collect(DTableColumn(d2, 2)) == col_b[1:Int(S / 2)]

d2 = filter(x -> x.a >= S / 2, d)
@test collect(DTableColumn(d2, 1)) == col_a[Int(S / 2):end]
@test collect(DTableColumn(d2, 2)) == col_b[Int(S / 2):end]

d2 = filter(x -> x.a < 0, d)
@test collect(DTableColumn(d2, 1)) == col_a[1:-1]
@test collect(DTableColumn(d2, 2)) == col_b[1:-1]
end

0 comments on commit de93a0e

Please sign in to comment.