sqlload_python_host/crossing/main/
table_batches.rs1use std::sync::Arc;
4use std::sync::mpsc::sync_channel;
5
6use arrow_schema::Schema;
7use pyo3::{Bound, PyAny};
8
9use crate::crossing::_helpers::parser::start_parsers;
10use crate::crossing::_helpers::producer::produce;
11use crate::crossing::models::{
12 ByteBudget, CrossingOptions, CrossingStats, ReadContext, TableBatches,
13};
14
15pub fn table_batches(
17 iterable: &Bound<'_, PyAny>,
18 snapshot: Option<&Bound<'_, PyAny>>,
19 options: CrossingOptions,
20 context: ReadContext,
21) -> TableBatches {
22 let (batch_sender, batch_receiver) = sync_channel(0);
23 let stats = Arc::new(CrossingStats {
24 budget: ByteBudget::new(options.max_queued_bytes),
25 ..CrossingStats::default()
26 });
27 let dispatch = start_parsers(options, batch_sender, &stats, context);
28 let source = iterable.clone().unbind();
29 let snapshot = snapshot.map(|snapshot| snapshot.clone().unbind());
30 let producer_stats = stats.clone();
31 std::thread::spawn(move || produce((source, snapshot), options, dispatch, producer_stats));
32 TableBatches {
33 receiver: batch_receiver,
34 schema: Schema::empty(),
35 stats,
36 finished: false,
37 }
38}