Conversation
`Tags !^$ "sweet"` built `Tags.Any(z => z != "sweet")`. This matched every collection with any other value, so it returned rows that have the value and left out empty collections. On Postgres, EF could not translate it and threw InvalidOperationException. The operator now builds the negation of has: `!Tags.Any(z => z == "sweet")`. This is the same pattern as the other negated collection operators. BREAKING CHANGE: `!^$` returns only collections without the value, including empty collections. It no longer returns a collection that has the value and another value. `%!^$` is now the negation of `%^$`. Use a custom operation to get the old meaning.
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.
Summary
This PR makes does-not-have (
!^$) exclude collections that have the value. This is a breaking change. It is one of the six breaking changes that were removed from #114 so that main stays compatible with v1.14.2.Status: for later consideration. Do not merge this PR now. The captain decides on each breaking change separately. If this change is accepted, it needs a major version, or a new operator.
Old behavior (v1.14.2 and main)
Tags !^$ "sweet"buildsx.Tags.Any(z => z != "sweet").["sweet", "sour"], and it does not match an empty collection.InvalidOperationException.New behavior
The operator builds the negation of has:
Not(x.Tags.Any(z => z == "sweet")). It returns only collections without the value, including empty collections.%!^$is now the negation of%^$. The same query now runs on Postgres.Example
Proof from the
verify-querykitharness. The tags are: Pancakes["breakfast", "sweet"], Beef Stew["dinner"], Salt Bread["bread", "Winner"], Plain Water[].InvalidOperationException(EF cannot translate the expression)Justification
"Does not have X" means that X is not in the collection. The v1.14.2 expression means "has a value that is not X", which is a different question. It returns rows that have X and leaves out empty collections, so every in-memory consumer gets wrong results. It also does not run on Postgres at all.
Every other negated operator in QueryKit is the negation of its positive operator, and the fix makes
!^$obey the same rule. A consumer that wants the old meaning can use a custom operation. Because the in-memory results change, this fix needs a major version or a new operator.Migration
Use a custom operation to get the old meaning ("has a value that is not X").
Tests
FilterParserTestsnow expectsNot(x.Tags.Any(z => (z == "winner")))and the case-insensitive form.has_returns_matching_rowsis nowhas_and_does_not_have_return_matching_rows, with 3 new cases for!^$,!^$*, and%!^$.dotnet test: 349 unit tests and 271 integration tests pass.