Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into gil/explain
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Feb 2, 2024
2 parents 9a7d2a6 + cbaf924 commit 266e8f7
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 76 deletions.
10 changes: 0 additions & 10 deletions ndc-client/src/apis/default_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub async fn capabilities_get(
let tracer = global::tracer("engine");
tracer
.in_span("capabilities_get", |ctx| async {
let configuration = configuration;

let client = &configuration.client;

let uri = append_path(&configuration.base_path, "capabilities")
Expand Down Expand Up @@ -91,8 +89,6 @@ pub async fn explain_post(
let tracer = global::tracer("engine");
tracer
.in_span("explain_post", |ctx| async {
let configuration = configuration;

let client = &configuration.client;

let uri = append_path(&configuration.base_path, "explain")
Expand Down Expand Up @@ -132,8 +128,6 @@ pub async fn mutation_post(
let tracer = global::tracer("engine");
tracer
.in_span("mutation_post", |ctx| async {
let configuration = configuration;

let client = &configuration.client;

let uri = append_path(&configuration.base_path, "mutation")
Expand Down Expand Up @@ -174,8 +168,6 @@ pub async fn query_post(
tracer
.in_span("query_post", |ctx| {
async {
let configuration = configuration;

let client = &configuration.client;

let uri = append_path(&configuration.base_path, "query")
Expand Down Expand Up @@ -217,8 +209,6 @@ pub async fn schema_get(
let tracer = global::tracer("engine");
tracer
.in_span("schema_get", |ctx| async {
let configuration = configuration;

let client = &configuration.client;

let uri = append_path(&configuration.base_path, "schema")
Expand Down
7 changes: 2 additions & 5 deletions ndc-client/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ pub struct Query {
/// Optionally offset from the Nth result
pub offset: Option<u32>,
pub order_by: Option<OrderBy>,
#[serde(rename = "where")]
pub predicate: Option<Expression>,
}
// ANCHOR_END: Query
Expand Down Expand Up @@ -453,8 +452,7 @@ pub enum Expression {
},
Exists {
in_collection: ExistsInCollection,
#[serde(rename = "where")]
predicate: Box<Expression>,
predicate: Option<Box<Expression>>,
},
}
// ANCHOR_END: Expression
Expand Down Expand Up @@ -499,8 +497,7 @@ pub struct PathElement {
/// Values to be provided to any collection arguments
pub arguments: BTreeMap<String, RelationshipArgument>,
/// A predicate expression to apply to the target collection
#[serde(rename = "where")]
pub predicate: Box<Expression>,
pub predicate: Option<Box<Expression>>,
}
// ANCHOR_END: PathElement

Expand Down
26 changes: 17 additions & 9 deletions ndc-client/tests/json_schema/mutation_request.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
}
]
},
"where": {
"predicate": {
"anyOf": [
{
"$ref": "#/definitions/Expression"
Expand Down Expand Up @@ -379,8 +379,7 @@
"type": "object",
"required": [
"arguments",
"relationship",
"where"
"relationship"
],
"properties": {
"relationship": {
Expand All @@ -394,11 +393,14 @@
"$ref": "#/definitions/RelationshipArgument"
}
},
"where": {
"predicate": {
"description": "A predicate expression to apply to the target collection",
"allOf": [
"anyOf": [
{
"$ref": "#/definitions/Expression"
},
{
"type": "null"
}
]
}
Expand Down Expand Up @@ -578,8 +580,7 @@
"type": "object",
"required": [
"in_collection",
"type",
"where"
"type"
],
"properties": {
"type": {
Expand All @@ -591,8 +592,15 @@
"in_collection": {
"$ref": "#/definitions/ExistsInCollection"
},
"where": {
"$ref": "#/definitions/Expression"
"predicate": {
"anyOf": [
{
"$ref": "#/definitions/Expression"
},
{
"type": "null"
}
]
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions ndc-client/tests/json_schema/query_request.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
}
]
},
"where": {
"predicate": {
"anyOf": [
{
"$ref": "#/definitions/Expression"
Expand Down Expand Up @@ -424,8 +424,7 @@
"type": "object",
"required": [
"arguments",
"relationship",
"where"
"relationship"
],
"properties": {
"relationship": {
Expand All @@ -439,11 +438,14 @@
"$ref": "#/definitions/RelationshipArgument"
}
},
"where": {
"predicate": {
"description": "A predicate expression to apply to the target collection",
"allOf": [
"anyOf": [
{
"$ref": "#/definitions/Expression"
},
{
"type": "null"
}
]
}
Expand Down Expand Up @@ -564,8 +566,7 @@
"type": "object",
"required": [
"in_collection",
"type",
"where"
"type"
],
"properties": {
"type": {
Expand All @@ -577,8 +578,15 @@
"in_collection": {
"$ref": "#/definitions/ExistsInCollection"
},
"where": {
"$ref": "#/definitions/Expression"
"predicate": {
"anyOf": [
{
"$ref": "#/definitions/Expression"
},
{
"type": "null"
}
]
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions ndc-reference/bin/reference/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ fn eval_path_element(
relationship: &models::Relationship,
arguments: &BTreeMap<String, models::RelationshipArgument>,
source: &[Row],
predicate: &models::Expression,
predicate: &Option<Box<models::Expression>>,
) -> Result<Vec<Row>> {
let mut matching_rows: Vec<Row> = vec![];

Expand Down Expand Up @@ -1077,14 +1077,18 @@ fn eval_path_element(

for tgt_row in target.iter() {
if eval_column_mapping(relationship, src_row, tgt_row)?
&& eval_expression(
collection_relationships,
variables,
state,
predicate,
tgt_row,
tgt_row,
)?
&& if let Some(expression) = predicate {
eval_expression(
collection_relationships,
variables,
state,
expression,
tgt_row,
tgt_row,
)?
} else {
true
}
{
matching_rows.push(tgt_row.clone());
}
Expand Down Expand Up @@ -1342,7 +1346,7 @@ fn eval_expression(
limit: None,
offset: None,
order_by: None,
predicate: Some(*predicate.clone()),
predicate: predicate.clone().map(|e| *e),
};
let collection = eval_in_collection(
collection_relationships,
Expand Down Expand Up @@ -1399,9 +1403,7 @@ fn eval_in_collection(
relationship,
arguments,
&source,
&models::Expression::And {
expressions: vec![],
},
&None
)
}
models::ExistsInCollection::Unrelated {
Expand Down Expand Up @@ -1522,9 +1524,7 @@ fn eval_field(
relationship,
arguments,
&source,
&models::Expression::And {
expressions: vec![],
},
&None
)?;
let rows = execute_query(
collection_relationships,
Expand Down
2 changes: 1 addition & 1 deletion ndc-reference/tests/query/order_by_aggregate/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{
"arguments": {},
"relationship": "author_articles",
"where": {
"predicate": {
"type": "and",
"expressions": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"arguments": {},
"relationship": "author_articles",
"where": {
"predicate": {
"type": "and",
"expressions": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"type": "star_count"
}
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand All @@ -48,7 +48,7 @@
{
"arguments": {},
"relationship": "author_articles",
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand Down
4 changes: 2 additions & 2 deletions ndc-reference/tests/query/order_by_relationship/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{
"arguments": {},
"relationship": "article_author",
"where": {
"predicate": {
"type": "and",
"expressions": []
}
Expand All @@ -57,7 +57,7 @@
{
"arguments": {},
"relationship": "article_author",
"where": {
"predicate": {
"type": "and",
"expressions": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
}
}
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
"name": "title",
"path": [{
"arguments": {},
"relationship": "author_articles",
"where": {
"predicate": {
"type": "and",
"expressions": []
}
Expand Down
2 changes: 1 addition & 1 deletion ndc-reference/tests/query/predicate_with_eq/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"column": "title"
}
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand Down
4 changes: 2 additions & 2 deletions ndc-reference/tests/query/predicate_with_exists/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
}
}
},
"where": {
"predicate": {
"type": "exists",
"in_collection": {
"type": "related",
"arguments": {},
"relationship": "author_articles"
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand Down
2 changes: 1 addition & 1 deletion ndc-reference/tests/query/predicate_with_in/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"column": "title"
}
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand Down
2 changes: 1 addition & 1 deletion ndc-reference/tests/query/predicate_with_like/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"column": "title"
}
},
"where": {
"predicate": {
"type": "binary_comparison_operator",
"column": {
"type": "column",
Expand Down
Loading

0 comments on commit 266e8f7

Please sign in to comment.