pub struct AggregationProjector;Expand description
Aggregation result projector
Implementations§
Source§impl AggregationProjector
impl AggregationProjector
Sourcepub fn project(
rows: Vec<HashMap<String, Value>>,
_plan: &AggregationPlan,
) -> Result<Value>
pub fn project( rows: Vec<HashMap<String, Value>>, _plan: &AggregationPlan, ) -> Result<Value>
Project SQL aggregate results to GraphQL JSON.
§Arguments
rows- SQL result rows asHashMapsplan- Aggregation execution plan (for metadata)
§Returns
GraphQL-compatible JSON response
§Errors
Currently infallible; reserved for future extension (e.g., type coercion failures).
§Example
// Requires: an AggregationPlan built from compiled schema metadata.
// See: tests/integration/ for runnable examples.
use std::collections::HashMap;
use serde_json::{json, Value};
let mut row = HashMap::new();
row.insert("category".to_string(), json!("Electronics"));
row.insert("count".to_string(), json!(42));
row.insert("revenue_sum".to_string(), json!(5280.50));
let rows = vec![row];
// let result = AggregationProjector::project(rows, &plan)?;
// result: [{"category": "Electronics", "count": 42, "revenue_sum": 5280.50}]§Errors
Returns FraiseQLError::Internal if JSON serialization of the projected
rows fails (should not occur for well-formed input).
Sourcepub fn wrap_in_data_envelope(projected: Value, query_name: &str) -> Value
pub fn wrap_in_data_envelope(projected: Value, query_name: &str) -> Value
Wrap projected results in GraphQL data envelope.
§Arguments
projected- Projected result arrayquery_name- GraphQL query field name (e.g., “sales_aggregate”)
§Returns
Complete GraphQL response with {"data": {...}} wrapper
§Example
let projected = json!([{"count": 42}]);
let response = AggregationProjector::wrap_in_data_envelope(projected, "sales_aggregate");
// response: {"data": {"sales_aggregate": [{"count": 42}]}}
assert!(response.get("data").is_some());Sourcepub fn project_single(
row: HashMap<String, Value>,
_plan: &AggregationPlan,
) -> Result<Value>
pub fn project_single( row: HashMap<String, Value>, _plan: &AggregationPlan, ) -> Result<Value>
Project a single aggregate result (no GROUP BY).
When there’s no GROUP BY, the result is a single object, not an array.
§Errors
Currently infallible; reserved for future extension (e.g., type coercion failures).
§Example
// Requires: an AggregationPlan built from compiled schema metadata.
// See: tests/integration/ for runnable examples.
use std::collections::HashMap;
use serde_json::json;
let mut row = HashMap::new();
row.insert("count".to_string(), json!(100));
row.insert("revenue_sum".to_string(), json!(5000.0));
// let result = AggregationProjector::project_single(row, &plan)?;
// result: {"count": 100, "revenue_sum": 5000.0}Auto Trait Implementations§
impl Freeze for AggregationProjector
impl RefUnwindSafe for AggregationProjector
impl Send for AggregationProjector
impl Sync for AggregationProjector
impl Unpin for AggregationProjector
impl UnsafeUnpin for AggregationProjector
impl UnwindSafe for AggregationProjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more