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: Add translator for Regex.IsMatch method #28121

Merged
merged 4 commits into from
May 30, 2022

Conversation

Marusyk
Copy link
Member

@Marusyk Marusyk commented May 28, 2022

Add translator for Regex.IsMatch method to REGEXMATCH

Fixes #28078

Please review
Thank you in advance

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's nice to see this!

In addition to the below, please take a look at the regex options as suggested by @AndriySvyryd (#28078 (comment)) - there seems to be at least some correspondence with the .NET API here.

Note that we'd only support constant regex options, which we can interpret at compile-time and translate to the appropriate Cosmos constant string. The PostgreSQL translator may provide some help.

@Marusyk Marusyk marked this pull request as ready for review May 29, 2022 00:37
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Marusyk!

AssertSql(
@"SELECT c
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND RegexMatch(c[""CustomerID""], ""^T"", """"))");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to print last argument if options are none?

Copy link
Member Author

@Marusyk Marusyk Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, yes. If Cosmos allows it and a user specifically indicated None, then why not. Clear behavior.
Of course I can change it if you want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with Smit's suggestion, always better to emit clearer, more concise SQL. Added to #28139.

Copy link
Member Author

@Marusyk Marusyk Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, please assign 28139 to me

{
await AssertQuery(
async,
ss => ss.Set<Customer>().Where(o => Regex.IsMatch(o.CustomerID, "^T", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider case where regex options are passed as a variable here so it won't be constant. We can force "constantization" in parameter extraction through evaluatablefilter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we definitely can... Added that to #28139.

WHERE ((c[""Discriminator""] = ""Customer"") AND RegexMatch(c[""CustomerID""], ""^T"", ""ix""))");
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConditionalTheory
sync/async both version
Use AssertQuery syntax

cc: @roji

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, doing as part of #28139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cosmos: Translate regex matching
4 participants