SQL: Implement TIME_PARSE function for parsing strings into TIME values (#55223)

Implement TIME_PARSE(<time_str>, <pattern_str>) function
which allows to parse a time string according to the specified
pattern into a time object. The patterns allowed are those of
java.time.format.DateTimeFormatter.

Closes #54963

Co-authored-by: Andrei Stefan <astefan@users.noreply.github.com>
Co-authored-by: Marios Trivyzas <matriv@users.noreply.github.com>
This commit is contained in:
Patrick Jiang(白泽) 2020-05-29 16:43:49 +08:00 committed by GitHub
parent d26f63d062
commit 1fe1188d44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 599 additions and 110 deletions

View file

@ -496,6 +496,56 @@ include-tagged::{sql-specs}/docs/docs.csv-spec[dateTimeParse3]
--------------------------------------------------
====
[[sql-functions-datetime-timeparse]]
==== `TIME_PARSE`
.Synopsis:
[source, sql]
--------------------------------------------------
TIME_PARSE(
string_exp, <1>
string_exp) <2>
--------------------------------------------------
*Input*:
<1> time expression as a string
<2> parsing pattern
*Output*: time
*Description*: Returns a time by parsing the 1st argument using the format specified in the 2nd argument. The parsing
format pattern used is the one from
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/time/format/DateTimeFormatter.html[`java.time.format.DateTimeFormatter`].
If any of the two arguments is `null` or an empty string `null` is returned.
[NOTE]
If the parsing pattern contains date units (e.g. 'dd/MM/uuuu', 'dd-MM HH:mm:ss', etc.) an error is returned
as the function needs to return a value of `time` type which will contain only time.
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[timeParse1]
--------------------------------------------------
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[timeParse2]
--------------------------------------------------
[NOTE]
====
If timezone is not specified in the time string expression and the parsing pattern,
the resulting `time` will have the offset of the time zone specified by the user through the
<<sql-rest-fields-timezone,`time_zone`>>/<<jdbc-cfg-timezone,`timezone`>> REST/driver
parameters at the Unix epoch date (`1970-01-01`) with no conversion applied.
[source, sql]
--------------------------------------------------
include-tagged::{sql-specs}/docs/docs.csv-spec[timeParse3]
--------------------------------------------------
====
[[sql-functions-datetime-part]]
==== `DATE_PART/DATEPART`

View file

@ -55,6 +55,7 @@
** <<sql-functions-datetime-diff>>
** <<sql-functions-datetime-datetimeformat>>
** <<sql-functions-datetime-datetimeparse>>
** <<sql-functions-datetime-timeparse>>
** <<sql-functions-datetime-part>>
** <<sql-functions-datetime-trunc>>
** <<sql-functions-datetime-day>>
@ -91,7 +92,7 @@
** <<sql-functions-math-log10>>
** <<sql-functions-math-pi>>
** <<sql-functions-math-power>>
** <<sql-functions-math-random>>
** <<sql-functions-math-random>>
** <<sql-functions-math-round>>
** <<sql-functions-math-sign>>
** <<sql-functions-math-sqrt>>