use crate::ArrowChunk;
use anyhow::{anyhow, Result};
use arrow2::datatypes::SchemaRef;
#[derive(Debug, Clone)]
pub struct QueryResponseData {
pub blocks: Vec<ArrowBatch>,
pub transactions: Vec<ArrowBatch>,
pub logs: Vec<ArrowBatch>,
}
#[derive(Debug, Clone)]
pub struct QueryResponse {
pub archive_height: Option<u64>,
pub next_block: u64,
pub total_execution_time: u64,
pub data: QueryResponseData,
}
#[derive(Debug, Clone)]
pub struct ArrowBatch {
pub chunk: ArrowChunk,
pub schema: SchemaRef,
}
impl ArrowBatch {
pub fn column<T: 'static>(&self, name: &str) -> Result<&T> {
match self
.schema
.fields
.iter()
.enumerate()
.find(|(_, f)| f.name == name)
{
Some((idx, _)) => {
let col = self.chunk.columns()[idx]
.as_any()
.downcast_ref::<T>()
.unwrap();
Ok(col)
}
None => Err(anyhow!("field {} not found in schema", name)),
}
}
}