Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ranma42 committed Jun 16, 2024
1 parent 51d0217 commit a8096ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

// CONCAT_WS filters out nulls, but string.Join treats them as empty strings; so coalesce (which is a no-op for non-nullable
// arguments).
arguments[i + 1] = sqlArgument switch
{
ColumnExpression { IsNullable: false } => sqlArgument,
SqlConstantExpression constantExpression => constantExpression.Value is null
? _sqlExpressionFactory.Constant(string.Empty)
: constantExpression,
_ => Dependencies.SqlExpressionFactory.Coalesce(sqlArgument, _sqlExpressionFactory.Constant(string.Empty))
};
arguments[i + 1] = Dependencies.SqlExpressionFactory.Coalesce(sqlArgument, _sqlExpressionFactory.Constant(string.Empty));
}

// CONCAT_WS never returns null; a null delimiter is interpreted as an empty string, and null arguments are skipped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ public SqlServerStringAggregateMethodTranslator(
}
}

// STRING_AGG filters out nulls, but string.Join treats them as empty strings; coalesce unless we know we're aggregating over
// a non-nullable column.
if (sqlExpression is not ColumnExpression { IsNullable: false })
{
sqlExpression = _sqlExpressionFactory.Coalesce(
sqlExpression,
_sqlExpressionFactory.Constant(string.Empty, typeof(string)));
}
// STRING_AGG filters out nulls, but string.Join treats them as empty strings.
sqlExpression = _sqlExpressionFactory.Coalesce(
sqlExpression,
_sqlExpressionFactory.Constant(string.Empty, typeof(string)));

// STRING_AGG returns null when there are no rows (or non-null values), but string.Join returns an empty string.
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ public SqliteStringAggregateMethodTranslator(ISqlExpressionFactory sqlExpression
return null;
}

if (sqlExpression is not ColumnExpression { IsNullable: false })
{
sqlExpression = _sqlExpressionFactory.Coalesce(
sqlExpression,
_sqlExpressionFactory.Constant(string.Empty, typeof(string)));
}
sqlExpression = _sqlExpressionFactory.Coalesce(
sqlExpression,
_sqlExpressionFactory.Constant(string.Empty, typeof(string)));

if (source.Predicate != null)
{
Expand Down

0 comments on commit a8096ad

Please sign in to comment.