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

Cosmos: Translate regex matching #28078

Closed
Tracked by #3868
sekarcse opened this issue May 23, 2022 · 6 comments · Fixed by #28121
Closed
Tracked by #3868

Cosmos: Translate regex matching #28078

sekarcse opened this issue May 23, 2022 · 6 comments · Fixed by #28121
Assignees
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported type-enhancement
Milestone

Comments

@sekarcse
Copy link

sekarcse commented May 23, 2022

How to use RegexMatch in EF Core Cosmos C#

I want to apply the below in Linq. Here code is in-case sensitive

Cosmos Query
SELECT * FROM c
WHERE RegexMatch (c.Code, "ZWw","i")

@roji
Copy link
Member

roji commented May 23, 2022

This isn't currently supported, but you can use raw SQL queries to call the function in SQL yourself.

Cosmos docs for the function

@sekarcse
Copy link
Author

Thanks @roji for the quick reply

@AndriySvyryd AndriySvyryd added the good first issue This issue should be relatively straightforward to fix. label May 24, 2022
@AndriySvyryd AndriySvyryd added this to the Backlog milestone May 24, 2022
@Marusyk
Copy link
Member

Marusyk commented May 25, 2022

@roji @AndriySvyryd What is your point of view for implementing this feature?

smth like this?

dataSet.Where(x => EF.Functions.RegexMatch(x, "Zxw", "i"));

@roji
Copy link
Member

roji commented May 25, 2022

@Marusyk if possible, translating built-in .NET functions is preferred. For example, the PG provider supports regex by translating Regex.IsMatch(stringValue, "^A+") (see docs).

@AndriySvyryd
Copy link
Member

Adding to what @roji said you can also translate some of the options, but throw for the ones not supported by Cosmos.

RegexOptions Modifier
Multiline m
Singleline s
IgnoreCase i
IgnorePatternWhitespace x

@roji roji changed the title How to use RegexMatch in EF Core C# Cosmos: Translate regex matching May 26, 2022
@roji
Copy link
Member

roji commented May 26, 2022

Note: we also already translate Regex.IsMatch in SQLite and have tests for it in NorthwindFunctionsQueryTestBase.

Marusyk added a commit to Marusyk/efcore that referenced this issue May 28, 2022
@roji roji added community-contribution and removed good first issue This issue should be relatively straightforward to fix. labels May 30, 2022
@roji roji removed this from the Backlog milestone May 30, 2022
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 30, 2022
@roji roji added this to the 7.0.0 milestone May 30, 2022
@roji roji self-assigned this May 30, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview6 Jun 20, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview6, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants