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

Query result grouping depends on presence of grouped-by fields in selected set. #3315

Open
islamaliev opened this issue Dec 11, 2024 · 0 comments
Labels
area/query Related to the query component bug Something isn't working

Comments

@islamaliev
Copy link
Contributor

The following test passes:

func TestQueryOneToMany_WithOnlyAggregatesSelected_ShouldGroupResults(t *testing.T) {
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.CreateDoc{
				CollectionID: 1,
				Doc: `{
					"name": "John Grisham",
					"age": 65,
					"verified": true
				}`,
			},
			testUtils.CreateDoc{
				CollectionID: 1,
				Doc: `{
					"name": "Cornelia Funke",
					"age": 62,
					"verified": false
				}`,
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				DocMap: map[string]any{
					"name":      "Painted House",
					"rating":    4.9,
					"author_id": testUtils.NewDocIndex(1, 0),
				},
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				DocMap: map[string]any{
					"name":      "A Time for Mercy",
					"rating":    4.5,
					"author_id": testUtils.NewDocIndex(1, 0),
				},
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				DocMap: map[string]any{
					"name":      "Theif Lord",
					"rating":    4.8,
					"author_id": testUtils.NewDocIndex(1, 1),
				},
			},
			testUtils.Request{
				Request: `query {
				Book(groupBy: [author]) 
					{
						_avg(_group: { field: rating })
					}
				}`,
				Results: map[string]any{
					"Book": []map[string]any{
						{
							"_avg": 4.733333333333333,
						},
					},
				},
			},
			testUtils.Request{
				Request: `query {
				Book(groupBy: [author]) 
					{
						author {
							name
						}
						_avg(_group: { field: rating })
					}
				}`,
				Results: map[string]any{
					"Book": []map[string]any{
						{
							"author": map[string]any{
								"name": "John Grisham",
							},
							"_avg": 4.7,
						},
						{
							"author": map[string]any{
								"name": "Cornelia Funke",
							},
							"_avg": 4.8,
						},
					},
				},
			},
		},
	}

	executeTestCase(t, test)
}

But the first query (without author { name} in selected fields) should produce the same result as the second one.

@islamaliev islamaliev added area/query Related to the query component bug Something isn't working labels Dec 11, 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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant