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

Add GET_FORMAT Function To OpenSearch SQL Plugin #1299

Merged

Conversation

GabeFernandez310
Copy link
Contributor

Signed-off-by: GabeFernandez310 Gabriel.Fernandez@improving.com

Description

Adds the get_format function to the OpenSearch SQL Plugin. It's implementation is aligned with the MySQL Documentation.

Note: This currently only supports a USA format for DATE, TIME, TIMESTAMP and DATETIME. Support and testing for other formats will be completed in follow-up work

Examples:

opensearchsql> SELECT get_format(DATE, 'USA');
fetched rows / total rows = 1/1
+---------------------------+
| get_format(DATE, 'USA')   |
|---------------------------|
| %m.%d.%Y                  |
+---------------------------+
opensearchsql> SELECT DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'USA'));
fetched rows / total rows = 1/1
+----------------------------------------------------+
| DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'USA'))   |
|----------------------------------------------------|
| 10.03.2003                                         |
+----------------------------------------------------+
opensearchsql> SELECT DATE_FORMAT('2003-10-03', null);
fetched rows / total rows = 1/1
+-----------------------------------+
| DATE_FORMAT('2003-10-03', null)   |
|-----------------------------------|
| null                              |
+-----------------------------------+

Issues Resolved

#722

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --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.

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2023

Codecov Report

Merging #1299 (1d052f8) into main (4b3cdbb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff            @@
##               main    #1299   +/-   ##
=========================================
  Coverage     98.36%   98.37%           
- Complexity     3643     3649    +6     
=========================================
  Files           343      343           
  Lines          9017     9041   +24     
  Branches        585      585           
=========================================
+ Hits           8870     8894   +24     
  Misses          142      142           
  Partials          5        5           
Flag Coverage Δ
sql-engine 98.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...arch/sql/expression/datetime/DateTimeFunction.java 100.00% <100.00%> (ø)
...h/sql/expression/function/BuiltinFunctionName.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

* @return ExprValue..
*/
private ExprValue exprGetFormat(ExprValue type, ExprValue format) {
String key = type.stringValue() + "-" + format.stringValue();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does https://guava.dev/releases/19.0/api/docs/com/google/common/collect/Table.html solve the problem without concat the string value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here, and here


Argument type: TYPE, STRING
TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP].
STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by ').
Copy link
Collaborator

Choose a reason for hiding this comment

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

only "USA" support for now, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes. I will adjust the documentation for now and update it once the other formats are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here

Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
@GabeFernandez310
Copy link
Contributor Author

I had to rebase while addressing PR comments. There appears to be a failing test which exists on the main branch as well.

Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

May I ask where this comes from? Is it part of deprecate legacy engine or other issue? Because I didn't find it in our codebase.

@GabeFernandez310
Copy link
Contributor Author

May I ask where this comes from? Is it part of deprecate legacy engine or other issue? Because I didn't find it in our codebase.

The get_format function was listed along with others in issue #722 to support date and time functions.

@Yury-Fridlyand
Copy link
Collaborator

It is one of MySQL functions which we're going to support.

@GabeFernandez310 GabeFernandez310 marked this pull request as draft February 2, 2023 18:14
@GabeFernandez310 GabeFernandez310 marked this pull request as ready for review February 9, 2023 17:52
@dai-chen
Copy link
Collaborator

dai-chen commented Feb 10, 2023

@GabeFernandez310 Shall we merge IT fix from main before merging this?

@MaxKsyunz MaxKsyunz merged commit 72547f4 into opensearch-project:main Feb 15, 2023
@MaxKsyunz MaxKsyunz deleted the integ-add-get_format-function branch February 15, 2023 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants