Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

DATE_FORMAT function #764

Conversation

lyndonbauto
Copy link
Contributor

*Issue #710

Description of changes:
Added implementation, unit tests, manual integration tests, and documentation for date_format function.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

penghuo and others added 30 commits June 17, 2020 09:17
…rch#522)

* Bug fix, support long type for aggregation

* change to datetime to JDBC format
* prepare odfe 1.9

* Fix all ES 7.8 compile and build errors

* Revert changes as Lombok is working now

* Update CustomExternalTestCluster.java

* Fix license headers check

* Use splitFieldsByMetadata to separate fields when calling SearchHit constructor

* More fixes for ODFE 1.9

* Remove todo statement

* Add ODFE 1.9.0 release notes
…ticsearch#551)

* Revert "Rename release notes to use 4 digit versions (opendistro-for-elasticsearch#547)"

This reverts commit 33c6d3e.

* Revert "Opendistro Release 1.9.0 (opendistro-for-elasticsearch#532)"

This reverts commit 254f2e0.

* Revert "Bug fix, support long type for aggregation (opendistro-for-elasticsearch#522)"

This reverts commit fb2ed91.
…h#549) (opendistro-for-elasticsearch#554)

* merge all sql repos

* fix test and build workflows

* fix workbench and odbc path

* fix workbench and odbc path

* restructure workbench dir and fix workflows

* fix workbench workflow

* fix workbench workflow

* fix workbench workflow

* fix workbench workflow

* fix workbench workflow

* revert workbench directory structure

* fix workbench workflow

* fix workbench workflow

* fix workbench workflow

* fix workbench workflow

* update workbench workflow for release

* Delete .github/ in sql-workbench directory

* Add cypress to sql-workbench

* Sync latest ODBC commits

* Sync latest workbench commits (will add cypress in separate PR)

* Add ignored ODBC libs
* add date and time support

* update doc

* update doc
…-elasticsearch#645)

- add null check to avoid crashing if details not initialized
…or-elasticsearch/develop

Merge develop branch into master to cut odfe1.10 release
lyndonbauto and others added 23 commits September 29, 2020 10:08
…ime-function-week

# Conflicts:
#	core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprStringValue.java
#	core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/DSL.java
#	core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/datetime/DateTimeFunction.java
#	core/src/main/java/com/amazon/opendistroforelasticsearch/sql/expression/function/BuiltinFunctionName.java
#	docs/user/dql/functions.rst
#	integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/DateTimeFunctionIT.java
#	ppl/src/main/antlr/OpenDistroPPLParser.g4
#	sql/src/main/antlr/OpenDistroSQLParser.g4
…arch/sql into lyndon/date-format-function

[1] Fixing merge conflicts
Copy link
Member

@chloe-zh chloe-zh left a comment

Choose a reason for hiding this comment

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

LGTM!

* @param formatExpr the format ExprValue of String type.
* @return Date formatted using format and returned as a String.
*/
static ExprValue getFormattedDate(ExprValue dateExpr, ExprValue formatExpr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure the use case. Do you try to do something like this format.replace("%\W", () -> replace).
If so, i recommended to consider the https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)
which provide the more clean code structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't realize I could do this, tahnks for the suggestion! I have updated with this change.

* @param format Incoming format String without mapping completed.
* @return Outgoing format String with mapping completed.
*/
private static String literalReplace(String format) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the expected result if the user input the format string which we doesn't support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean a format we don't support, such as %z?
According to the documentation for MySQL it should come out as just z, so using the DateTimeFormatter specification, to get a literal out, we wrap in ', so %z => 'z'.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, does it covered in the test cases also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor

@penghuo penghuo left a comment

Choose a reason for hiding this comment

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

Thanks for the change!

@penghuo penghuo merged commit f33c0e6 into opendistro-for-elasticsearch:develop Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants