From 1a69e9034dcc68a02d6b2359a2fc2e7f656b9c53 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Tue, 14 Nov 2023 09:58:39 +0000 Subject: [PATCH] Fix EXISTS tests --- .../tests/goldenfiles/select_where_related_exists.json | 2 +- crates/ndc-sqlserver/tests/query_tests.rs | 2 -- ...uery_tests__predicates__select_where_related_exists.snap | 4 ++-- crates/query-engine/sql/src/sql/convert.rs | 6 +++--- .../snapshots/tests__it_select_where_unrelated_exists.snap | 2 +- ...ere_album_id_equals_self_nested_object_relationship.snap | 6 +++--- .../snapshots/tests__select_where_array_relationship.snap | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_related_exists.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_related_exists.json index 3338c423..daac10f4 100644 --- a/crates/ndc-sqlserver/tests/goldenfiles/select_where_related_exists.json +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_related_exists.json @@ -38,7 +38,7 @@ }, "operator": { "type": "other", - "name": "like" + "name": "_like" }, "value": { "type": "scalar", diff --git a/crates/ndc-sqlserver/tests/query_tests.rs b/crates/ndc-sqlserver/tests/query_tests.rs index e059064f..f89d6e4c 100644 --- a/crates/ndc-sqlserver/tests/query_tests.rs +++ b/crates/ndc-sqlserver/tests/query_tests.rs @@ -96,7 +96,6 @@ mod predicates { insta::assert_json_snapshot!(result); } - /* // fix exists implementation #[tokio::test] async fn select_where_unrelated_exists() { @@ -110,7 +109,6 @@ mod predicates { let result = run_query("select_where_related_exists").await; insta::assert_json_snapshot!(result); } - */ } mod sorting { diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_related_exists.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_related_exists.snap index afcfc353..a5c50a3f 100644 --- a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_related_exists.snap +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_related_exists.snap @@ -6,6 +6,7 @@ expression: result { "rows": [ { + "title": "Santana", "albums": { "rows": [ { @@ -18,8 +19,7 @@ expression: result "title": "Santana Live" } ] - }, - "title": "Santana" + } } ] } diff --git a/crates/query-engine/sql/src/sql/convert.rs b/crates/query-engine/sql/src/sql/convert.rs index 45cfe186..8122413a 100644 --- a/crates/query-engine/sql/src/sql/convert.rs +++ b/crates/query-engine/sql/src/sql/convert.rs @@ -191,7 +191,7 @@ impl Join { sql.append_syntax(")"); sql.append_syntax(" AS "); join.alias.to_sql(sql); - sql.append_syntax(" ON ('true') "); + sql.append_syntax(" ON (1 = 1) "); } Join::CrossJoin(join) => { sql.append_syntax(" CROSS JOIN "); @@ -411,8 +411,8 @@ impl Value { Value::Character(s) => sql.append_param(Param::String(s.clone())), Value::String(s) => sql.append_param(Param::String(s.clone())), Value::Variable(v) => sql.append_param(Param::Variable(v.clone())), - Value::Bool(true) => sql.append_syntax("true"), - Value::Bool(false) => sql.append_syntax("false"), + Value::Bool(true) => sql.append_syntax("1 = 1"), + Value::Bool(false) => sql.append_syntax("1 = 0"), Value::Null => sql.append_syntax("null"), Value::Array(items) => { sql.append_syntax("ARRAY ["); diff --git a/crates/query-engine/translation/tests/snapshots/tests__it_select_where_unrelated_exists.snap b/crates/query-engine/translation/tests/snapshots/tests__it_select_where_unrelated_exists.snap index f28d7615..91ba9e5a 100644 --- a/crates/query-engine/translation/tests/snapshots/tests__it_select_where_unrelated_exists.snap +++ b/crates/query-engine/translation/tests/snapshots/tests__it_select_where_unrelated_exists.snap @@ -19,7 +19,7 @@ FROM WHERE ( ( - true + 1 = 1 AND ([1_artist].[Name] = cast(@P1 as varchar)) ) AND ([0_album].[ArtistId] = [1_artist].[ArtistId]) diff --git a/crates/query-engine/translation/tests/snapshots/tests__select_where_album_id_equals_self_nested_object_relationship.snap b/crates/query-engine/translation/tests/snapshots/tests__select_where_album_id_equals_self_nested_object_relationship.snap index d7e79d96..a66b419a 100644 --- a/crates/query-engine/translation/tests/snapshots/tests__select_where_album_id_equals_self_nested_object_relationship.snap +++ b/crates/query-engine/translation/tests/snapshots/tests__select_where_album_id_equals_self_nested_object_relationship.snap @@ -58,7 +58,7 @@ FROM [0_Track].[AlbumId] = [9_BOOLEXP_Album].[AlbumId] ) ) - ) AS [9_BOOLEXP_Album] ON ('true') + ) AS [9_BOOLEXP_Album] ON (1 = 1) INNER JOIN ( SELECT * @@ -73,7 +73,7 @@ FROM [0_Track].[AlbumId] = [10_BOOLEXP_Album].[AlbumId] ) ) - ) AS [10_BOOLEXP_Album] ON ('true') + ) AS [10_BOOLEXP_Album] ON (1 = 1) INNER JOIN ( SELECT * @@ -88,7 +88,7 @@ FROM [10_BOOLEXP_Album].[ArtistId] = [11_BOOLEXP_Artist].[ArtistId] ) ) - ) AS [11_BOOLEXP_Artist] ON ('true') + ) AS [11_BOOLEXP_Artist] ON (1 = 1) WHERE ( [9_BOOLEXP_Album].[AlbumId] > [11_BOOLEXP_Artist].[ArtistId] diff --git a/crates/query-engine/translation/tests/snapshots/tests__select_where_array_relationship.snap b/crates/query-engine/translation/tests/snapshots/tests__select_where_array_relationship.snap index f808c345..5b540f66 100644 --- a/crates/query-engine/translation/tests/snapshots/tests__select_where_array_relationship.snap +++ b/crates/query-engine/translation/tests/snapshots/tests__select_where_array_relationship.snap @@ -38,7 +38,7 @@ FROM ( [0_Artist].[ArtistId] = [5_BOOLEXP_Album].[ArtistId] ) - ) AS [5_BOOLEXP_Album] ON ('true') + ) AS [5_BOOLEXP_Album] ON (1 = 1) WHERE ( [5_BOOLEXP_Album].[Title] LIKE cast(@P1 as varchar)