reifydb_core/stream/
mod.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later
3
4//! Streaming result types for async query execution.
5//!
6//! This module provides types for streaming query results instead of
7//! collecting them into `Vec<Frame>`. The primary type is `SendableFrameStream`,
8//! which is a pinned, boxed, sendable stream of frames.
9
10mod error;
11
12use std::pin::Pin;
13
14pub use error::{StreamError, StreamResult};
15use futures_util::Stream;
16
17use crate::Frame;
18
19/// Primary result type for async query execution.
20///
21/// A sendable stream of query result frames. This is the async equivalent
22/// of DataFusion's `SendableRecordBatchStream`, but uses `Frame` as the
23/// data unit instead of `RecordBatch`.
24///
25/// The stream is bounded for backpressure - producers will wait if
26/// consumers are slow.
27pub type SendableFrameStream = Pin<Box<dyn Stream<Item = StreamResult<Frame>> + Send>>;
28
29/// Configuration for streaming query execution.
30#[derive(Debug, Clone)]
31pub struct StreamConfig {
32	/// Size of the bounded channel buffer (controls backpressure).
33	/// Larger values use more memory but provide smoother throughput.
34	pub buffer_size: usize,
35
36	/// Batch size for each Frame (inherited from ExecutionContext).
37	pub batch_size: u64,
38
39	/// Optional timeout for the entire query in milliseconds.
40	pub timeout_ms: Option<u64>,
41}
42
43impl Default for StreamConfig {
44	fn default() -> Self {
45		Self {
46			buffer_size: 8,   // 8 frames in-flight
47			batch_size: 1024, // 1024 rows per batch
48			timeout_ms: None, // No timeout by default
49		}
50	}
51}
52
53/// Schema information for a frame stream.
54#[derive(Debug, Clone)]
55pub struct FrameSchema {
56	/// Column names in order.
57	pub column_names: Vec<String>,
58	/// Column types (if known statically).
59	pub column_types: Option<Vec<reifydb_type::Type>>,
60}