Skip to content

Commit

Permalink
update metadata, remove custom count aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Dec 6, 2024
1 parent ec35930 commit d29fe8a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 469 deletions.
12 changes: 0 additions & 12 deletions crates/mongodb-agent-common/src/aggregation_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use enum_iterator::{all, Sequence};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Sequence)]
pub enum AggregationFunction {
Avg,
Count,
Min,
Max,
Sum,
Expand All @@ -17,7 +16,6 @@ impl AggregationFunction {
pub fn graphql_name(self) -> &'static str {
match self {
A::Avg => "avg",
A::Count => "count",
A::Min => "min",
A::Max => "max",
A::Sum => "sum",
Expand All @@ -31,14 +29,4 @@ impl AggregationFunction {
aggregate_function: s.to_owned().into(),
})
}

pub fn is_count(self) -> bool {
match self {
A::Avg => false,
A::Count => true,
A::Min => false,
A::Max => false,
A::Sum => false,
}
}
}
22 changes: 1 addition & 21 deletions crates/mongodb-agent-common/src/query/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn facet_pipelines_for_query(
let aggregate_selections: bson::Document = aggregates
.iter()
.flatten()
.map(|(key, aggregate)| {
.map(|(key, _)| {
// The facet result for each aggregate is an array containing a single document which
// has a field called `result`. This code selects each facet result by name, and pulls
// out the `result` value.
Expand All @@ -202,17 +202,6 @@ fn facet_pipelines_for_query(
null,
]
};

// Matching SQL semantics, if a **count** aggregation does not match any rows we want
// to return zero. Other aggregations should return null.
let value_expr = if is_count(aggregate) {
doc! {
"$ifNull": [value_expr, 0],
}
} else {
value_expr
};

(key.to_string(), value_expr.into())
})
.collect();
Expand All @@ -238,14 +227,6 @@ fn facet_pipelines_for_query(
Ok((facet_pipelines, selection))
}

fn is_count(aggregate: &Aggregate) -> bool {
match aggregate {
Aggregate::ColumnCount { .. } => true,
Aggregate::StarCount { .. } => true,
Aggregate::SingleColumn { function, .. } => function.is_count(),
}
}

fn pipeline_for_aggregate(
aggregate: Aggregate,
limit: Option<u32>,
Expand Down Expand Up @@ -332,7 +313,6 @@ fn pipeline_for_aggregate(

let accumulator = match function {
Avg => Accumulator::Avg(field_ref),
Count => Accumulator::Count,
Min => Accumulator::Min(field_ref),
Max => Accumulator::Max(field_ref),
Sum => Accumulator::Sum(field_ref),
Expand Down
27 changes: 12 additions & 15 deletions crates/mongodb-agent-common/src/scalar_types_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn extended_json_scalar_type() -> (ndc_models::ScalarTypeName, ScalarType) {
let name = aggregation_function.graphql_name().into();
let result_type = match aggregation_function {
AggregationFunction::Avg => ext_json_type.clone(),
AggregationFunction::Count => bson_to_named_type(S::Int),
AggregationFunction::Min => ext_json_type.clone(),
AggregationFunction::Max => ext_json_type.clone(),
AggregationFunction::Sum => ext_json_type.clone(),
Expand Down Expand Up @@ -150,20 +149,18 @@ fn bson_to_named_type(bson_scalar_type: BsonScalarType) -> Type {
pub fn aggregate_functions(
scalar_type: BsonScalarType,
) -> impl Iterator<Item = (AggregationFunction, BsonScalarType)> {
[(A::Count, S::Int)]
.into_iter()
.chain(iter_if(
scalar_type.is_orderable(),
[A::Min, A::Max]
.into_iter()
.map(move |op| (op, scalar_type)),
))
.chain(iter_if(
scalar_type.is_numeric(),
[A::Avg, A::Sum]
.into_iter()
.map(move |op| (op, scalar_type)),
))
iter_if(
scalar_type.is_orderable(),
[A::Min, A::Max]
.into_iter()
.map(move |op| (op, scalar_type)),
)
.chain(iter_if(
scalar_type.is_numeric(),
[A::Avg, A::Sum]
.into_iter()
.map(move |op| (op, scalar_type)),
))
}

pub fn comparison_operators(
Expand Down
13 changes: 7 additions & 6 deletions fixtures/hasura/app/metadata/chinook-types.hml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ definition:
aggregatedType: ObjectId_1
aggregationFunctions:
- name: count
returnType: Int!
returnType: Int
dataConnectorAggregationFunctionMapping:
- dataConnectorName: chinook
dataConnectorScalarType: ObjectId
Expand Down Expand Up @@ -152,15 +152,15 @@ definition:
aggregatedType: Decimal
aggregationFunctions:
- name: avg
returnType: Decimal!
returnType: Decimal
- name: count
returnType: Int!
returnType: Int
- name: max
returnType: Decimal!
returnType: Decimal
- name: min
returnType: Decimal!
returnType: Decimal
- name: sum
returnType: Decimal!
returnType: Decimal
dataConnectorAggregationFunctionMapping:
- dataConnectorName: chinook
dataConnectorScalarType: Decimal
Expand Down Expand Up @@ -191,3 +191,4 @@ definition:
representation: Double
graphql:
comparisonExpressionTypeName: DoubleComparisonExp

Loading

0 comments on commit d29fe8a

Please sign in to comment.