Skip to content

Commit

Permalink
Fix compound relational filters in aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Feb 8, 2024
1 parent ea511f0 commit a8b71b0
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 a8b71b0

Please sign in to comment.