Skip to main content

ArrowReader

Struct ArrowReader 

Source
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:

  1. A schema message
  2. 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>

Source

pub fn new(connection: &'conn Connection) -> Self

Creates a new Arrow reader for the given connection.

Source

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::Other if the connection is using gRPC transport (ArrowReader wraps COPY TO STDOUT, which is TCP-only).
  • Returns crate::Error::Client if the server rejects the COPY (<query>) TO STDOUT WITH (format arrowstream) statement.
  • Returns crate::Error::Io on transport-level I/O failures.
Source

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.

Source

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 name
  • columns - 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.

Source

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 name
  • where_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§

Source§

impl<'conn> Debug for ArrowReader<'conn>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more