-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: add PARSE_DATE and FORMAT_DATE functions #7733
Conversation
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.
LGTM, with a couple of suggestions. Also needs to be cherry-[picked to the 0.20.x-ksqldb
branch.
} | ||
try { | ||
final DateTimeFormatter formatter = formatters.get(formatPattern); | ||
return LocalDate.ofEpochDay(TimeUnit.MILLISECONDS.toDays(date.getTime())).format(formatter); |
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.
I wonder what if formatPattern
contains time characters? Would those be part of the final String?
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.
Added a test for this.
final Object result = udf.formatDate(Date.valueOf("2014-11-09"), "yyyy-dd-MM'Fred'"); | ||
|
||
// Then: | ||
assertThat(result, is("2014-09-11Fred")); |
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.
I'm not sure about this. Should we support embedded chars in the final date string?
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.
It was supported in the old DateToString function:
ksql/ksqldb-engine/src/test/java/io/confluent/ksql/function/udf/datetime/DateToStringTest.java
Line 61 in cd1a988
public void shouldSupportEmbeddedChars() { |
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.
Just tested Mysql and it supports this too. Perhaps it is allowed in order to write the format you want, i.e. dates yyyy/MM/dd
or yyyy-MM-dd
or Today is Year = yyyy Month = MM Day = dd
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.
LGTM
Description
Enables DATE data for UDFs and adds the PARSE_DATE and FORMAT_DATE functions + docs.
Testing done
QTT + unit tests
Reviewer checklist