chronix_query/lib.rs
1//! # chronix-query
2//!
3//! Query engine for the Chronix time-series database.
4//!
5//! This crate implements the full query pipeline:
6//!
7//! 1. **Planning** — [`QueryPlan`] and [`QueryBuilder`] for fluent query construction
8//! 2. **Pruning** — Multi-level segment elimination (time, bloom, stats)
9//! 3. **Projection** — Read only the columns needed by the query
10//! 4. **Filtering** — Vectorized predicate evaluation on Arrow arrays
11//! 5. **Deduplication** — Sort-merge dedup for overlapping segments
12//! 6. **Aggregation** — count, sum, min, max, avg, first, last
13//! 7. **Downsampling** — Time-bucket aggregation
14//! 8. **Window functions** — row_number, rank, lead, lag, delta, rate, irate,
15//! moving average, cumulative sum, increase
16//!
17//! All results are returned as Apache Arrow `RecordBatch` for zero-copy
18//! interoperability with data processing ecosystems.
19
20#![warn(missing_docs)]
21#![deny(unsafe_code)]
22#![allow(clippy::module_name_repetitions)]
23
24pub mod aggregate;
25pub mod convert;
26pub mod dedup;
27pub mod downsample;
28pub mod encoded_pushdown;
29pub mod error;
30pub mod filter;
31pub mod memory;
32pub mod plan;
33pub mod pruning;
34pub mod window;
35
36pub use aggregate::AggFn;
37pub use convert::points_to_record_batch;
38pub use encoded_pushdown::{ColumnPredicate, EncodedDomainEvaluator, RowGroupVerdict};
39pub use error::QueryError;
40pub use memory::MemoryTracker;
41pub use plan::{FieldPredicate, QueryBuilder, QueryPlan, ZoneMapOp};
42pub use window::WindowFn;
43
44/// Consolidated Arrow column → `f64` extraction.
45///
46/// Supports `Float64Array`, `Int64Array`, and `UInt64Array`. Returns
47/// `None` for null values or unsupported types.
48pub fn extract_f64(col: &dyn arrow::array::Array, index: usize) -> Option<f64> {
49 use arrow::array::{Float64Array, Int64Array, UInt64Array};
50 if col.is_null(index) {
51 return None;
52 }
53 col.as_any()
54 .downcast_ref::<Float64Array>()
55 .map(|a| a.value(index))
56 .or_else(|| {
57 col.as_any()
58 .downcast_ref::<Int64Array>()
59 .map(|a| a.value(index) as f64)
60 })
61 .or_else(|| {
62 col.as_any()
63 .downcast_ref::<UInt64Array>()
64 .map(|a| a.value(index) as f64)
65 })
66}