global: snapshot

This commit is contained in:
nym21
2025-11-10 13:18:41 +01:00
parent f6a2a0540b
commit 37f5f50867
50 changed files with 1550 additions and 334 deletions
+2 -2
View File
@@ -53,14 +53,14 @@ impl AsyncQuery {
// metric: &str,
// index: Index,
// // params: &Params,
// ) -> Result<Vec<(String, &&dyn AnyCollectableVec)>> {
// ) -> Result<Vec<(String, &&dyn AnyWritableVec)>> {
// let query = self.0.clone();
// spawn_blocking(move || query.search_metric_with_index(metric, index)).await?
// }
// pub async fn format(
// &self,
// metrics: Vec<(String, &&dyn AnyCollectableVec)>,
// metrics: Vec<(String, &&dyn AnyWritableVec)>,
// params: &ParamsOpt,
// ) -> Result<Output> {
// let query = self.0.clone();
+20 -16
View File
@@ -11,7 +11,7 @@ use brk_types::{
Address, AddressStats, Format, Height, Index, IndexInfo, Limit, Metric, MetricCount,
Transaction, TxidPath,
};
use vecdb::{AnyCollectableVec, AnyStoredVec};
use vecdb::{AnyStoredVec, AnyWritableVec};
mod r#async;
mod chain;
@@ -77,7 +77,7 @@ impl Query {
metric: &str,
index: Index,
// params: &Params,
) -> Result<Vec<(String, &&dyn AnyCollectableVec)>> {
) -> Result<Vec<(String, &&dyn AnyWritableVec)>> {
todo!();
// let all_metrics = &self.vecs.metrics;
@@ -121,7 +121,7 @@ impl Query {
}
fn columns_to_csv(
columns: &[&&dyn AnyCollectableVec],
columns: &[&&dyn AnyWritableVec],
from: Option<i64>,
to: Option<i64>,
) -> Result<String> {
@@ -144,23 +144,31 @@ impl Query {
}
csv.push('\n');
let mut iters: Vec<_> = columns
// Create one writer per column
let mut writers: Vec<_> = columns
.iter()
.map(|col| col.iter_range_strings(from, to))
.map(|col| col.create_writer(from, to))
.collect();
for _ in 0..num_rows {
for (index, iter) in iters.iter_mut().enumerate() {
for (index, writer) in writers.iter_mut().enumerate() {
if index > 0 {
csv.push(',');
}
if let Some(field) = iter.next() {
if field.contains(',') {
// Check if we need CSV escaping
let start_pos = csv.len();
if writer.write_next(&mut csv)? {
let end_pos = csv.len();
// If contains comma, rewrite with quotes
if csv[start_pos..end_pos].contains(',') {
let value = csv[start_pos..end_pos].to_string(); // Only allocate if needed
csv.truncate(start_pos);
csv.push('"');
csv.push_str(&field);
csv.push_str(&value);
csv.push('"');
} else {
csv.push_str(&field);
}
}
}
@@ -170,11 +178,7 @@ impl Query {
Ok(csv)
}
pub fn format(
&self,
metrics: Vec<&&dyn AnyCollectableVec>,
params: &ParamsOpt,
) -> Result<Output> {
pub fn format(&self, metrics: Vec<&&dyn AnyWritableVec>, params: &ParamsOpt) -> Result<Output> {
let from = params.from().map(|from| {
metrics
.iter()
+6 -6
View File
@@ -6,7 +6,7 @@ use brk_traversable::{Traversable, TreeNode};
use brk_types::{Index, IndexInfo, Limit, Metric};
use derive_deref::{Deref, DerefMut};
use quickmatch::{QuickMatch, QuickMatchConfig};
use vecdb::AnyCollectableVec;
use vecdb::AnyWritableVec;
use crate::pagination::{PaginatedIndexParam, PaginatedMetrics, PaginationParam};
@@ -31,11 +31,11 @@ impl<'a> Vecs<'a> {
indexer
.vecs
.iter_any_collectable()
.iter_any_writable()
.for_each(|vec| this.insert(vec));
computer
.iter_any_collectable()
.iter_any_writable()
.for_each(|vec| this.insert(vec));
let mut ids = this
@@ -108,7 +108,7 @@ impl<'a> Vecs<'a> {
}
// Not the most performant or type safe but only built once so that's okay
fn insert(&mut self, vec: &'a dyn AnyCollectableVec) {
fn insert(&mut self, vec: &'a dyn AnyWritableVec) {
let name = vec.name();
let serialized_index = vec.index_type_to_string();
let index = Index::try_from(serialized_index)
@@ -181,7 +181,7 @@ impl<'a> Vecs<'a> {
}
#[derive(Default, Deref, DerefMut)]
pub struct IndexToVec<'a>(BTreeMap<Index, &'a dyn AnyCollectableVec>);
pub struct IndexToVec<'a>(BTreeMap<Index, &'a dyn AnyWritableVec>);
#[derive(Default, Deref, DerefMut)]
pub struct MetricToVec<'a>(BTreeMap<&'a str, &'a dyn AnyCollectableVec>);
pub struct MetricToVec<'a>(BTreeMap<&'a str, &'a dyn AnyWritableVec>);