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
SQL: Fix issue with wrong NULL optimization #37124
Changes from 5 commits
ebdf275
15470a7
7a07d5e
764b5cd
7bfeff9
cd2c32f
5e7fe98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression; | ||
|
||
public enum Nullability { | ||
TRUE, // Whether the expression can become null | ||
FALSE, // The expression can never become null | ||
UNKNOWN; // Cannot determine if the expression supports possible null folding | ||
|
||
/** | ||
* Return the logical AND of a list of {@code Nullability} | ||
* <pre> | ||
* UNKNOWN AND TRUE/FALSE/UNKNOWN = UNKNOWN | ||
* FALSE AND FALSE = FALSE | ||
* TRUE AND FALSE/TRUE = TRUE | ||
* </pre> | ||
*/ | ||
public static Nullability and(Nullability... nullabilities) { | ||
Nullability value = null; | ||
for (Nullability n: nullabilities) { | ||
switch (n) { | ||
case UNKNOWN: | ||
return UNKNOWN; | ||
case TRUE: | ||
value = TRUE; | ||
break; | ||
case FALSE: | ||
if (value == null || value == FALSE) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
value = FALSE; | ||
} | ||
} | ||
} | ||
return value != null ? value : UNKNOWN; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this ever occur? Is the method called over an empty list? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it's a "safety net". Should we throw an exception instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might make sense though my preference is to handle this corner cases leniently. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? It's the method signature and the args should align.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the signature is different than before; as far as I recall the alignment doesn't have to be under the same param (see the other constructors).