-
Notifications
You must be signed in to change notification settings - Fork 16
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
CASE WHEN
expression labels evaluated eagerly instead of lazily
#65
Comments
Thinking about this some more, the existing caching is necessary for correctness due to NULL propagation semantics. For example, var temp1 = A();
var temp2 = B();
return temp1 == null || temp2 == null ? null : temp1 == temp2; Without caching, the evaluation would happen twice, which is at best undesired and at worst incorrect (when the function has side effects). Thus, it makes sense to keep the general approach, and fix the problem in the compilation of |
Hmm, that's odd:
|
Background
We have a table similar to:
We're trying to transform the date value to a different format using NQuery with:
Expected result
Returns table with date value transformed to
2023-07-27
.Actual result
Throws exception:
Analysis
The problem is caused by the caching of expression values in variables implemented in
ExpressionBuilder.BuildCachedExpression
. This code transforms expressions likea.b.c.Prop
toAnd it transforms our
CASE WHEN Type = 'date' THEN FORMAT(TO_DATETIME(Value), 'yyyy-MM-dd') ELSE Value END
to:In words: It pulls calculations out of the
CASE
expression, changing the semantics (searchedCASE
expressions are short-circuited in SQL).Open questions
As a little experiment, I removed caching by replacing all calls to
BuildCachedExpression
withBuildLiftedExpression
. All unit tests are still green, but I'm unsure whether that is a good idea as I do not know:CASE WHEN
bug described here?Highly appreciate any insights.
The text was updated successfully, but these errors were encountered: