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

Fix to #26344 - SqlNullabilityProcessor and COALESCE with more than two arguments #26419

Merged
merged 1 commit into from
Oct 26, 2021

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Oct 21, 2021

Nested coalesce ops are converted to coalesce with multiple arguments. Fixing null semantics logic that only assumed coalesce function would have two arguments

Fixes #26344

@maumar maumar requested a review from smitpatel October 21, 2021 04:31
@maumar
Copy link
Contributor Author

maumar commented Oct 22, 2021

new version up @smitpatel

Comment on lines +91 to +97
? new SqlFunctionExpression(
sqlFunctionExpression.Name,
distinctArguments,
sqlFunctionExpression.IsNullable,
argumentsPropagateNullability: distinctArguments.Select(a => false).ToArray(),
sqlFunctionExpression.Type,
sqlFunctionExpression.TypeMapping)
Copy link
Contributor

@dmitry-lipetsk dmitry-lipetsk Oct 23, 2021

Choose a reason for hiding this comment

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

In my opinion, it is better to define and use a new

SqlExpression SqlExpressionFactory::Coalesce(params SqlExpression[] parameters);

instead direct creation of SqlFunctionExpression.

Copy link
Contributor Author

@maumar maumar Oct 26, 2021

Choose a reason for hiding this comment

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

@dmitry-lipetsk coalesce will get to us in form of binary expression so this logic is necessary as well.
We could add a SqlExpressionFactory overload that takes multiple args, but I'm not sure how it would be used - do you have a scenario in mind?

One thing that I can think of is constructing sqlexpression tree manually in the HasTranslation, but for the translation we take care of type mappings so users can call ctor directly there also.

Main advantage of using expression factory over the ctor directly (the way I see it) is that the former takes care of type mappings for you. However, after the initial translation the type mappings are filled in, so there's no need to use the factory.

Copy link
Contributor

@dmitry-lipetsk dmitry-lipetsk Oct 26, 2021

Choose a reason for hiding this comment

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

Hello @maumar,

For COALESCE and all another built-in, SQL-function I use own classes based SqlFunctionExpression. This is help to resolve some problems with SQL-tree transformation (through Update and VisitChildren methods) and improve generation of SQL text.

Usage of SqlExpressionFactory.Coalesce instead of direct creation of SqlFunctionExpression allows to save a custom expression class for COALESCE.

In case of COALESCE, replacing to standard SqFunctionlExpression not critical for me.


At current time I nothing know about HasTranslation :)

I finished implementation of translation to SQL and initiate implementation of Migrations support.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given the coalesce in LINQ will come with 2 arguments, there is no particular value in relational layer to have another overload. Providers who translates Coalesce with multiple arguments directly can add overload in provider specific ISqlExpressionFactory as needed.

…wo arguments

Nested coalesce ops are converted to coalesce with multiple arguments. Fixing null semantics logic that only assumed coalesce function would have two arguments

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

Successfully merging this pull request may close these issues.

SqlNullabilityProcessor and COALESCE with more than two arguments
3 participants