Skip to content

Commit

Permalink
[NSP-12] New meanings for comparison and aggregate operators (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 authored Oct 30, 2024
1 parent c80bda7 commit 21941c9
Show file tree
Hide file tree
Showing 13 changed files with 803 additions and 133 deletions.
27 changes: 24 additions & 3 deletions ndc-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ pub enum Type {
pub enum ComparisonOperatorDefinition {
Equal,
In,
LessThan,
LessThanOrEqual,
GreaterThan,
GreaterThanOrEqual,
Custom {
/// The type of the argument to this operator
argument_type: Type,
Expand All @@ -350,10 +354,27 @@ pub enum ComparisonOperatorDefinition {
// ANCHOR: AggregateFunctionDefinition
/// The definition of an aggregation function on a scalar type
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
#[schemars(title = "Aggregate Function Definition")]
pub struct AggregateFunctionDefinition {
/// The scalar or object type of the result of this function
pub result_type: Type,
pub enum AggregateFunctionDefinition {
Min,
Max,
Sum {
/// The scalar type of the result of this function, which should have
/// one of the type representations Int64 or Float64, depending on
/// whether this function is defined on a scalar type with an integer or
/// floating-point representation, respectively.
result_type: ScalarTypeName,
},
Average {
/// The scalar type of the result of this function, which should have
/// the type representation Float64
result_type: ScalarTypeName,
},
Custom {
/// The scalar or object type of the result of this function
result_type: Type,
},
}
// ANCHOR_END: AggregateFunctionDefinition

Expand Down
157 changes: 145 additions & 12 deletions ndc-models/tests/json_schema/schema_response.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,97 @@
"AggregateFunctionDefinition": {
"title": "Aggregate Function Definition",
"description": "The definition of an aggregation function on a scalar type",
"type": "object",
"required": [
"result_type"
],
"properties": {
"result_type": {
"description": "The scalar or object type of the result of this function",
"allOf": [
{
"$ref": "#/definitions/Type"
"oneOf": [
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"min"
]
}
]
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"max"
]
}
}
},
{
"type": "object",
"required": [
"result_type",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"sum"
]
},
"result_type": {
"description": "The scalar type of the result of this function, which should have one of the type representations Int64 or Float64, depending on whether this function is defined on a scalar type with an integer or floating-point representation, respectively.",
"type": "string"
}
}
},
{
"type": "object",
"required": [
"result_type",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"average"
]
},
"result_type": {
"description": "The scalar type of the result of this function, which should have the type representation Float64",
"type": "string"
}
}
},
{
"type": "object",
"required": [
"result_type",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"custom"
]
},
"result_type": {
"description": "The scalar or object type of the result of this function",
"allOf": [
{
"$ref": "#/definitions/Type"
}
]
}
}
}
}
]
},
"Type": {
"title": "Type",
Expand Down Expand Up @@ -534,6 +611,62 @@
}
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"less_than"
]
}
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"less_than_or_equal"
]
}
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"greater_than"
]
}
}
},
{
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"greater_than_or_equal"
]
}
}
},
{
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit 21941c9

Please sign in to comment.