We rewrite the NVL function in org/apache/calcite/sql2rel/StandardConvertletTable.java:303 , during the rewrite we currently override the operands' nullability to be NOT NULL which is not needed. This causes issues if that operand is pushdown , since the input of that operand need not be not nullable whereas we forced that operand to be Not nullable.
We rewrite the nvl function [ NVL(op1, op2) to CASE ( IS NOT NULL (op1), op1, op2) ]
Previously we were wrongly setting final op1, op2 nullability to NOT NULL
For Example for the query
select nvl("name", 'undefined') FROM "hr"."emps"
Using the test framework, (Column "name" is nullable)
The generated plan before this change is:
After this change:
If we look at expr#8 , its the CASE described earlier and expr#6 is the "name" column.
As described with this change we can assert that the nullability is preserved as nullable as required ( expr#6 is set to Nullable)