Skip to main content

sqlload_python_host/host/main/
table_stream.rs

1//! Cross a table function's yields into the engine's batches.
2
3use pyo3::{Bound, PyAny};
4use sqlload::python_sources::models::TableRead;
5use sqlload::python_sources::types::BatchStream;
6
7use crate::crossing::main::crossing_options::crossing_options;
8use crate::crossing::main::table_batches::table_batches;
9use crate::host::_helpers::api_version::api_version_problem;
10use crate::host::_helpers::read_context::read_context;
11use crate::host::models::PythonBatches;
12
13/// What `iterable` (what the table function `request` reads returned or yields) yields, as the engine's batches: dicts, Arrow data, `sl.json`/`sl.ndjson`, `sl.http` jobs and `sl.checkpoint`s cross as SQLLoad's own tables' do, with the table's flatten, naming, masked columns, cursor and connections from `request`. `snapshot`, for a logged table, returns its `ctx.state` as JSON as each piece crosses. Fails when this interpreter's `sqlload_api` is not this crate's version.
14pub fn table_stream(
15    iterable: &Bound<'_, PyAny>,
16    snapshot: Option<&Bound<'_, PyAny>>,
17    request: &TableRead,
18) -> Result<Box<dyn BatchStream>, String> {
19    if let Some(problem) = api_version_problem() {
20        return Err(problem);
21    }
22    let batches = table_batches(
23        iterable,
24        snapshot,
25        crossing_options(),
26        read_context(request),
27    );
28    Ok(Box::new(PythonBatches(batches)))
29}