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 DATE_FORMAT function #55065

Open
matriv opened this issue Apr 10, 2020 · 19 comments
Open

SQL: Implement DATE_FORMAT function #55065

matriv opened this issue Apr 10, 2020 · 19 comments

Comments

@matriv
Copy link
Contributor

@matriv matriv commented Apr 10, 2020

Implement DATE_FORMAT according to the MySQL spec: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format by translating to the java.time patterns used in DATETIME_FORMAT.

Follows: #54832

@elasticmachine
Copy link
Collaborator

@elasticmachine elasticmachine commented Apr 10, 2020

Pinging @elastic/es-ql (:Query Languages/SQL)

@erickmp07
Copy link

@erickmp07 erickmp07 commented Apr 10, 2020

Hi. Can I start working on this?

@matriv
Copy link
Contributor Author

@matriv matriv commented Apr 11, 2020

@erickmp07 Yes, sure, thank you!

@MohamedBechir
Copy link

@MohamedBechir MohamedBechir commented Apr 24, 2020

Is it possible to start working on it?

@erickmp07
Copy link

@erickmp07 erickmp07 commented Apr 25, 2020

@MohamedBechir I'm working on it.
Sorry if I haven't created a PR yet, but this activity is part of my course evaluation.
My group scheduled a meeting for tomorrow qnd we're going to do this together.

@chitranshi21
Copy link

@chitranshi21 chitranshi21 commented May 4, 2020

Hi Can I take this one ?

@rjernst rjernst added the Team:QL label May 4, 2020
@erickmp07
Copy link

@erickmp07 erickmp07 commented May 5, 2020

Hi, @chitranshi21 .
My group developed the solution and we're creating the tests.
We're going to create the PR soon.

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 8, 2020

Hi, @erickmp07 saw that you're assigned to this issue two months ago. Are you still working on this? If not, please let me know, I would like to take it

@Anushka9833
Copy link

@Anushka9833 Anushka9833 commented Jun 15, 2020

Hi @erickmp07 , is this issue still available ? Can I please start working on it ?Please let me know

@erickmp07
Copy link

@erickmp07 erickmp07 commented Jun 15, 2020

Hi, @Anyrob and @Anushka9833 .
You can take it.
My group are implementing a refactoring to propose.

@matriv matriv assigned Anyrob and unassigned erickmp07 Jun 16, 2020
@matriv
Copy link
Contributor Author

@matriv matriv commented Jun 16, 2020

@Anyrob I've assigned you.

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 22, 2020

Hey @matriv! I was making some changes to the code but then I realized something. Would you mind being more specific in the difference of the DateTimeFormat with the DateFormat, I want to be sure that I'm on the right path, I discovered that my previous analysis looked a lot like the DatePart function, so this difference doesn't seem so trivial to me now, and I would like to make it clear before continuing :)

@matriv
Copy link
Contributor Author

@matriv matriv commented Jun 23, 2020

DATETIME_FORMAT uses the java's DateTimeFormatter patterns, whereas DATE_FORMAT will use the patterns as specified by MySQL, e.g.: %H denotes the 24-hour format where in java is HH. So the implementation should simply accept the MySQL patterns and translate them to the corresponding java ones.

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 23, 2020

Thank you! I think I got it now! I let you know in case I have another doubt.

@matriv
Copy link
Contributor Author

@matriv matriv commented Jun 23, 2020

@Anyrob There is a similar PR open that addresses the MS-SQL variant of the function, so you'll only need to add the new function definition, and a new Formatter to implement the MySQL variant.

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 25, 2020

Thank you @matriv I'm still working on it, I have a few doubts about the translation of specific symbols as:

  • For example, the "%U,%u,%V,%v" (MySQL) I'm replacing those as "w" (JAVA), am I right?
  • Also %f (Microseconds) has no proper translation, what should I do in that case?
@matriv
Copy link
Contributor Author

@matriv matriv commented Jun 25, 2020

  • For example, the "%U,%u,%V,%v" (MySQL) I'm replacing those as "w" (JAVA), am I right?

I'd say yes, but we need to properly document that they would all result in computing the week starting from Monday (If I remember correctly for Java's w).

  • Also %f (Microseconds) has no proper translation, what should I do in that case?

I think you can simply use S and for a MySQL pattern it will go up to 6 digits so 6 Ss.

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 25, 2020

Thank you @matriv! I keep you up to date

@Anyrob
Copy link

@Anyrob Anyrob commented Jun 29, 2020

Hey, @matriv! I just wanted to update you: I'm trying to write a test for my code based on DateTimeFormatProcessor. Today I'll make my PR, I would like that you could check it, to see If I have made the correct approach or if I need to make changes :)

Anyrob added a commit to Anyrob/elasticsearch that referenced this issue Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.