Skip to content

Conversation

@matriv
Copy link
Contributor

@matriv matriv commented Nov 23, 2018

This operator handles nulls in different way than the normal =.
If one of the operants is null and the other not it returns false.
If both operants are null it returns true. Therefore in contrary to
=, which returns null if at least one of the operants is null, this one
never returns null as a result.

Closes: #35871

This operator handles nulls in different way than the normal `=`. If one of the operants is `null` and the other not it returns `false`. If both operants are `null` it returns `true`. Therefore in contrary to `=`, which returns `null` if at least one of the operants is `null`, this one never returns `null` as a result. Closes: elastic#35871
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Looks good. I've added a comment though on the IsNull optimization which should be in the optimizer not the parser as it won't catch non-trivial cases:
ABS(NULL) <=> a

return new Equals(loc, left, right);
case SqlBaseParser.NULLEQ:
// Simplify to IS NULL to avoid special handling in QueryTranslator later on
if (right.equals(NULL)) {
Copy link
Member

Choose a reason for hiding this comment

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

This logic should be optimizer (changing the tree) instead of the parser which should be pretty accurate to the actual query (helps with reporting errors). Further more it would make this apply if one of the expressions becomes NULL in folding and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I didn't think this through.

@matriv
Copy link
Contributor Author

matriv commented Nov 24, 2018

@costin thanks for the comment, fixup pushed.

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@matriv matriv merged commit b078e29 into elastic:master Nov 26, 2018
@matriv matriv deleted the mt/impl-35871 branch November 26, 2018 13:02
matriv added a commit that referenced this pull request Nov 26, 2018
This operator handles nulls in different way than the normal `=`. If one of the operants is `null` and the other not it returns `false`. If both operants are `null` it returns `true`. Therefore in contrary to `=`, which returns `null` if at least one of the operants is `null`, this one never returns `null` as a result. Closes: #35871
@matriv
Copy link
Contributor Author

matriv commented Nov 26, 2018

Backported to 6.x with 4ecfecf

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