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
impl QueryResult
Sourcepub fn data_utf8(&self) -> Result<String>
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.
Sourcepub fn data_utf8_lossy(&self) -> Cow<'_, str>
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);Sourcepub fn data_utf8_unchecked(&self) -> String
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);Sourcepub fn data_ref(&self) -> &[u8] ⓘ
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());Sourcepub fn rows_read(&self) -> u64
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());Sourcepub fn bytes_read(&self) -> u64
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());Sourcepub fn elapsed(&self) -> Duration
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());