Skip to main content

sqlload_python_host/host/main/
transform_stream.rs

1//! Run a `transform` on rows and cross what it returns.
2
3use arrow_array::RecordBatch;
4use arrow_schema::SchemaRef;
5use sqlload::python_sources::models::TransformCall;
6use sqlload::python_sources::types::BatchStream;
7
8use crate::crossing::main::crossing_options::crossing_options;
9use crate::crossing::main::returned_batches::returned_batches;
10use crate::host::_helpers::api_version::api_version_problem;
11use crate::host::models::{PythonBatches, TransformBatches};
12
13/// What `call`'s transform (looked up in `sqlload_api`'s one registry) returns for `rows`, in `schema`, as the engine's batches, or why it can't run.
14pub fn transform_stream(
15    call: &TransformCall,
16    rows: Vec<RecordBatch>,
17    schema: SchemaRef,
18) -> Result<Box<dyn BatchStream>, String> {
19    if let Some(problem) = api_version_problem() {
20        return Err(problem);
21    }
22    let (batches, returned) = returned_batches(
23        call,
24        (rows, schema),
25        (crossing_options(), call.flatten.clone()),
26    )?;
27    Ok(Box::new(TransformBatches {
28        batches: PythonBatches(batches),
29        returned,
30    }))
31}