Skip to content
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: Implement NULLIF(expr1, expr2) function #35826

Merged
merged 6 commits into from Nov 23, 2018

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Nov 22, 2018

NULLIF returns null if the 2 expressions are equal or the
expr1 otherwise.

Closes: #35818

NULLIF returns null if the 2 expressions are equal or the
expr1 otherwise.

Closes: elastic#35818
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

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.

Looking good. Left few comments.

<2> 2nd expression


*Output*: `NULL` if the 2 expressions are equal, otherwise the 1st expression.
Copy link
Contributor

Choose a reason for hiding this comment

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

Lowercase null? For another function doc page you used the lowercased version of null: https://github.com/elastic/elasticsearch/pull/35793/files#diff-cf102e856ee9e39135c9677a52db35e1R108

/**
* Name is `NULLIf` to avoid having it registered as `NULL_IF` instead of `NULLIF`.
*/
public class NULLIf extends ConditionalFunction {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do something about these class names? I understand why it is named like this and same goes for IFNull added previously, but I believe we should change the way we normalize the names. Simplest/quickest approach: put these exception functions in a Set (or similar) and treat them differently in the normalize method from FunctionRegistry.

}

public static Object apply(Object leftValue, Object rightValue) {
if (BinaryComparisonProcessor.BinaryComparisonOperation.EQ.apply(leftValue, rightValue) == Boolean.TRUE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe import org.elasticsearch.xpack.sql.expression.predicate.operator.comparison.BinaryComparisonProcessor.BinaryComparisonOperation to shorten this line and make it more readable?

@@ -1172,6 +1174,9 @@ protected Expression rule(Expression e) {
return Literal.of(in, null);
}

} else if (e instanceof NULLIf) {
return e; // Special rule SimplifyNullIf is applied instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was on purpose as we have them in all else if blocks.

Copy link
Member

Choose a reason for hiding this comment

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

We do?

@matriv
Copy link
Contributor Author

matriv commented Nov 22, 2018

Thanks @astefan! Pushed commit to address your comments.

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
Copy link
Contributor Author

matriv commented Nov 23, 2018

retest this please

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

@@ -1172,6 +1174,9 @@ protected Expression rule(Expression e) {
return Literal.of(in, null);
}

} else if (e instanceof NULLIf) {
return e; // Special rule SimplifyNullIf is applied instead

Copy link
Member

Choose a reason for hiding this comment

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

We do?

@matriv matriv merged commit 410f570 into elastic:master Nov 23, 2018
@matriv matriv deleted the mt/impl-35818 branch November 23, 2018 21:21
matriv added a commit that referenced this pull request Nov 23, 2018
NULLIF returns null if the 2 expressions are equal or the
expr1 otherwise.

Closes: #35818
@matriv
Copy link
Contributor Author

matriv commented Nov 23, 2018

Backported to 6.x with 4757556

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

Successfully merging this pull request may close these issues.

None yet

5 participants