pub struct ArrowReader<'conn> { /* private fields */ }Expand description
Reads query results in Arrow IPC stream format.
ArrowReader provides methods to execute queries and receive results as
Arrow IPC stream data. This is useful for integration with Arrow-based
data processing pipelines.
§How It Works
Internally, ArrowReader uses COPY (SELECT ...) TO STDOUT WITH (format arrowstream)
to retrieve query results in Arrow format. The returned bytes are a valid
Arrow IPC stream containing:
- A schema message
- One or more record batch messages
§Example
use hyperdb_api::{ArrowReader, Connection, CreateMode, Result};
fn main() -> Result<()> {
let conn = Connection::connect("localhost:7483", "test.hyper", CreateMode::CreateIfNotExists)?;
// Create and populate a table
conn.execute_command("CREATE TABLE data (id INT, value DOUBLE PRECISION)")?;
conn.execute_command("INSERT INTO data VALUES (1, 1.5), (2, 2.5), (3, 3.5)")?;
// Read the table as Arrow
let reader = ArrowReader::new(&conn);
let arrow_data = reader.table_to_arrow("data")?;
println!("Got {} bytes of Arrow IPC data", arrow_data.len());
Ok(())
}Implementations§
Source§impl<'conn> ArrowReader<'conn>
impl<'conn> ArrowReader<'conn>
Sourcepub fn new(connection: &'conn Connection) -> Self
pub fn new(connection: &'conn Connection) -> Self
Creates a new Arrow reader for the given connection.
Sourcepub fn query_to_arrow(&self, select_query: &str) -> Result<Vec<u8>>
pub fn query_to_arrow(&self, select_query: &str) -> Result<Vec<u8>>
Executes a SELECT query and returns results as Arrow IPC stream.
The query should be a SELECT statement. It will be wrapped in a
COPY (...) TO STDOUT WITH (format arrowstream) to retrieve the
results in Arrow format.
§Arguments
select_query- A SELECT query (without COPY wrapper)
§Returns
Raw Arrow IPC stream bytes that can be parsed by Arrow libraries.
§Example
let reader = ArrowReader::new(&conn);
let arrow_data = reader.query_to_arrow("SELECT id, name FROM users WHERE active = true")?;§Errors
- Returns
crate::Error::Otherif the connection is using gRPC transport (ArrowReader wrapsCOPY TO STDOUT, which is TCP-only). - Returns
crate::Error::Clientif the server rejects theCOPY (<query>) TO STDOUT WITH (format arrowstream)statement. - Returns
crate::Error::Ioon transport-level I/O failures.
Sourcepub fn table_to_arrow(&self, table_name: &str) -> Result<Vec<u8>>
pub fn table_to_arrow(&self, table_name: &str) -> Result<Vec<u8>>
Exports an entire table to Arrow IPC stream format.
This is equivalent to query_to_arrow("SELECT * FROM table_name").
§Arguments
table_name- The table name (should be properly escaped if needed)
§Returns
Raw Arrow IPC stream bytes containing all rows from the table.
§Example
let reader = ArrowReader::new(&conn);
let arrow_data = reader.table_to_arrow("my_table")?;§Errors
See query_to_arrow.
Sourcepub fn table_columns_to_arrow(
&self,
table_name: &str,
columns: &[&str],
) -> Result<Vec<u8>>
pub fn table_columns_to_arrow( &self, table_name: &str, columns: &[&str], ) -> Result<Vec<u8>>
Exports specific columns from a table to Arrow IPC stream format.
§Arguments
table_name- The table namecolumns- Column names to export
§Returns
Raw Arrow IPC stream bytes containing the specified columns.
§Example
let reader = ArrowReader::new(&conn);
let arrow_data = reader.table_columns_to_arrow("users", &["id", "name", "email"])?;§Errors
See query_to_arrow.
Sourcepub fn table_filtered_to_arrow(
&self,
table_name: &str,
where_clause: &str,
) -> Result<Vec<u8>>
pub fn table_filtered_to_arrow( &self, table_name: &str, where_clause: &str, ) -> Result<Vec<u8>>
Exports a table with a WHERE clause to Arrow IPC stream format.
§Arguments
table_name- The table namewhere_clause- The WHERE clause (without the “WHERE” keyword)
§Returns
Raw Arrow IPC stream bytes containing filtered rows.
§Example
let reader = ArrowReader::new(&conn);
let arrow_data = reader.table_filtered_to_arrow("users", "active = true")?;§Errors
See query_to_arrow.
Trait Implementations§
Auto Trait Implementations§
impl<'conn> Freeze for ArrowReader<'conn>
impl<'conn> !RefUnwindSafe for ArrowReader<'conn>
impl<'conn> Send for ArrowReader<'conn>
impl<'conn> Sync for ArrowReader<'conn>
impl<'conn> Unpin for ArrowReader<'conn>
impl<'conn> UnsafeUnpin for ArrowReader<'conn>
impl<'conn> !UnwindSafe for ArrowReader<'conn>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request