Skip to content

Commit

Permalink
use the predicate in PathElement (#81)
Browse files Browse the repository at this point in the history
### What

We haven't been using the `predicate` in the
[PathElement](https://hasura.github.io/ndc-spec/reference/types.html#pathelement).
This is no good. We need to use it so we don't produce incorrect results
to users.

### How

We generate a boolean Expression for the predicates using the relevant
tables and we `AND` the resulting Expression with the join predicate in
the `WHERE` clause.
  • Loading branch information
Gil Mizrahi authored Oct 19, 2023
1 parent 4cd5ee8 commit 8faaebb
Show file tree
Hide file tree
Showing 31 changed files with 1,290 additions and 137 deletions.
31 changes: 31 additions & 0 deletions crates/connectors/ndc-citus/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,37 @@ mod sorting {
.await;
insta::assert_json_snapshot!(result);
}
#[tokio::test]
async fn sorting_by_nested_relationship_column_with_predicate() {
let result = run_query(
create_router().await,
"sorting_by_nested_relationship_column_with_predicate",
)
.await;
insta::assert_json_snapshot!(result);
}

// Citus sorts strings differently than PostgreSQL,
// so the 5th row might be different.
#[tokio::test]
async fn sorting_by_nested_relationship_column_with_predicate_exists() {
let result = run_query(
create_router().await,
"sorting_by_nested_relationship_column_with_predicate_exists",
)
.await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn sorting_by_relationship_count_with_predicate() {
let result = run_query(
create_router().await,
"sorting_by_relationship_count_with_predicate",
)
.await;
insta::assert_json_snapshot!(result);
}
}

mod aggregation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/connectors/ndc-citus/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Crazy Train"
},
{
"Name": "I Don't Know"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/connectors/ndc-citus/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Balls to the Wall"
},
{
"Name": "Fast As a Shark"
},
{
"Name": "Princess of the Dawn"
},
{
"Name": "Restless and Wild"
},
{
"Name": "\"?\""
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/connectors/ndc-citus/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Iron Maiden"
},
{
"Name": "Metallica"
},
{
"Name": "U2"
},
{
"Name": "Led Zeppelin"
},
{
"Name": "Deep Purple"
}
]
}
]
16 changes: 16 additions & 0 deletions crates/connectors/ndc-cockroach/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ mod sorting {
.await;
insta::assert_json_snapshot!(result);
}

// CockroachDB has the opposite default for nulls ordering than PostgreSQL,
// making the test I've written return random results
// (since most tracks are not by Accept, nulls are returned
// first, and we limit the number of results,
// we are not going to get the same result here),
// so we skip the two other sorting with predicate tests.
#[tokio::test]
async fn sorting_by_relationship_count_with_predicate() {
let result = run_query(
create_router().await,
"sorting_by_relationship_count_with_predicate",
)
.await;
insta::assert_json_snapshot!(result);
}
}

mod aggregation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/connectors/ndc-cockroach/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Iron Maiden"
},
{
"Name": "Metallica"
},
{
"Name": "U2"
},
{
"Name": "Led Zeppelin"
},
{
"Name": "Deep Purple"
}
]
}
]
30 changes: 30 additions & 0 deletions crates/connectors/ndc-postgres/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,36 @@ mod sorting {
.await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn sorting_by_nested_relationship_column_with_predicate() {
let result = run_query(
create_router().await,
"sorting_by_nested_relationship_column_with_predicate",
)
.await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn sorting_by_nested_relationship_column_with_predicate_exists() {
let result = run_query(
create_router().await,
"sorting_by_nested_relationship_column_with_predicate_exists",
)
.await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn sorting_by_relationship_count_with_predicate() {
let result = run_query(
create_router().await,
"sorting_by_relationship_count_with_predicate",
)
.await;
insta::assert_json_snapshot!(result);
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/connectors/ndc-postgres/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Crazy Train"
},
{
"Name": "I Don't Know"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/connectors/ndc-postgres/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Balls to the Wall"
},
{
"Name": "Fast As a Shark"
},
{
"Name": "Princess of the Dawn"
},
{
"Name": "Restless and Wild"
},
{
"Name": "\"40\""
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: crates/connectors/ndc-postgres/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Name": "Iron Maiden"
},
{
"Name": "Metallica"
},
{
"Name": "U2"
},
{
"Name": "Led Zeppelin"
},
{
"Name": "Deep Purple"
}
]
}
]
Loading

0 comments on commit 8faaebb

Please sign in to comment.