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

SqlNullabilityProcessor and COALESCE with more than two arguments #26344

Closed
dmitry-lipetsk opened this issue Oct 14, 2021 · 1 comment · Fixed by #26419
Closed

SqlNullabilityProcessor and COALESCE with more than two arguments #26344

dmitry-lipetsk opened this issue Oct 14, 2021 · 1 comment · Fixed by #26419
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@dmitry-lipetsk
Copy link
Contributor

Hello,

if (sqlFunctionExpression.IsBuiltIn
&& sqlFunctionExpression.Arguments != null
&& string.Equals(sqlFunctionExpression.Name, "COALESCE", StringComparison.OrdinalIgnoreCase))
{
var left = Visit(sqlFunctionExpression.Arguments[0], out var leftNullable);
var right = Visit(sqlFunctionExpression.Arguments[1], out var rightNullable);
nullable = leftNullable && rightNullable;
return sqlFunctionExpression.Update(sqlFunctionExpression.Instance, new[] { left, right });
}

SQL-function COALESCE allows usage more than two parameters.

My provider, for example, may generate a call of COALESCE with many arguments.

I think, your generic SqlNullabilityProcessor must process all arguments of COALESCE. Not only [0] and [1].

@dmitry-lipetsk
Copy link
Contributor Author

Same problem in next code:

if (sqlFunctionExpression.IsBuiltIn
&& string.Equals("COALESCE", sqlFunctionExpression.Name, StringComparison.OrdinalIgnoreCase))
{
// for coalesce:
// (a ?? b) == null -> a == null && b == null
// (a ?? b) != null -> a != null || b != null
var left = ProcessNullNotNull(
_sqlExpressionFactory.MakeUnary(
sqlUnaryExpression.OperatorType,
sqlFunctionExpression.Arguments![0],
typeof(bool),
sqlUnaryExpression.TypeMapping)!,
operandNullable);
var right = ProcessNullNotNull(
_sqlExpressionFactory.MakeUnary(
sqlUnaryExpression.OperatorType,
sqlFunctionExpression.Arguments[1],
typeof(bool),
sqlUnaryExpression.TypeMapping)!,
operandNullable);
return SimplifyLogicalSqlBinaryExpression(
_sqlExpressionFactory.MakeBinary(
sqlUnaryExpression.OperatorType == ExpressionType.Equal
? ExpressionType.AndAlso
: ExpressionType.OrElse,
left,
right,
sqlUnaryExpression.TypeMapping)!);
}

@maumar maumar self-assigned this Oct 14, 2021
@ajcvickers ajcvickers added this to the 7.0.0 milestone Oct 15, 2021
maumar added a commit that referenced this issue Oct 21, 2021
…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
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 21, 2021
maumar added a commit that referenced this issue Oct 22, 2021
…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
maumar added a commit that referenced this issue Oct 22, 2021
…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
@maumar maumar closed this as completed in 21318f1 Oct 26, 2021
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview1 Feb 14, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview1, 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-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants