-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow combinations of keys of different types to make batching l…
…ogic consistent with single queries
- Loading branch information
1 parent
5e70d19
commit b4cf0f3
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batching/mod.rs
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod select_one_compound; | ||
mod select_one_singular; | ||
mod select_with_diff_key_types; | ||
mod transactional_batch; |
180 changes: 180 additions & 0 deletions
180
...ector-test-kit-rs/query-engine-tests/tests/queries/batching/select_with_diff_key_types.rs
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,180 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schema))] | ||
mod select_different_key_type { | ||
use indoc::indoc; | ||
use query_engine_tests::{Runner, TestResult}; | ||
|
||
fn schema() -> String { | ||
let schema = indoc! { | ||
r#" | ||
model FloatEntity { | ||
Id Float @id | ||
Text String | ||
} | ||
model BigIntEntity { | ||
Id BigInt @id | ||
Text String | ||
} | ||
model DecimalEntity { | ||
Id Decimal @id | ||
Text String | ||
} | ||
model DateEntity { | ||
Id DateTime @id | ||
Text String | ||
} | ||
"# | ||
}; | ||
|
||
schema.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn batch_of_two_distinct(runner: Runner) -> TestResult<()> { | ||
create_test_data(&runner).await?; | ||
|
||
// These pairs of queries are run as batched and non-batched to verify that the | ||
// batching logic returns the same results as the non-batched logic. | ||
// The reason this is valuable is that the batching logic, unlike regular queries | ||
// relies on a comparison operation implemented in our code, which is sensitive | ||
// to differences in types of values. | ||
let pairs = [ | ||
( | ||
r#"query { findUniqueFloatEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueFloatEntity(where: { Id: 2 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueBigIntEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueBigIntEntity(where: { Id: 2 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueDecimalEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueDecimalEntity(where: { Id: 2 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueDateEntity(where: { Id: "2020-01-01T00:00:00Z" }){ Text }}"#, | ||
r#"query { findUniqueDateEntity(where: { Id: "2020-01-02T00:00:00Z" }){ Text }}"#, | ||
), | ||
]; | ||
|
||
for (query_a, query_b) in pairs { | ||
let batch = runner | ||
.batch(vec![query_a.to_owned(), query_b.to_owned()], false, None) | ||
.await? | ||
.into_data(); | ||
let (single_a, single_b) = futures::try_join!(runner.query(query_a), runner.query(query_b),)?; | ||
|
||
assert_eq!(batch.len(), 2, "{batch:?}"); | ||
assert_eq!( | ||
batch, | ||
single_a | ||
.into_data() | ||
.into_iter() | ||
.chain(single_b.into_data()) | ||
.collect::<Vec<_>>() | ||
); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn batch_of_two_repeated(runner: Runner) -> TestResult<()> { | ||
create_test_data(&runner).await?; | ||
|
||
// Same as above, but with just one row repeated twice in each batch. | ||
let pairs = [ | ||
( | ||
r#"query { findUniqueFloatEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueFloatEntity(where: { Id: 1 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueBigIntEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueBigIntEntity(where: { Id: 1 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueDecimalEntity(where: { Id: 1 }){ Text }}"#, | ||
r#"query { findUniqueDecimalEntity(where: { Id: 1 }){ Text }}"#, | ||
), | ||
( | ||
r#"query { findUniqueDateEntity(where: { Id: "2020-01-01T00:00:00Z" }){ Text }}"#, | ||
r#"query { findUniqueDateEntity(where: { Id: "2020-01-01T00:00:00Z" }){ Text }}"#, | ||
), | ||
]; | ||
|
||
for (query_a, query_b) in pairs { | ||
let batch = runner | ||
.batch(vec![query_a.to_owned(), query_b.to_owned()], false, None) | ||
.await? | ||
.into_data(); | ||
let (single_a, single_b) = futures::try_join!(runner.query(query_a), runner.query(query_b),)?; | ||
|
||
assert_eq!(batch.len(), 2, "{batch:?}"); | ||
assert_eq!( | ||
batch, | ||
single_a | ||
.into_data() | ||
.into_iter() | ||
.chain(single_b.into_data()) | ||
.collect::<Vec<_>>() | ||
); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn create_test_data(runner: &Runner) -> TestResult<()> { | ||
let mutations = [ | ||
r#"mutation entity { | ||
createOneFloatEntity(data: { Id: 1, Text: "A" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneFloatEntity(data: { Id: 2, Text: "B" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneBigIntEntity(data: { Id: 1, Text: "A" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneBigIntEntity(data: { Id: 2, Text: "B" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneDecimalEntity(data: { Id: 1, Text: "A" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneDecimalEntity(data: { Id: 2, Text: "B" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneDateEntity(data: { Id: "2020-01-01T00:00:00Z", Text: "A" }) { | ||
Text | ||
} | ||
}"#, | ||
r#"mutation entity { | ||
createOneDateEntity(data: { Id: "2020-01-02T00:00:00Z", Text: "B" }) { | ||
Text | ||
} | ||
}"#, | ||
]; | ||
|
||
for mutation in mutations { | ||
runner.query(mutation).await?.assert_success(); | ||
} | ||
|
||
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
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