-
Notifications
You must be signed in to change notification settings - Fork 181
Support CASE function with Calcite
#3558
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
Conversation
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Signed-off-by: Lantao Jin <ltjin@amazon.com>
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Lantao Jin <ltjin@amazon.com>
Do you know the reason to make documentation executable? It's hard to debug if doctest fails. @penghuo |
doctest has grown to have three primary uses, more reading opendistro-for-elasticsearch/sql#497
|
Signed-off-by: Lantao Jin <ltjin@amazon.com>
| os> source=accounts | eval result = case(age > 35, firstname, age < 30, lastname else employer) | fields result, firstname, lastname | ||
| fetched rows / total rows = 4/4 | ||
| +--------+-----------+----------+ | ||
| | result | firstname | lastname | |
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.
add age and employer, fields result, age, firstname, lastname, employer
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.
done
| | null | Dale | Adams | | ||
| +--------+-----------+----------+ | ||
|
|
||
| os> source=accounts | eval result = case(age > 35, firstname, age < 30, lastname) | fields result, firstname, lastname |
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.
ditto, add age
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.
done
Signed-off-by: Lantao Jin <ltjin@amazon.com>
|
I will backport this to branch 3.0 since it should be treated as bug:
Can you approve it? @penghuo @anasalkouz @model-collapse |
|
Approved to backport |
* Support CASE function with Calcite Signed-off-by: Lantao Jin <ltjin@amazon.com> * add anonymizer Signed-off-by: Lantao Jin <ltjin@amazon.com> * address comment and fix varchar literal bug Signed-off-by: Lantao Jin <ltjin@amazon.com> * add doc Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix doctest Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix doctest Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit 47e6a2a) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* Support CASE function with Calcite * add anonymizer * address comment and fix varchar literal bug * add doc * fix doctest * fix doctest --------- (cherry picked from commit 47e6a2a) Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* Support CASE function with Calcite Signed-off-by: Lantao Jin <ltjin@amazon.com> * add anonymizer Signed-off-by: Lantao Jin <ltjin@amazon.com> * address comment and fix varchar literal bug Signed-off-by: Lantao Jin <ltjin@amazon.com> * add doc Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix doctest Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix doctest Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: xinyual <xinyual@amazon.com>
Description
Support CASE function with Calcite (v3) and v2 engine.
Its syntax should be support in PPL OpenSearch as well.
https://github.com/opensearch-project/opensearch-spark/blob/6832737577119221819c49235c212020c0214fed/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4#L489-L491
Fix the bug of string literal: enforce to CHAR(1) type or VARCHAR type to avoid CHAR(n)
Related Issues
Resolves #3536
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.