From 77e10271d301010a903de9d9a9aad241737178cc Mon Sep 17 00:00:00 2001 From: Sergey Tatarintsev Date: Wed, 29 Nov 2023 16:34:17 +0100 Subject: [PATCH 1/2] Fix duplicate snapshots in json_filters test --- .../tests/queries/filters/json_filters.rs | 865 +++++++++--------- 1 file changed, 455 insertions(+), 410 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs index e2ab83cfd62f..f3e4026a8678 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs @@ -46,53 +46,68 @@ mod json_filters { create_row(&runner, 4, r#"{ \"a\": { \"b\": [null] } }"#, false).await?; create_row(&runner, 5, r#"{ }"#, false).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b"], equals: "\"c\"" "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: ["a", "b"], equals: "\"c\"" "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b", "0"], equals: "1" "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: ["a", "b", "0"], equals: "1" "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b", "0"], equals: JsonNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: ["a", "b", "0"], equals: JsonNull "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b"], equals: JsonNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":3}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: ["a", "b"], equals: JsonNull "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b"], equals: DbNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":5}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"path: ["a", "b"], equals: DbNull "#, Some(""))); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":5}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: ["a", "b"], equals: AnyNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":3},{"id":5}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: ["a", "b"], equals: AnyNull "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3},{"id":5}]}}"### + ); + } Ok(()) } @@ -120,13 +135,13 @@ mod json_filters { create_row(&runner, 5, r#"{ \"a\": { \"b\": [null] } }"#, false).await?; create_row(&runner, 6, r#"{ }"#, false).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: "$.a.b", equals: "\"c\"" "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"path: "$.a.b", equals: "\"c\"" "#, Some(""))); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### + ); + } insta::assert_snapshot!( run_query!( @@ -136,29 +151,32 @@ mod json_filters { @r###"{"data":{"findManyTestModel":[{"id":2},{"id":3}]}}"### ); - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: "$.a.b[0]", equals: JsonNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":4},{"id":5}]}}"### + let res = run_query!( + runner, + jsonq(&runner, r#"path: "$.a.b[0]", equals: JsonNull "#, Some("")) ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4},{"id":5}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: "$.a.b", equals: DbNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"path: "$.a.b", equals: DbNull "#, Some(""))); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"path: "$.a.b", equals: AnyNull "#, Some("")) - ), - @r###"{"data":{"findManyTestModel":[{"id":4},{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"path: "$.a.b", equals: AnyNull "#, Some(""))); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4},{"id":6}]}}"### + ); + } Ok(()) } @@ -174,36 +192,36 @@ mod json_filters { create_row(&runner, 8, r#"[1, [null], 2]"#, true).await?; // array_contains - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_contains: "[3]""#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_contains: "[\"a\"]""#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_contains: "[3]""#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } + let res = run_query!(runner, jsonq(&runner, r#"array_contains: "[\"a\"]""#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### + ); + } // NOT array_contains - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_contains: "[3]""#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":4},{"id":6},{"id":7},{"id":8}]}}"### - ); - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_contains: "[\"a\"]""#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":6},{"id":7},{"id":8}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_contains: "[3]""#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4},{"id":6},{"id":7},{"id":8}]}}"### + ); + } + let res = run_query!(runner, not_jsonq(&runner, r#"array_contains: "[\"a\"]""#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":6},{"id":7},{"id":8}]}}"### + ); + } // MySQL has slightly different semantics and also coerces null to [null]. is_one_of!( @@ -225,30 +243,30 @@ mod json_filters { match runner.connector_version() { // MariaDB does not support finding arrays in arrays, unlike MySQL ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) => { - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_contains: "[[1, 2]]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":6},{"id":7},{"id":8}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_contains: "[[1, 2]]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":6},{"id":7},{"id":8}]}}"### + ); + } } _ => { - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_contains: "[[1, 2]]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### - ); - - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_contains: "[[null]]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_contains: "[[1, 2]]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### + ); + } + + let res = run_query!(runner, jsonq(&runner, r#"array_contains: "[[null]]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### + ); + } } } @@ -280,86 +298,86 @@ mod json_filters { create_row(&runner, 8, r#"[null, \"test\"]"#, true).await?; create_row(&runner, 9, r#"[[null], \"test\"]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_starts_with: "3" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_starts_with: "3" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_starts_with: "\"a\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_starts_with: "\"a\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_starts_with: "[1, 2]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_starts_with: "[1, 2]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":6}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_starts_with: "null" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_starts_with: "null" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_starts_with: "[null]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":9}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_starts_with: "[null]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":9}]}}"### + ); + } // NOT - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_starts_with: "3" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":4},{"id":6},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_starts_with: "3" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":4},{"id":6},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_starts_with: "\"a\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":6},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_starts_with: "\"a\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":6},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_starts_with: "[1, 2]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_starts_with: "[1, 2]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_starts_with: "null" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":6},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_starts_with: "null" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":6},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_starts_with: "[null]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":6},{"id":8}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_starts_with: "[null]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":6},{"id":8}]}}"### + ); + } Ok(()) } @@ -387,86 +405,86 @@ mod json_filters { create_row(&runner, 8, r#"[\"test\", null]"#, true).await?; create_row(&runner, 9, r#"[\"test\", [null]]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_ends_with: "3" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_ends_with: "3" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_ends_with: "\"b\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":3}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_ends_with: "\"b\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_ends_with: "[3, 4]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_ends_with: "[3, 4]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_ends_with: "null" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_ends_with: "null" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":8}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"array_ends_with: "[null]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":9}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"array_ends_with: "[null]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":9}]}}"### + ); + } // NOT - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_ends_with: "3" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":2},{"id":3},{"id":4},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_ends_with: "3" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":2},{"id":3},{"id":4},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_ends_with: "\"b\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_ends_with: "\"b\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":4},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_ends_with: "[3, 4]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":8},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_ends_with: "[3, 4]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":8},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_ends_with: "null" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":9}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_ends_with: "null" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":9}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"array_ends_with: "[null]" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":8}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"array_ends_with: "[null]" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":8}]}}"### + ); + } Ok(()) } @@ -490,22 +508,22 @@ mod json_filters { create_row(&runner, 2, r#"\"fool\""#, true).await?; create_row(&runner, 3, r#"[\"foo\"]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"string_contains: "oo" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"string_contains: "oo" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } // NOT - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"string_contains: "ab" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"string_contains: "ab" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } Ok(()) } @@ -530,22 +548,22 @@ mod json_filters { create_row(&runner, 3, r#"[\"foo\"]"#, true).await?; // string_starts_with - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"string_starts_with: "foo" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"string_starts_with: "foo" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } // NOT string_starts_with - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"string_starts_with: "ab" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"string_starts_with: "ab" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } Ok(()) } @@ -569,22 +587,22 @@ mod json_filters { create_row(&runner, 2, r#"\"fool\""#, true).await?; create_row(&runner, 3, r#"[\"foo\"]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"string_ends_with: "oo" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"string_ends_with: "oo" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1}]}}"### + ); + } // NOT - insta::assert_snapshot!( - run_query!( - runner, - not_jsonq(&runner, r#"string_ends_with: "oo" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### - ); + let res = run_query!(runner, not_jsonq(&runner, r#"string_ends_with: "oo" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### + ); + } Ok(()) } @@ -612,37 +630,37 @@ mod json_filters { create_row(&runner, 6, r#"100"#, true).await?; create_row(&runner, 7, r#"[\"foo\"]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"gt: "\"b\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"gt: "\"b\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"gte: "\"b\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"gte: "\"b\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"gt: "1" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":4},{"id":5},{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"gt: "1" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":4},{"id":5},{"id":6}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"gte: "1" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5},{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"gte: "1" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5},{"id":6}]}}"### + ); + } Ok(()) } @@ -693,37 +711,37 @@ mod json_filters { create_row(&runner, 6, r#"100"#, true).await?; create_row(&runner, 7, r#"[\"foo\"]"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"lt: "\"f\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"lt: "\"f\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"lte: "\"foo\"" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"lte: "\"foo\"" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":1},{"id":2}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"lt: "100" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"lt: "100" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5}]}}"### + ); + } - insta::assert_snapshot!( - run_query!( - runner, - jsonq(&runner, r#"lte: "100" "#, None) - ), - @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5},{"id":6}]}}"### - ); + let res = run_query!(runner, jsonq(&runner, r#"lte: "100" "#, None)); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"id":3},{"id":4},{"id":5},{"id":6}]}}"### + ); + } Ok(()) } @@ -753,70 +771,97 @@ mod json_filters { create_row(&runner, 6, r#"2.4"#, true).await?; create_row(&runner, 7, r#"3"#, true).await?; - insta::assert_snapshot!( - run_query!( - runner, - format!(r#"query {{ - findManyTestModel( - where: {{ json: {{ {}, array_contains: "3", array_starts_with: "3" }} }}, - cursor: {{ id: 2 }}, - take: 2 - ) {{ json }} - }}"#, json_path(&runner)) - ), - @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":[3,4,5]}}"},{"json":"{\"a\":{\"b\":[3,4,6]}}"}]}}"### - ); - insta::assert_snapshot!( - run_query!( - runner, - format!(r#"query {{ - findManyTestModel( - where: {{ - AND: [ - {{ json: {{ {}, gte: "1" }} }}, - {{ json: {{ {}, lt: "3" }} }}, - ] - }} - ) {{ json }} - }}"#, json_path(&runner), json_path(&runner)) - ), - @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":1}}"},{"json":"{\"a\":{\"b\":2.4}}"}]}}"### - ); + let res = run_query!( + runner, + format!( + r#"query {{ + findManyTestModel( + where: {{ json: {{ {}, array_contains: "3", array_starts_with: "3" }} }}, + cursor: {{ id: 2 }}, + take: 2 + ) {{ json }} + }}"#, + json_path(&runner) + ) + ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":[3,4,5]}}"},{"json":"{\"a\":{\"b\":[3,4,6]}}"}]}}"### + ); + } + + let res = run_query!( + runner, + format!( + r#"query {{ + findManyTestModel( + where: {{ + AND: [ + {{ json: {{ {}, gte: "1" }} }}, + {{ json: {{ {}, lt: "3" }} }}, + ] + }} + ) {{ json }} + }}"#, + json_path(&runner), + json_path(&runner) + ) + ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":1}}"},{"json":"{\"a\":{\"b\":2.4}}"}]}}"### + ); + } // NOT - insta::assert_snapshot!( - run_query!( - runner, - format!(r#"query {{ - findManyTestModel( - where: {{ NOT: {{ json: {{ {}, array_contains: "3", array_starts_with: "3" }} }} }}, - cursor: {{ id: 2 }}, - take: 2 - ) {{ json }} - }}"#, json_path(&runner)) - ), - @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":[5,6,7]}}"}]}}"### - ); + let res = run_query!( + runner, + format!( + r#"query {{ + findManyTestModel( + where: {{ NOT: {{ json: {{ {}, array_contains: "3", array_starts_with: "3" }} }} }}, + cursor: {{ id: 2 }}, + take: 2 + ) {{ json }} + }}"#, + json_path(&runner) + ) + ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":[5,6,7]}}"}]}}"### + ); + } // 1, 2.4, 3 // filter: false, true, false // negated: true, false, true // result: 1, 3 - insta::assert_snapshot!( - run_query!( - runner, - format!(r#"query {{ - findManyTestModel( - where: {{ - NOT: {{ AND: [ - {{ json: {{ {}, gt: "1" }} }}, - {{ json: {{ {}, lt: "3" }} }}, - ]}} - }} - ) {{ json }} - }}"#, json_path(&runner), json_path(&runner)) - ), - @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":1}}"},{"json":"{\"a\":{\"b\":3}}"}]}}"### - ); + let res = run_query!( + runner, + format!( + r#"query {{ + findManyTestModel( + where: {{ + NOT: {{ AND: [ + {{ json: {{ {}, gt: "1" }} }}, + {{ json: {{ {}, lt: "3" }} }}, + ]}} + }} + ) {{ json }} + }}"#, + json_path(&runner), + json_path(&runner) + ) + ); + insta::allow_duplicates! { + insta::assert_snapshot!( + res, + @r###"{"data":{"findManyTestModel":[{"json":"{\"a\":{\"b\":1}}"},{"json":"{\"a\":{\"b\":3}}"}]}}"### + ); + } Ok(()) } From f63661b544c9b037a71a9d62b25690a8b6dbb53a Mon Sep 17 00:00:00 2001 From: Sergey Tatarintsev Date: Thu, 30 Nov 2023 11:17:58 +0100 Subject: [PATCH 2/2] Size low hanging fruits Removes following functionality from WASM engine: - GraphQL protocol - DMMF - SDL Schema Neither of the features are used by the client runtimes and thrid party clients don't and can not use WASM engine, so it is safe to remove. --- query-engine/core/Cargo.toml | 5 ++- query-engine/core/src/protocol.rs | 3 ++ query-engine/core/src/response_ir/internal.rs | 2 ++ .../query-engine-node-api/src/functions.rs | 1 - query-engine/query-engine-wasm/Cargo.toml | 2 +- .../query-engine-wasm/src/wasm/engine.rs | 33 +------------------ .../query-engine-wasm/src/wasm/functions.rs | 18 ---------- query-engine/request-handlers/Cargo.toml | 12 +++++-- query-engine/request-handlers/src/lib.rs | 4 ++- .../request-handlers/src/protocols/mod.rs | 6 ++++ 10 files changed, 29 insertions(+), 57 deletions(-) diff --git a/query-engine/core/Cargo.toml b/query-engine/core/Cargo.toml index 1b7c52e59de9..da9e8331dfdf 100644 --- a/query-engine/core/Cargo.toml +++ b/query-engine/core/Cargo.toml @@ -5,6 +5,7 @@ version = "0.1.0" [features] metrics = ["query-engine-metrics"] +graphql-protocol = [] [dependencies] async-trait = "0.1" @@ -19,7 +20,9 @@ indexmap = { version = "1.7", features = ["serde-1"] } itertools = "0.10" once_cell = "1" petgraph = "0.4" -query-structure = { path = "../query-structure", features = ["default_generators"] } +query-structure = { path = "../query-structure", features = [ + "default_generators", +] } opentelemetry = { version = "0.17.0", features = ["rt-tokio", "serialize"] } query-engine-metrics = { path = "../metrics", optional = true } serde.workspace = true diff --git a/query-engine/core/src/protocol.rs b/query-engine/core/src/protocol.rs index 75e8dbc0fd70..e92438d5e92d 100644 --- a/query-engine/core/src/protocol.rs +++ b/query-engine/core/src/protocol.rs @@ -3,6 +3,7 @@ use serde::Deserialize; #[derive(Debug, Clone, Copy, Deserialize)] #[serde(rename_all = "camelCase")] pub enum EngineProtocol { + #[cfg(feature = "graphql-protocol")] Graphql, Json, } @@ -14,6 +15,7 @@ impl EngineProtocol { } /// Returns `true` if the engine protocol is [`Graphql`]. + #[cfg(feature = "graphql-protocol")] pub fn is_graphql(&self) -> bool { matches!(self, Self::Graphql) } @@ -22,6 +24,7 @@ impl EngineProtocol { impl From<&String> for EngineProtocol { fn from(s: &String) -> Self { match s.as_str() { + #[cfg(feature = "graphql-protocol")] "graphql" => EngineProtocol::Graphql, "json" => EngineProtocol::Json, x => panic!("Unknown engine protocol '{x}'. Must be 'graphql' or 'json'."), diff --git a/query-engine/core/src/response_ir/internal.rs b/query-engine/core/src/response_ir/internal.rs index 7becb19e768b..bbda8d7bd05d 100644 --- a/query-engine/core/src/response_ir/internal.rs +++ b/query-engine/core/src/response_ir/internal.rs @@ -552,11 +552,13 @@ fn serialize_scalar(field: &OutputField<'_>, value: PrismaValue) -> crate::Resul fn convert_prisma_value(field: &OutputField<'_>, value: PrismaValue, st: &ScalarType) -> crate::Result { match crate::executor::get_engine_protocol() { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => convert_prisma_value_graphql_protocol(field, value, st), EngineProtocol::Json => convert_prisma_value_json_protocol(field, value, st), } } +#[cfg(feature = "graphql-protocol")] fn convert_prisma_value_graphql_protocol( field: &OutputField<'_>, value: PrismaValue, diff --git a/query-engine/query-engine-node-api/src/functions.rs b/query-engine/query-engine-node-api/src/functions.rs index 868178f7361d..bcb64e240cae 100644 --- a/query-engine/query-engine-node-api/src/functions.rs +++ b/query-engine/query-engine-node-api/src/functions.rs @@ -1,4 +1,3 @@ -use crate::error::ApiError; use napi_derive::napi; use request_handlers::dmmf; use std::sync::Arc; diff --git a/query-engine/query-engine-wasm/Cargo.toml b/query-engine/query-engine-wasm/Cargo.toml index 6d3dc33050b7..e08d412d5f97 100644 --- a/query-engine/query-engine-wasm/Cargo.toml +++ b/query-engine/query-engine-wasm/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [lib] doc = false crate-type = ["cdylib"] -name = "query_engine" +name = "query_engine_wasm" [dependencies] diff --git a/query-engine/query-engine-wasm/src/wasm/engine.rs b/query-engine/query-engine-wasm/src/wasm/engine.rs index 19f442106b97..a40dfbd4ff94 100644 --- a/query-engine/query-engine-wasm/src/wasm/engine.rs +++ b/query-engine/query-engine-wasm/src/wasm/engine.rs @@ -14,7 +14,7 @@ use query_core::{ telemetry, QueryExecutor, TransactionOptions, TxId, }; use request_handlers::ConnectorMode; -use request_handlers::{dmmf, load_executor, render_graphql_schema, RequestBody, RequestHandler}; +use request_handlers::{load_executor, RequestBody, RequestHandler}; use serde::{Deserialize, Serialize}; use serde_json::json; use std::{ @@ -385,28 +385,6 @@ impl QueryEngine { .await } - #[wasm_bindgen] - pub async fn dmmf(&self, trace: String) -> Result { - let inner = self.inner.read().await; - let engine = inner.as_engine()?; - - let dispatcher = self.logger.dispatcher(); - - tracing::dispatcher::with_default(&dispatcher, || { - let span = tracing::info_span!("prisma:engine:dmmf"); - let _ = telemetry::helpers::set_parent_context_from_json_str(&span, &trace); - let _guard = span.enter(); - let dmmf = dmmf::render_dmmf(&engine.query_schema); - - let json = { - let _span = tracing::info_span!("prisma:engine:dmmf_to_json").entered(); - serde_json::to_string(&dmmf)? - }; - - Ok(json) - }) - } - /// If connected, attempts to roll back a transaction with id `tx_id` in the core. #[wasm_bindgen(js_name = rollbackTransaction)] pub async fn rollback_transaction(&self, tx_id: String, trace: String) -> Result { @@ -425,15 +403,6 @@ impl QueryEngine { .await } - /// Loads the query schema. Only available when connected. - #[wasm_bindgen(js_name = sdlSchema)] - pub async fn sdl_schema(&self) -> Result { - let inner = self.inner.read().await; - let engine = inner.as_engine()?; - - Ok(render_graphql_schema(engine.query_schema())) - } - #[wasm_bindgen] pub async fn metrics(&self, json_options: String) -> Result<(), wasm_bindgen::JsError> { log::info!("Called `QueryEngine::metrics()`"); diff --git a/query-engine/query-engine-wasm/src/wasm/functions.rs b/query-engine/query-engine-wasm/src/wasm/functions.rs index 9767b22fb811..5aa2a8d6ba2a 100644 --- a/query-engine/query-engine-wasm/src/wasm/functions.rs +++ b/query-engine/query-engine-wasm/src/wasm/functions.rs @@ -1,7 +1,4 @@ -use crate::error::ApiError; -use request_handlers::dmmf; use serde::Serialize; -use std::sync::Arc; use tsify::Tsify; use wasm_bindgen::prelude::wasm_bindgen; @@ -21,21 +18,6 @@ pub fn version() -> Version { } } -#[wasm_bindgen] -pub fn dmmf(datamodel_string: String) -> Result { - let mut schema = psl::validate(datamodel_string.into()); - - schema - .diagnostics - .to_result() - .map_err(|errors| ApiError::conversion(errors, schema.db.source()))?; - - let query_schema = query_core::schema::build(Arc::new(schema), true); - let dmmf = dmmf::render_dmmf(&query_schema); - - Ok(serde_json::to_string(&dmmf)?) -} - #[wasm_bindgen] pub fn debug_panic(panic_message: Option) -> Result<(), wasm_bindgen::JsError> { let user_facing = user_facing_errors::Error::from_panic_payload(Box::new( diff --git a/query-engine/request-handlers/Cargo.toml b/query-engine/request-handlers/Cargo.toml index 51ed4bd8b5ad..3686f14154af 100644 --- a/query-engine/request-handlers/Cargo.toml +++ b/query-engine/request-handlers/Cargo.toml @@ -20,7 +20,7 @@ bigdecimal = "0.3" thiserror = "1" tracing = "0.1" url = "2" -connection-string.workspace = true +connection-string.workspace = true once_cell = "1.15" mongodb-query-connector = { path = "../connectors/mongodb-query-connector", optional = true } @@ -32,11 +32,17 @@ schema = { path = "../schema" } codspeed-criterion-compat = "1.1.0" [features] -default = ["sql", "mongodb", "native"] +default = ["sql", "mongodb", "native", "graphql-protocol"] mongodb = ["mongodb-query-connector"] sql = ["sql-query-connector"] driver-adapters = ["sql-query-connector/driver-adapters"] -native = ["mongodb", "sql-query-connector", "quaint/native", "query-core/metrics"] +native = [ + "mongodb", + "sql-query-connector", + "quaint/native", + "query-core/metrics", +] +graphql-protocol = ["query-core/graphql-protocol"] [[bench]] name = "query_planning_bench" diff --git a/query-engine/request-handlers/src/lib.rs b/query-engine/request-handlers/src/lib.rs index 361e5c628bdf..949c26b302f3 100644 --- a/query-engine/request-handlers/src/lib.rs +++ b/query-engine/request-handlers/src/lib.rs @@ -12,7 +12,9 @@ mod response; pub use self::{error::HandlerError, load_executor::load as load_executor}; pub use connector_mode::ConnectorMode; pub use handler::*; -pub use protocols::{graphql::*, json::*, RequestBody}; +#[cfg(feature = "graphql-protocol")] +pub use protocols::graphql::*; +pub use protocols::{json::*, RequestBody}; pub use response::*; pub type Result = std::result::Result; diff --git a/query-engine/request-handlers/src/protocols/mod.rs b/query-engine/request-handlers/src/protocols/mod.rs index e2c50c2e7f1f..93bac460fecb 100644 --- a/query-engine/request-handlers/src/protocols/mod.rs +++ b/query-engine/request-handlers/src/protocols/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "graphql-protocol")] pub mod graphql; pub mod json; @@ -5,6 +6,7 @@ use query_core::{protocol::EngineProtocol, schema::QuerySchemaRef, QueryDocument #[derive(Debug)] pub enum RequestBody { + #[cfg(feature = "graphql-protocol")] Graphql(graphql::GraphqlBody), Json(json::JsonBody), } @@ -12,6 +14,7 @@ pub enum RequestBody { impl RequestBody { pub fn into_doc(self, query_schema: &QuerySchemaRef) -> crate::Result { match self { + #[cfg(feature = "graphql-protocol")] RequestBody::Graphql(body) => body.into_doc(), RequestBody::Json(body) => body.into_doc(query_schema), } @@ -19,6 +22,7 @@ impl RequestBody { pub fn try_from_str(val: &str, engine_protocol: EngineProtocol) -> Result { match engine_protocol { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => serde_json::from_str::(val).map(Self::from), EngineProtocol::Json => serde_json::from_str::(val).map(Self::from), } @@ -26,12 +30,14 @@ impl RequestBody { pub fn try_from_slice(val: &[u8], engine_protocol: EngineProtocol) -> Result { match engine_protocol { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => serde_json::from_slice::(val).map(Self::from), EngineProtocol::Json => serde_json::from_slice::(val).map(Self::from), } } } +#[cfg(feature = "graphql-protocol")] impl From for RequestBody { fn from(body: graphql::GraphqlBody) -> Self { Self::Graphql(body)