DonnyZone commented on PR #3203:
URL: https://github.com/apache/calcite/pull/3203#issuecomment-1563744642
> > Sorry for the late reply. I make some tests in my local environment. The
optimization for `BinaryExpression` seems to be incorrect. The code after
optimization throws compilation error.
> > ```
> > Boolean a = true || null;
> > Boolean b = null || true;
> > ```
>
> @DonnyZone thanks for reply
>
> I can`t obtain such a code after optimization ( can you show me how can i
make it ?
>
> final ParameterExpression x_ = Expressions.parameter(Object.class, "x");
BinaryExpression y1 = Expressions.orElse(Expressions.constant(true),
Expressions.constant(null)); DeclarationStatement exp0 =
Expressions.declare(Modifier.PUBLIC, x_, y1);
>
> assertEquals("{\n public Object x = true;\n}\n", optimize(exp0))
>
> after optimization shows: public Object x = true;
I just pick the code from your UT.
```
@Test void testOptimizeBinaryNullCasting() {
// (v ? null : "a") == 1
assertEquals("{\n return (v || null) == 1;\n}\n",
optimize(
Expressions.equal(
Expressions.makeBinary(ExpressionType.OrElse,
Expressions.parameter(boolean.class, "v"),
new ConstantExpression(String.class, null)),
ONE)));
}
```
By the way, is it necessary to apply `skipNullCast` for the
`BinaryExpression`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]