Support multiple filters in aggregations#2568
Open
TravelCurry02 wants to merge 17 commits intoash-project:mainfrom
Open
Support multiple filters in aggregations#2568TravelCurry02 wants to merge 17 commits intoash-project:mainfrom
TravelCurry02 wants to merge 17 commits intoash-project:mainfrom
Conversation
Updated compile error handling to correctly point to the second invocation of 'use Ash.Domain' instead of the defmodule line. Enhanced error messages for clarity and consistency in Ash.Domain.Interface. Added tests to verify correct error line and message content.
- Add filters entity to all aggregate types - Combine multiple filters with AND, matching read actions behavior - Maintain backward compatibility with single filter - Add comprehensive tests Fixes ash-project#1265
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor checklist
Leave anything that you believe does not apply unchecked.
Overview
This PR implements support for multiple
filterlines in aggregate definitions, matching the behavior of read actions. Previously, attempting to use multiple filters in an aggregate would result in the error: "Multiple values for key:filter".Issue: #1265
What Changed
Before
After
Implementation Details
Files Modified
lib/ash/resource/aggregate/aggregate.exfilters: []field to struct to store multiple filter entitiesconcat_filters/1to combine multiple filters with AND (single code path for one or many)combine_filter/2helper to merge with existing filter when present (backward compatibility)transform/1to callconcat_filtersafter relationship path normalizationfilters: [any]lib/ash/resource/dsl.exfilters: [@filter]entity to all 9 aggregate types (count,first,max,min,sum,avg,exists,custom,list)filterfrom schema in aggregate entities to avoid DSL ambiguitytest/resource/aggregates_test.exsdescribe "multiple filters"block:How It Works
filter expr(...)lines as repeatable entities (same pattern as read actions).filterline is stored in thefilters: []list on the aggregate struct.concat_filters/1combines all filters usingAsh.Query.BooleanExpression.new(:and, ...).aggregate.filter, which existing code continues to use.Backward Compatibility
filter expr(...)still works (same code path; whenrestis empty, reduce returns the single filter).filterfield on the struct remains; downstream code is unchanged.Testing
All tests pass, including:
Related Patterns
This implementation mirrors existing patterns:
filters: [@filter]entity →concat_filters→ combinedfilterjoin_filters: []; this adds the same list pattern for main filters