Skip to main content

QueryResult

Struct QueryResult 

Source
pub struct QueryResult { /* private fields */ }
Expand description

The result of a query execution.

QueryResult contains the output data from a query execution, along with metadata such as execution time and number of rows read.

§Thread Safety

QueryResult implements Send, meaning it can be safely transferred between threads.

§Examples

use chdb_rust::execute;
use chdb_rust::format::OutputFormat;
use chdb_rust::arg::Arg;

let result = execute(
    "SELECT number FROM numbers(10)",
    Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)])
)?;

// Access the data as a string
println!("Data: {}", result.data_utf8_lossy());

// Access metadata
println!("Rows read: {}", result.rows_read());
println!("Bytes read: {}", result.bytes_read());
println!("Elapsed time: {:?}", result.elapsed());

Implementations§

Source§

impl QueryResult

Source

pub fn data_utf8(&self) -> Result<String>

Get the result data as a UTF-8 string.

This method validates that the data is valid UTF-8. If the data contains invalid UTF-8 sequences, it returns an error.

§Returns

Returns a String containing the query result, or an error if the data contains invalid UTF-8 sequences.

§Examples
use chdb_rust::execute;

let result = execute("SELECT 'Hello, World!' AS greeting", None)?;
let data = result.data_utf8()?;
println!("{}", data);
§Errors

Returns Error::NonUtf8Sequence if the result data contains invalid UTF-8 sequences. Use data_utf8_lossy if you want to handle invalid UTF-8 gracefully.

Source

pub fn data_utf8_lossy(&self) -> Cow<'_, str>

Get the result data as a UTF-8 string, replacing invalid sequences.

This method converts the result data to a string, replacing any invalid UTF-8 sequences with the Unicode replacement character (U+FFFD).

§Returns

Returns a Cow<str> containing the query result. Invalid UTF-8 sequences are replaced with the replacement character.

§Examples
use chdb_rust::execute;

let result = execute("SELECT 'Hello, World!' AS greeting", None)?;
let data = result.data_utf8_lossy();
println!("{}", data);
Source

pub fn data_utf8_unchecked(&self) -> String

Get the result data as a UTF-8 string without validation.

§Safety

This function is marked as safe, but it will produce invalid UTF-8 strings if the underlying data contains non-UTF-8 bytes. Only use this if you’re certain the data is valid UTF-8, or if you’re prepared to handle potentially invalid strings.

§Examples
use chdb_rust::execute;

let result = execute("SELECT 'Hello' AS greeting", None)?;
let data = result.data_utf8_unchecked();
println!("{}", data);
Source

pub fn data_ref(&self) -> &[u8]

Get a reference to the raw result data as bytes.

This method returns a byte slice containing the raw query result data. The data is in the format specified when executing the query (e.g., JSON, CSV, etc.).

§Returns

Returns a byte slice containing the query result data. Returns an empty slice if there’s no data or if the buffer pointer is null.

§Examples
use chdb_rust::execute;

let result = execute("SELECT 1 AS value", None)?;
let bytes = result.data_ref();
println!("Data length: {} bytes", bytes.len());
Source

pub fn rows_read(&self) -> u64

Get the number of rows read by the query.

This returns the total number of rows that were read from storage during query execution.

§Returns

Returns the number of rows read as a u64.

§Examples
use chdb_rust::execute;

let result = execute("SELECT number FROM numbers(100)", None)?;
println!("Rows read: {}", result.rows_read());
Source

pub fn bytes_read(&self) -> u64

Get the number of bytes read by the query.

This returns the total number of bytes that were read from storage during query execution.

§Returns

Returns the number of bytes read as a u64.

§Examples
use chdb_rust::execute;

let result = execute("SELECT number FROM numbers(100)", None)?;
println!("Bytes read: {}", result.bytes_read());
Source

pub fn elapsed(&self) -> Duration

Get the elapsed time for query execution.

This returns the time it took to execute the query, measured from when the query was submitted until the result was ready.

§Returns

Returns a Duration representing the elapsed time.

§Examples
use chdb_rust::execute;

let result = execute("SELECT number FROM numbers(1000)", None)?;
println!("Query took: {:?}", result.elapsed());

Trait Implementations§

Source§

impl Debug for QueryResult

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for QueryResult

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for QueryResult

Auto Trait Implementations§

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, 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, 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.