From 76f5c8a0af7d284468d4637b4f03b2fa5eaa5453 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 18 Oct 2024 09:27:12 -0700 Subject: [PATCH] fix(i): Inline array filter types (#3145) ## Relevant issue(s) Resolves #3142 ## Description This PR fixes an issue with inline array filters where a non array value would return an error. ## Tasks - [x] I made sure the code is well commented, particularly hard-to-understand areas. - [x] I made sure the repository-held documentation is changed accordingly. - [x] I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in [tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)). - [x] I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ... ## How has this been tested? Updated / added integration tests. Specify the platform(s) on which this was tested: - MacOS --- internal/connor/all.go | 4 +-- internal/connor/any.go | 4 +-- .../inline_array/with_filter_all_test.go | 26 +++++++++++++++++ .../inline_array/with_filter_any_test.go | 26 +++++++++++++++++ tests/integration/query/json/with_all_test.go | 28 +++++++++++++++++-- tests/integration/query/json/with_any_test.go | 28 +++++++++++++++++-- 6 files changed, 106 insertions(+), 10 deletions(-) diff --git a/internal/connor/all.go b/internal/connor/all.go index ce2557d25b..bf607b583b 100644 --- a/internal/connor/all.go +++ b/internal/connor/all.go @@ -1,8 +1,6 @@ package connor import ( - "github.com/sourcenetwork/defradb/client" - "github.com/sourcenetwork/immutable" ) @@ -39,7 +37,7 @@ func all(condition, data any) (bool, error) { return allSlice(condition, t) default: - return false, client.NewErrUnhandledType("data", data) + return false, nil } } diff --git a/internal/connor/any.go b/internal/connor/any.go index 7eea2a7bce..ecd16ce992 100644 --- a/internal/connor/any.go +++ b/internal/connor/any.go @@ -1,8 +1,6 @@ package connor import ( - "github.com/sourcenetwork/defradb/client" - "github.com/sourcenetwork/immutable" ) @@ -39,7 +37,7 @@ func anyOp(condition, data any) (bool, error) { return anySlice(condition, t) default: - return false, client.NewErrUnhandledType("data", data) + return false, nil } } diff --git a/tests/integration/query/inline_array/with_filter_all_test.go b/tests/integration/query/inline_array/with_filter_all_test.go index 1661c54731..a558a70a23 100644 --- a/tests/integration/query/inline_array/with_filter_all_test.go +++ b/tests/integration/query/inline_array/with_filter_all_test.go @@ -303,3 +303,29 @@ func TestQueryInlineNotNullBooleanArray_WithAllFilter_Succeeds(t *testing.T) { executeTestCase(t, test) } + +func TestQueryInlineStringArray_WithAllFilterAndNullValue_Succeeds(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple inline array, filtered all of string array with null", + Actions: []any{ + testUtils.CreateDoc{ + Doc: `{ + "name": "Islam", + "pageHeaders": null + }`, + }, + testUtils.Request{ + Request: `query { + Users(filter: {pageHeaders: {_all: {_eq: null}}}) { + name + } + }`, + Results: map[string]any{ + "Users": []map[string]any{}, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/inline_array/with_filter_any_test.go b/tests/integration/query/inline_array/with_filter_any_test.go index 0dfc815595..15d3f701e4 100644 --- a/tests/integration/query/inline_array/with_filter_any_test.go +++ b/tests/integration/query/inline_array/with_filter_any_test.go @@ -303,3 +303,29 @@ func TestQueryInlineNotNullBooleanArray_WithAnyFilter_Succeeds(t *testing.T) { executeTestCase(t, test) } + +func TestQueryInlineStringArray_WithAnyFilterAndNullValue_Succeeds(t *testing.T) { + test := testUtils.TestCase{ + Description: "Simple inline array, filtered any of string array with null", + Actions: []any{ + testUtils.CreateDoc{ + Doc: `{ + "name": "Islam", + "pageHeaders": null + }`, + }, + testUtils.Request{ + Request: `query { + Users(filter: {pageHeaders: {_any: {_eq: null}}}) { + name + } + }`, + Results: map[string]any{ + "Users": []map[string]any{}, + }, + }, + }, + } + + executeTestCase(t, test) +} diff --git a/tests/integration/query/json/with_all_test.go b/tests/integration/query/json/with_all_test.go index 918c51e5bb..b0d12765ae 100644 --- a/tests/integration/query/json/with_all_test.go +++ b/tests/integration/query/json/with_all_test.go @@ -16,9 +16,9 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func TestQueryJSON_WithAllFilter_ShouldFilter(t *testing.T) { +func TestQueryJSON_WithAllFilterWithAllTypes_ShouldFilter(t *testing.T) { test := testUtils.TestCase{ - Description: "Simple JSON array, filtered all of string array", + Description: "Simple JSON array, filtered all of all types array", Actions: []any{ testUtils.SchemaUpdate{ Schema: `type Users { @@ -38,6 +38,30 @@ func TestQueryJSON_WithAllFilter_ShouldFilter(t *testing.T) { "custom": [null, false, "second", {"one": 1}, [1, 2]] }`, }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Islam", + "custom": null + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Keenan", + "custom": 0 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Andy", + "custom": "" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "custom": true + }`, + }, testUtils.Request{ Request: `query { Users(filter: {custom: {_all: {_ne: null}}}) { diff --git a/tests/integration/query/json/with_any_test.go b/tests/integration/query/json/with_any_test.go index d38d3e83e8..e79e90946b 100644 --- a/tests/integration/query/json/with_any_test.go +++ b/tests/integration/query/json/with_any_test.go @@ -16,9 +16,9 @@ import ( testUtils "github.com/sourcenetwork/defradb/tests/integration" ) -func TestQueryJSON_WithAnyFilter_ShouldFilter(t *testing.T) { +func TestQueryJSON_WithAnyFilterWithAllTypes_ShouldFilter(t *testing.T) { test := testUtils.TestCase{ - Description: "Simple JSON array, filtered any of string array", + Description: "Simple JSON array, filtered any of all types array", Actions: []any{ testUtils.SchemaUpdate{ Schema: `type Users { @@ -38,6 +38,30 @@ func TestQueryJSON_WithAnyFilter_ShouldFilter(t *testing.T) { "custom": [null, false, "second", {"one": 1}, [1, 2]] }`, }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Islam", + "custom": null + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Keenan", + "custom": 0 + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "Andy", + "custom": "" + }`, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John", + "custom": true + }`, + }, testUtils.Request{ Request: `query { Users(filter: {custom: {_any: {_eq: null}}}) {