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

Add Array_Contains partial match support to Linq #4991

Open
bcrobinson opened this issue Jan 31, 2025 · 0 comments · May be fixed by #4992
Open

Add Array_Contains partial match support to Linq #4991

bcrobinson opened this issue Jan 31, 2025 · 0 comments · May be fixed by #4992
Labels
customer-reported Issue created by a customer needs-investigation

Comments

@bcrobinson
Copy link

bcrobinson commented Jan 31, 2025

Is your feature request related to a problem? Please describe.

The Array_Contains function CosmosDB Sql has a 3rd parameter which allows it to do a partial match on the given item.

https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/array-contains

The current Linq array.Contains(item) don't have a way to set this 3rd parameter to do the partial match.

Describe the solution you'd like

A Linq extension method that allows me to set all the CosmosSql Array_Contains function parameters, something like this:

documents.Where(document => document.ObjectArray.ArrayContains(new { Name = "abc" }, true))

This would most likely need to be a new extension method where the given item has an object type, as the partial match would need to take an anonumous object so we can only supply the properties we need. If it uses the generic Linq .Contains<T>(...) extension methods it would require creating instances of that class, which would then serialise with null property values.

I.e. it would need to look like this

bool ArrayContains(this IEnumerable obj, object itemToMatch, bool partialMatch)

As if this was ArrayContains<T>(this IEnumerable<T> obj, T itemToMatch, bool partialMatch) then we'd need to always pass the same T type to this method. The downside is you loose some type checking (the anonymous object could have a property name typed wrong),

Describe alternatives you've considered
We can create a user defined function in cosmos that wraps the Array_Contains call, but we ran into issues with it not using indexes in searches.

Additional context

I had a quick play around to see if I could add this to the client lib, if this is a valid request I can create a PR for this new extension method

https://github.com/bcrobinson/azure-cosmos-dotnet-v3/tree/feature/array_contains_builtin_function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issue created by a customer needs-investigation
Projects
None yet
1 participant