DataHandle:count() -> integerRow count, computed from the source — see len() on in-memory batches.
In the guide: Load a table Ask with SQL Chart the answer
handle9 methods, 1 field
Opaque tabular-data handle produced by bytes:csv() and bytes:parquet(). Methods read the data when first needed or return a derived handle; a later read reuses that work rather than repeating it.
Bytes:csv, Bytes:parquetScale:fit, Scale:reset, Mark:replace_data, PlotArea:line, PlotArea:points, PlotArea:area, PlotArea:bars, PlotArea:histogram and 4 moreThe examples on this page start from:
local csv = [[
day,item,loaves
Mon,Bread,12
Mon,Buns,30
Tue,Bread,9
Tue,Buns,24
]]
local sales = datumhue.bytes(csv):csv()| Field | Type | Access | Description |
|---|---|---|---|
state | ReadyState | read-only | Completion state of this operation. Reading it never raises or suspends; a failed operation's error surfaces at :ready(). |
DataHandle:count() -> integerRow count, computed from the source — see len() on in-memory batches.
In the guide: Load a table Ask with SQL Chart the answer
DataHandle:query(sql: string, params?: any[]) -> DataHandleCreate a lazy SQL query rooted on this handle (bound as the table data). params is an array bound to ? placeholders; a Dir or File handle binds the next ? to a location inside its grant; another DataHandle binds the next ? as a table to select from or join. The query runs once, on first read.
-- In the SQL the table is called data; each ? takes the next value.
local sql = "SELECT SUM(loaves) AS total FROM data WHERE item = ?"
local buns = sales:query(sql, { "Buns" })
for _, row in buns:rows() do
print(row.total) --> 54
endIn the guide: Ask with SQL Chart the answer Query and chart data
DataHandle:rows(opts?: data.RowsOptions) -> function, table, integerStreaming row iterator (for _, row in h:rows() do). One row table per step; each step suspends until the data is available. A full pass over the source with a table allocated per row — for rendering, bind the handle to a chart mark instead of iterating.
-- A table per row, keyed by column; columns picks which to read.
for i, row in sales:rows({ columns = { "item", "loaves" } }) do
print(i, row.item, row.loaves, row.day) --> 1 Bread 12 nil
break
endopts data.RowsOptions options 1 key, 1 inherited
| Key | Type | Default | Description |
|---|---|---|---|
| From data.ColumnSelectBase | |||
| columns | string[] | every column | Column names to include. |
In the guide: Ask with SQL Query and chart data
DataHandle:batches(opts?: data.BatchesOptions) -> function, table, integerStreaming batch iterator yielding DataBatch values that expose columns directly via DataColumn — no per-row Lua table allocation. Each step suspends until the data is available.
-- Columns of up to size rows at a time; get counts from 1 in each.
local total = 0
for _, batch in sales:batches({ size = 3 }) do
local loaves = batch:column("loaves")
for i = 1, batch:len() do
total = total + loaves:get(i)
end
end
print(total) --> 75opts data.BatchesOptions options 2 keys, 1 inherited
| Key | Type | Default | Description |
|---|---|---|---|
| size | integer | each source batch whole | Rows per batch; each source batch is sliced into chunks of at most this many rows. |
| From data.ColumnSelectBase | |||
| columns | string[] | every column | Column names to include. |
In the guide: Query and chart data
DataHandle:schema() -> SchemaDescribe the columns, their types, nullability, and metadata.
local schema = sales:schema()
print(schema:len(), schema:field("loaves"):dtype()) --> 3 int64In the guide: Query and chart data
DataHandle:view(options: data.ViewOptions) -> DataViewCreate a viewport-aware, downsampled projection of this handle.
-- A mark bound to the view draws its rows downsampled to the
-- pixel budget.
local lines = { "t,v" }
for t = 1, 1000 do
lines[#lines + 1] = t .. "," .. math.sin(t / 50)
end
local wave = datumhue.bytes(table.concat(lines, "\n")):csv()
local view =
wave:view({ x_column = "t", y_column = "v", pixel_width = 100 })
print(view:range().x_max) --> 1000.0options data.ViewOptions options 10 keys, 4 inherited
| Key | Type | Default | Description |
|---|---|---|---|
| x_column required | string | no default | Column name for the x axis. |
| y_column required | string | no default | Column name for the y axis. |
| strategy | "none" | "lttb_pixel" | "stride" | "bin_2d" | "lttb_pixel" | Downsampling strategy. |
| pixel_width | number | the canvas's width, else 400 | X-axis downsampling pixel budget. |
| pixel_height | number | the canvas's height, else 300 | Y-axis downsampling pixel budget. |
| canvas | DrawCanvas | the budget comes from pixel_width and pixel_height alone | Draw canvas to size the pixel budget from. |
| From data.RangeBounds | |||
| x_min | number | string | "auto" | Lower x bound: a number, or "auto" to fit the data. |
| x_max | number | string | "auto" | Upper x bound: a number, or "auto". |
| y_min | number | string | "auto" | Lower y bound: a number, or "auto". |
| y_max | number | string | "auto" | Upper y bound: a number, or "auto". |
DataHandle:encode_csv() -> BytesSerialize the handle's contents as CSV, returning a Bytes userdata.
local tuesday =
sales:query("SELECT item, loaves FROM data WHERE day = 'Tue'")
local encoded = tuesday:encode_csv()
print(encoded:text()) --> item,loaves Bread,9 Buns,24In the guide: Query and chart data
DataHandle:encode_parquet() -> BytesSerialize the handle's contents as Parquet, returning a Bytes userdata.
In the guide: Query and chart data
DataHandle:ready() -> DataHandleWait until this asset is fully loaded, then return it for chaining. An in-memory asset returns at once; one still loading (a file read or remote fetch) yields the coroutine until it lands. A load failure raises; format errors on playable assets still surface at use time.
-- A query runs when first read; ready runs it now, and raises if it
-- fails.
local typo = sales:query("SELECT loaf FROM data")
print(typo.state) --> pending
local ok = pcall(function()
typo:ready()
end)
print(ok, typo.state) --> false failedoptions 1 key
| Key | Type | Default | Description |
|---|---|---|---|
| columns | string[] | every column | Column names to include. |
Extended by: data.BatchesOptions, data.RowsOptions
| Value | Description |
|---|---|
"none" | |
"lttb_pixel" | |
"stride" | |
"bin_2d" |
Nested in: data.ViewOptions
options 4 keys
| Key | Type | Default | Description |
|---|---|---|---|
| x_min | number | string | "auto" | Lower x bound: a number, or "auto" to fit the data. |
| x_max | number | string | "auto" | Upper x bound: a number, or "auto". |
| y_min | number | string | "auto" | Lower y bound: a number, or "auto". |
| y_max | number | string | "auto" | Upper y bound: a number, or "auto". |
Extended by: data.SetRangeOptions, data.ViewOptions