1use super::{
2 Statement,
3 arrow::{datatypes::SchemaRef, record_batch::RecordBatch},
4};
5
6#[must_use = "Arrow is lazy and will do nothing unless consumed"]
17pub struct Arrow<'stmt> {
18 pub(crate) stmt: Option<&'stmt Statement<'stmt>>,
19}
20
21#[allow(clippy::needless_lifetimes)]
22impl<'stmt> Arrow<'stmt> {
23 #[inline]
24 pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Self {
25 Arrow { stmt: Some(stmt) }
26 }
27
28 #[inline]
30 pub fn get_schema(&self) -> SchemaRef {
31 self.stmt
32 .expect("Arrow iterator always holds a statement")
33 .stmt
34 .schema()
35 }
36}
37
38#[allow(clippy::needless_lifetimes)]
39impl<'stmt> Iterator for Arrow<'stmt> {
40 type Item = RecordBatch;
41
42 fn next(&mut self) -> Option<Self::Item> {
43 match self.stmt?.step() {
44 Ok(Some(array)) => Some(RecordBatch::from(&array)),
45 Ok(None) => None,
46 Err(err) => panic!("Failed to fetch Arrow record batch: {err}"),
47 }
48 }
49}
50
51pub type ArrowStream<'stmt> = Arrow<'stmt>;