Skip to content

Commit

Permalink
fix: Fix compound relational filters in aggregates (#2297)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #1869

## Description

Fixes compound relational filters in aggregates where their dependencies
were not already part of the query.
  • Loading branch information
AndrewSisley authored Feb 9, 2024
1 parent ea511f0 commit e28ea26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 13 additions & 0 deletions planner/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ func resolveAggregates(
mapping.SetChildAt(index, childMapping)

if !childIsMapped {
filterDependencies, err := resolveFilterDependencies(
ctx,
store,
childCollectionName,
target.filter,
mapping.ChildMappings[index],
childFields,
)
if err != nil {
return nil, err
}
childFields = append(childFields, filterDependencies...)

// If the child was not mapped, the filter will not have been converted yet
// so we must do that now.
convertedFilter = ToFilter(target.filter.Value(), mapping.ChildMappings[index])
Expand Down
11 changes: 2 additions & 9 deletions tests/integration/query/one_to_one/with_count_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

// This test documents a bug and should be altered with:
// https://github.com/sourcenetwork/defradb/issues/1869
func TestQueryOneToOneWithCountWithCompoundOrFilterThatIncludesRelation(t *testing.T) {
test := testUtils.TestCase{
Description: "One-to-one relation with count with _or filter that includes relation",
Expand Down Expand Up @@ -103,17 +101,12 @@ func TestQueryOneToOneWithCountWithCompoundOrFilterThatIncludesRelation(t *testi
}`,
Results: []map[string]any{
{
"_count": "2",
"_count": int(2),
},
},
},
},
}

testUtils.AssertPanic(
t,
func() {
testUtils.ExecuteTestCase(t, test)
},
)
testUtils.ExecuteTestCase(t, test)
}

0 comments on commit e28ea26

Please sign in to comment.