-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support all comparison and aggregation functions on extended json fie…
…lds (#99) Since Extended JSON fields may contain any data users may reasonably want access to all comparison and aggregation operations. MongoDB is designed to accommodate functions that don't make sense on all values they are applied to. I included a native query that produces a collection of mixed data types, and some integration tests on that data. I also updated the dev shell to pull the cli from the [nix flake](https://github.com/hasura/ddn-cli-nix) that @TheInnerLight helpfully set up.
- Loading branch information
Showing
19 changed files
with
835 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use insta::assert_yaml_snapshot; | ||
|
||
use crate::graphql_query; | ||
|
||
#[tokio::test] | ||
async fn filters_on_extended_json_using_string_comparison() -> anyhow::Result<()> { | ||
// Skip this test in MongoDB 5 because the example fails there. We're getting an error: | ||
// | ||
// > Kind: Command failed: Error code 5491300 (Location5491300): $documents' is not allowed in user requests, labels: {} | ||
// | ||
// This doesn't affect native queries that don't use the $documents stage. | ||
if let Ok(image) = std::env::var("MONGODB_IMAGE") { | ||
if image == "mongo:5" { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
assert_yaml_snapshot!( | ||
graphql_query( | ||
r#" | ||
query Filtering { | ||
extendedJsonTestData(where: { value: { _regex: "hello" } }) { | ||
type | ||
value | ||
} | ||
} | ||
"# | ||
) | ||
.run() | ||
.await? | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...__tests__aggregation__aggregates_extended_json_representing_mixture_of_numeric_types.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
source: crates/integration-tests/src/tests/aggregation.rs | ||
expression: "graphql_query(r#\"\n query ($types: String!) {\n extendedJsonTestDataAggregate(\n filter_input: { where: { type: { _regex: $types } } }\n ) {\n value {\n _avg\n _count\n _max\n _min\n _sum\n _count_distinct\n }\n }\n extendedJsonTestData(where: { type: { _regex: $types } }) {\n type\n value\n }\n }\n \"#).variables(json!({\n \"types\": \"decimal|double|int|long\"\n })).run().await?" | ||
--- | ||
data: | ||
extendedJsonTestDataAggregate: | ||
value: | ||
_avg: | ||
$numberDecimal: "4.5" | ||
_count: 8 | ||
_max: | ||
$numberLong: "8" | ||
_min: | ||
$numberDecimal: "1" | ||
_sum: | ||
$numberDecimal: "36" | ||
_count_distinct: 8 | ||
extendedJsonTestData: | ||
- type: decimal | ||
value: | ||
$numberDecimal: "1" | ||
- type: decimal | ||
value: | ||
$numberDecimal: "2" | ||
- type: double | ||
value: | ||
$numberDouble: "3.0" | ||
- type: double | ||
value: | ||
$numberDouble: "4.0" | ||
- type: int | ||
value: | ||
$numberInt: "5" | ||
- type: int | ||
value: | ||
$numberInt: "6" | ||
- type: long | ||
value: | ||
$numberLong: "7" | ||
- type: long | ||
value: | ||
$numberLong: "8" | ||
errors: ~ |
27 changes: 27 additions & 0 deletions
27
...integration_tests__tests__aggregation__aggregates_mixture_of_numeric_and_null_values.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
source: crates/integration-tests/src/tests/aggregation.rs | ||
expression: "graphql_query(r#\"\n query ($types: String!) {\n extendedJsonTestDataAggregate(\n filter_input: { where: { type: { _regex: $types } } }\n ) {\n value {\n _avg\n _count\n _max\n _min\n _sum\n _count_distinct\n }\n }\n extendedJsonTestData(where: { type: { _regex: $types } }) {\n type\n value\n }\n }\n \"#).variables(json!({\n \"types\": \"double|null\"\n })).run().await?" | ||
--- | ||
data: | ||
extendedJsonTestDataAggregate: | ||
value: | ||
_avg: | ||
$numberDouble: "3.5" | ||
_count: 2 | ||
_max: | ||
$numberDouble: "4.0" | ||
_min: | ||
$numberDouble: "3.0" | ||
_sum: | ||
$numberDouble: "7.0" | ||
_count_distinct: 2 | ||
extendedJsonTestData: | ||
- type: double | ||
value: | ||
$numberDouble: "3.0" | ||
- type: double | ||
value: | ||
$numberDouble: "4.0" | ||
- type: "null" | ||
value: ~ | ||
errors: ~ |
9 changes: 9 additions & 0 deletions
9
...ntegration_tests__tests__filtering__filters_on_extended_json_using_string_comparison.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
source: crates/integration-tests/src/tests/filtering.rs | ||
expression: "graphql_query(r#\"\n query Filtering {\n extendedJsonTestData(where: { value: { _regex: \"hello\" } }) {\n type\n value\n }\n }\n \"#).variables(json!({\n \"types\": \"double|null\"\n })).run().await?" | ||
--- | ||
data: | ||
extendedJsonTestData: | ||
- type: string | ||
value: "hello, world!" | ||
errors: ~ |
45 changes: 45 additions & 0 deletions
45
...-tests/src/tests/snapshots/integration_tests__tests__sorting__sorts_on_extended_json.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
source: crates/integration-tests/src/tests/sorting.rs | ||
expression: "graphql_query(r#\"\n query Sorting {\n extendedJsonTestData(order_by: { value: Desc }) {\n type\n value\n }\n }\n \"#).run().await?" | ||
--- | ||
data: | ||
extendedJsonTestData: | ||
- type: date | ||
value: | ||
$date: | ||
$numberLong: "1724164680000" | ||
- type: date | ||
value: | ||
$date: | ||
$numberLong: "1637571600000" | ||
- type: string | ||
value: "hello, world!" | ||
- type: string | ||
value: foo | ||
- type: long | ||
value: | ||
$numberLong: "8" | ||
- type: long | ||
value: | ||
$numberLong: "7" | ||
- type: int | ||
value: | ||
$numberInt: "6" | ||
- type: int | ||
value: | ||
$numberInt: "5" | ||
- type: double | ||
value: | ||
$numberDouble: "4.0" | ||
- type: double | ||
value: | ||
$numberDouble: "3.0" | ||
- type: decimal | ||
value: | ||
$numberDecimal: "2" | ||
- type: decimal | ||
value: | ||
$numberDecimal: "1" | ||
- type: "null" | ||
value: ~ | ||
errors: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use insta::assert_yaml_snapshot; | ||
|
||
use crate::graphql_query; | ||
|
||
#[tokio::test] | ||
async fn sorts_on_extended_json() -> anyhow::Result<()> { | ||
// Skip this test in MongoDB 5 because the example fails there. We're getting an error: | ||
// | ||
// > Kind: Command failed: Error code 5491300 (Location5491300): $documents' is not allowed in user requests, labels: {} | ||
// | ||
// This doesn't affect native queries that don't use the $documents stage. | ||
if let Ok(image) = std::env::var("MONGODB_IMAGE") { | ||
if image == "mongo:5" { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
assert_yaml_snapshot!( | ||
graphql_query( | ||
r#" | ||
query Sorting { | ||
extendedJsonTestData(order_by: { value: Desc }) { | ||
type | ||
value | ||
} | ||
} | ||
"# | ||
) | ||
.run() | ||
.await? | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.