Skip to content

Cosmos: Add translator for Regex.IsMatch method - #28121

Merged
roji merged 4 commits into
dotnet:mainfrom
Marusyk:rmarusyk/28078
May 30, 2022
Merged

roji merged 4 commits into
dotnet:mainfrom
Marusyk:rmarusyk/28078

Conversation

@Marusyk

@Marusyk Marusyk commented May 28, 2022 •

Copy link
Copy Markdown
Member

Add translator for Regex.IsMatch method to REGEXMATCH

Fixes #28078

Please review
Thank you in advance

@roji roji left a comment

Copy link
Copy Markdown
Member

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

@roji roji left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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?

@Marusyk Marusyk Jun 1, 2022 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

@Marusyk Marusyk Jun 2, 2022 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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