sqlload-python-host 0.87.0

The Python host of SQLLoad's engine: runs Python tables and crosses what they yield into the engine, for a pyo3 extension of your own.
Documentation
//! Start reading a table generator into Arrow.

use std::sync::Arc;
use std::sync::mpsc::sync_channel;

use arrow_schema::Schema;
use pyo3::{Bound, PyAny};

use crate::crossing::_helpers::parser::start_parsers;
use crate::crossing::_helpers::producer::produce;
use crate::crossing::models::{
    ByteBudget, CrossingOptions, CrossingStats, ReadContext, TableBatches,
};

/// Read `iterable` (a table function's generator) on a background thread (calling `snapshot`, when given, for `ctx.state` as each piece crosses), batching dict yields, and parse what it yields into Arrow on others, expanding the objects `context` lists to flatten and running `sl.http` jobs with its connections; at most `options.max_queued + options.parse_threads` batches wait between them and the consumer, so the generator pauses when the consumer falls behind.
pub fn table_batches(
    iterable: &Bound<'_, PyAny>,
    snapshot: Option<&Bound<'_, PyAny>>,
    options: CrossingOptions,
    context: ReadContext,
) -> TableBatches {
    let (batch_sender, batch_receiver) = sync_channel(0);
    let stats = Arc::new(CrossingStats {
        budget: ByteBudget::new(options.max_queued_bytes),
        ..CrossingStats::default()
    });
    let dispatch = start_parsers(options, batch_sender, &stats, context);
    let source = iterable.clone().unbind();
    let snapshot = snapshot.map(|snapshot| snapshot.clone().unbind());
    let producer_stats = stats.clone();
    std::thread::spawn(move || produce((source, snapshot), options, dispatch, producer_stats));
    TableBatches {
        receiver: batch_receiver,
        schema: Schema::empty(),
        stats,
        finished: false,
    }
}