Skip to content

Commit

Permalink
fix(i): Inline array filter types (#3145)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
nasdf authored Oct 18, 2024
1 parent 8181a15 commit 76f5c8a
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 10 deletions.
4 changes: 1 addition & 3 deletions internal/connor/all.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package connor

import (
"github.com/sourcenetwork/defradb/client"

"github.com/sourcenetwork/immutable"
)

Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 1 addition & 3 deletions internal/connor/any.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package connor

import (
"github.com/sourcenetwork/defradb/client"

"github.com/sourcenetwork/immutable"
)

Expand Down Expand Up @@ -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
}
}

Expand Down
26 changes: 26 additions & 0 deletions tests/integration/query/inline_array/with_filter_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
26 changes: 26 additions & 0 deletions tests/integration/query/inline_array/with_filter_any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
28 changes: 26 additions & 2 deletions tests/integration/query/json/with_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}}}) {
Expand Down
28 changes: 26 additions & 2 deletions tests/integration/query/json/with_any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}}}) {
Expand Down

0 comments on commit 76f5c8a

Please sign in to comment.