Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable filtering within array elements of json docs #3308

Open
islamaliev opened this issue Dec 9, 2024 · 0 comments
Open

Enable filtering within array elements of json docs #3308

islamaliev opened this issue Dec 9, 2024 · 0 comments
Labels
area/query Related to the query component feature New feature or request

Comments

@islamaliev
Copy link
Contributor

islamaliev commented Dec 9, 2024

func TestJSONArrayIndex_WithNestedArraysAndObjects_ShouldScopeIndexSearch(t *testing.T) {
	req := `query {
		User(filter: {custom: {numbers: {nested: {_any: {_eq: 4}}}}}) {
			name
		}
	}`
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type User {
						name: String 
						custom: JSON @index
					}`,
			},
			testUtils.CreateDoc{
				DocMap: map[string]any{
					"name": "John",
					"custom": map[string]any{
						"numbers": []any{3, 5, map[string]any{"nested": []int{9, 4}}, 7},
					},
				},
			},
			testUtils.CreateDoc{
				DocMap: map[string]any{
					"name": "Islam",
					"custom": map[string]any{
						// there is sought value here, but not in "nested" scope
						"numbers": []any{4, 9, map[string]any{"nested": []int{0, 3}}},
					},
				},
			},
			testUtils.CreateDoc{
				DocMap: map[string]any{
					"name": "Islam",
					"custom": map[string]any{
						"numbers": []any{1, map[string]any{"another": []int{4, 3}}},
					},
				},
			},
			testUtils.Request{
				Request: req,
				Results: map[string]any{
					"User": []map[string]any{
						{"name": "John"},
					},
				},
			},
			testUtils.Request{
				Request:  makeExplainQuery(req),
				Asserter: testUtils.NewExplainAsserter().WithIndexFetches(1),
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}

The test is specific for secondary indexes, but by removing couple things can be made regular.
Whoever picks up this task please also add secondary index somewhere here tests/integration/index/json_array_test.go if it's not too much trouble. Otherwise please create another task for sec. index.

Update:
After discussing with the team we concluded that we want queries to be more specific on what indexes of array we want to filter.
Proposed syntaxes were:

filter: {custom: {numbers: {2: {nested: {_any: {_eq: 4}}}}}}
filter: {custom: {numbers: {at: {index: 2, nested: {_any: {_eq: 4}}}}}}
@islamaliev islamaliev added area/query Related to the query component feature New feature or request labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant