Skip to content

Adding first, last and describe convenience functions. #42

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/DTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using Tables:
materializer,
partitioner,
rows,
rowtable,
schema,
Schema

Expand Down
20 changes: 20 additions & 0 deletions src/table/dtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ function length(table::DTable)
return sum(chunk_lengths(table))
end

function first(table::DTable, rows::UInt)
if nrow(table) == 0
return table
end

chunk_length = maximum(chunk_lengths(table))
num_full_chunks = Int(floor(rows / chunk_length)) # number of required chunks
sink = materializer(table.tabletype)
if num_full_chunks * chunk_length == rows
required_chunks = table.chunks[1:num_full_chunks]
else
# take only the needed rows from extra chunk
needed_rows = rows - num_full_chunks * chunk_length
extra_chunk = table.chunks[num_full_chunks + 1]
new_chunk = Dagger.@spawn sink(rowtable(fetch(extra_chunk))[1:needed_rows])
required_chunks = vcat(table.chunks[1:num_full_chunks], [new_chunk])
end
return DTable(required_chunks, table.tabletype)
end

function columnnames_svector(d::DTable)
colnames_tuple = determine_columnnames(d)
return colnames_tuple !== nothing ? [sym for sym in colnames_tuple] : nothing
Expand Down