Skip to content

[CALCITE-4377] Fix the return nullability inference during rex simpli…#2246

Closed
danny0405 wants to merge 1 commit into
apache:masterfrom
danny0405:fix-nullability
Closed

[CALCITE-4377] Fix the return nullability inference during rex simpli…#2246
danny0405 wants to merge 1 commit into
apache:masterfrom
danny0405:fix-nullability

Conversation

@danny0405

Copy link
Copy Markdown
Contributor

…fication

@danny0405
danny0405 force-pushed the fix-nullability branch 2 times, most recently from e8e478e to 4eb6c60 Compare November 5, 2020 08:25
@vlsi

vlsi commented Nov 5, 2020

Copy link
Copy Markdown
Contributor

Thanks, it looks ok.

Would you please remove @Disabled(...) from fuzzer tests as well?

@danny0405

Copy link
Copy Markdown
Contributor Author

Thanks, it looks ok.

Would you please remove @Disabled(...) from fuzzer tests as well?

No, there are still some NPEs reported from the Sargs.

Comment on lines +905 to +908
// Ignores the nullability change when all the operands are literals
// which come from the simplification.
assert operands.stream().map(RexNode::getType).anyMatch(RelDataType::isNullable)
|| operands.stream().allMatch(p -> RexUtil.isLiteral(p, false));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks strange, and it contradicts Policy.ALL definition

This kind of expression is null if and only if at least one of its arguments is null

What do literals do here?

@danny0405 danny0405 Nov 12, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the simplification, we drop the useless cast cast(1 as nullable INT) which breaks the nullability. We have 2 choices:

  1. Do not make any simplification that breaks the nullability
  2. Make the validation strategy more relaxed

I choose the latter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://issues.apache.org/jira/browse/CALCITE-4387
Simplify should be allowed to both widen and narrowing nullability.

I believe we must not alter the definition of nullness policyhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nullness policy is always there, we should make the validation adapter to the simplification.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case ANY is defined as return type is nullable if and only if one of the arguments is null.
It allows no exceptions like "ok, the return type might be null if one of the arguments is literal".

That is why I believe RexUtil.isLiteral must not be here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Assertion at line 907 must be kept intact.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should never use ReduceExpressionsRule.Config.matchNullability, it should always return true.

I can not figure out a way to fix if we keep the assertion at line 907 as it is.

@vlsi vlsi Nov 23, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rexBuilder.makeCall(e.getType(), e.getOperator(), operands); above must be updated to infer the proper type instead of e.getType().

PS. I have already done all of that in #2250 a week or two ago

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rexBuilder.makeCall(e.getType(), e.getOperator(), operands); above must be updated to infer the proper type instead of e.getType().

The problem is that it is hard to keep node type equivalence during simplification anymore, and the ReduceExpressionsRule.Config.matchNullability becomes meaningless.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReduceExpressionsRule.Config.matchNullability refers to the nullability of the overall expression rather than the nullability of the internal nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants