Skip to content

Commit e376c00

Browse files
committed
[FLINK-3580] [table] Add current time point functions
This closes apache#2441.
1 parent fb8f2c9 commit e376c00

File tree

9 files changed

+613
-2
lines changed

9 files changed

+613
-2
lines changed

docs/dev/table_api.md

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,8 @@ functionCall = composite , "." , functionIdentifier , [ "(" , [ expression , { "
981981

982982
atom = ( "(" , expression , ")" ) | literal | nullLiteral | fieldReference ;
983983

984+
fieldReference = "*" | identifier ;
985+
984986
nullLiteral = "Null(" , dataType , ")" ;
985987

986988
timeIntervalUnit = "YEAR" | "YEAR_TO_MONTH" | "MONTH" | "DAY" | "DAY_TO_HOUR" | "DAY_TO_MINUTE" | "DAY_TO_SECOND" | "HOUR" | "HOUR_TO_MINUTE" | "HOUR_TO_SECOND" | "MINUTE" | "MINUTE_TO_SECOND" | "SECOND" ;
@@ -989,7 +991,7 @@ timePointUnit = "YEAR" | "MONTH" | "DAY" | "HOUR" | "MINUTE" | "SECOND" | "QUART
989991

990992
{% endhighlight %}
991993

992-
Here, `literal` is a valid Java literal, `fieldReference` specifies a column in the data, and `functionIdentifier` specifies a supported scalar function. The
994+
Here, `literal` is a valid Java literal, `fieldReference` specifies a column in the data (or all columns if `*` is used), and `functionIdentifier` specifies a supported scalar function. The
993995
column names and function names follow Java identifier syntax. Expressions specified as Strings can also use prefix notation instead of suffix notation to call operators and functions.
994996

995997
If working with exact numeric values or large decimals is required, the Table API also supports Java's BigDecimal type. In the Scala Table API decimals can be defined by `BigDecimal("123456")` and in Java by appending a "p" for precise e.g. `123456p`.
@@ -1521,6 +1523,61 @@ TIMEPOINT.ceil(TIMEINTERVALUNIT)
15211523
</td>
15221524
</tr>
15231525

1526+
<tr>
1527+
<td>
1528+
{% highlight java %}
1529+
currentDate()
1530+
{% endhighlight %}
1531+
</td>
1532+
<td>
1533+
<p>Returns the current SQL date in UTC time zone.</p>
1534+
</td>
1535+
</tr>
1536+
1537+
<tr>
1538+
<td>
1539+
{% highlight java %}
1540+
currentTime()
1541+
{% endhighlight %}
1542+
</td>
1543+
<td>
1544+
<p>Returns the current SQL time in UTC time zone.</p>
1545+
</td>
1546+
</tr>
1547+
1548+
<tr>
1549+
<td>
1550+
{% highlight java %}
1551+
currentTimestamp()
1552+
{% endhighlight %}
1553+
</td>
1554+
<td>
1555+
<p>Returns the current SQL timestamp in UTC time zone.</p>
1556+
</td>
1557+
</tr>
1558+
1559+
<tr>
1560+
<td>
1561+
{% highlight java %}
1562+
localTime()
1563+
{% endhighlight %}
1564+
</td>
1565+
<td>
1566+
<p>Returns the current SQL time in local time zone.</p>
1567+
</td>
1568+
</tr>
1569+
1570+
<tr>
1571+
<td>
1572+
{% highlight java %}
1573+
localTimestamp()
1574+
{% endhighlight %}
1575+
</td>
1576+
<td>
1577+
<p>Returns the current SQL timestamp in local time zone.</p>
1578+
</td>
1579+
</tr>
1580+
15241581
</tbody>
15251582
</table>
15261583

@@ -1828,6 +1885,61 @@ TIMEPOINT.ceil(TimeIntervalUnit)
18281885
</td>
18291886
</tr>
18301887

1888+
<tr>
1889+
<td>
1890+
{% highlight scala %}
1891+
currentDate()
1892+
{% endhighlight %}
1893+
</td>
1894+
<td>
1895+
<p>Returns the current SQL date in UTC time zone.</p>
1896+
</td>
1897+
</tr>
1898+
1899+
<tr>
1900+
<td>
1901+
{% highlight scala %}
1902+
currentTime()
1903+
{% endhighlight %}
1904+
</td>
1905+
<td>
1906+
<p>Returns the current SQL time in UTC time zone.</p>
1907+
</td>
1908+
</tr>
1909+
1910+
<tr>
1911+
<td>
1912+
{% highlight scala %}
1913+
currentTimestamp()
1914+
{% endhighlight %}
1915+
</td>
1916+
<td>
1917+
<p>Returns the current SQL timestamp in UTC time zone.</p>
1918+
</td>
1919+
</tr>
1920+
1921+
<tr>
1922+
<td>
1923+
{% highlight scala %}
1924+
localTime()
1925+
{% endhighlight %}
1926+
</td>
1927+
<td>
1928+
<p>Returns the current SQL time in local time zone.</p>
1929+
</td>
1930+
</tr>
1931+
1932+
<tr>
1933+
<td>
1934+
{% highlight scala %}
1935+
localTimestamp()
1936+
{% endhighlight %}
1937+
</td>
1938+
<td>
1939+
<p>Returns the current SQL timestamp in local time zone.</p>
1940+
</td>
1941+
</tr>
1942+
18311943
</tbody>
18321944
</table>
18331945
</div>
@@ -2093,6 +2205,61 @@ CEIL(TIMEPOINT TO TIMEINTERVALUNIT)
20932205
</td>
20942206
</tr>
20952207

2208+
<tr>
2209+
<td>
2210+
{% highlight sql %}
2211+
CURRENT_DATE
2212+
{% endhighlight %}
2213+
</td>
2214+
<td>
2215+
<p>Returns the current SQL date in UTC time zone.</p>
2216+
</td>
2217+
</tr>
2218+
2219+
<tr>
2220+
<td>
2221+
{% highlight sql %}
2222+
CURRENT_TIME
2223+
{% endhighlight %}
2224+
</td>
2225+
<td>
2226+
<p>Returns the current SQL time in UTC time zone.</p>
2227+
</td>
2228+
</tr>
2229+
2230+
<tr>
2231+
<td>
2232+
{% highlight sql %}
2233+
CURRENT_TIMESTAMP
2234+
{% endhighlight %}
2235+
</td>
2236+
<td>
2237+
<p>Returns the current SQL timestamp in UTC time zone.</p>
2238+
</td>
2239+
</tr>
2240+
2241+
<tr>
2242+
<td>
2243+
{% highlight sql %}
2244+
LOCALTIME
2245+
{% endhighlight %}
2246+
</td>
2247+
<td>
2248+
<p>Returns the current SQL time in local time zone.</p>
2249+
</td>
2250+
</tr>
2251+
2252+
<tr>
2253+
<td>
2254+
{% highlight sql %}
2255+
LOCALTIMESTAMP
2256+
{% endhighlight %}
2257+
</td>
2258+
<td>
2259+
<p>Returns the current SQL timestamp in local time zone.</p>
2260+
</td>
2261+
</tr>
2262+
20962263
</tbody>
20972264
</table>
20982265
</div>

flink-libraries/flink-table/src/main/scala/org/apache/flink/api/scala/table/expressionDsl.scala

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,75 @@ trait ImplicitExpressionConversions {
402402
implicit def sqlTime2Literal(sqlTime: Time): Expression = Literal(sqlTime)
403403
implicit def sqlTimestamp2Literal(sqlTimestamp: Timestamp): Expression = Literal(sqlTimestamp)
404404
}
405+
406+
// ------------------------------------------------------------------------------------------------
407+
// Expressions with no parameters
408+
// ------------------------------------------------------------------------------------------------
409+
410+
/**
411+
* Returns the current SQL date in UTC time zone.
412+
*/
413+
object currentDate {
414+
415+
/**
416+
* Returns the current SQL date in UTC time zone.
417+
*/
418+
def apply(): Expression = {
419+
CurrentDate()
420+
}
421+
}
422+
423+
/**
424+
* Returns the current SQL time in UTC time zone.
425+
*/
426+
object currentTime {
427+
428+
/**
429+
* Returns the current SQL time in UTC time zone.
430+
*/
431+
def apply(): Expression = {
432+
CurrentTime()
433+
}
434+
}
435+
436+
/**
437+
* Returns the current SQL timestamp in UTC time zone.
438+
*/
439+
object currentTimestamp {
440+
441+
/**
442+
* Returns the current SQL timestamp in UTC time zone.
443+
*/
444+
def apply(): Expression = {
445+
CurrentTimestamp()
446+
}
447+
}
448+
449+
/**
450+
* Returns the current SQL time in local time zone.
451+
*/
452+
object localTime {
453+
454+
/**
455+
* Returns the current SQL time in local time zone.
456+
*/
457+
def apply(): Expression = {
458+
LocalTime()
459+
}
460+
}
461+
462+
/**
463+
* Returns the current SQL timestamp in local time zone.
464+
*/
465+
object localTimestamp {
466+
467+
/**
468+
* Returns the current SQL timestamp in local time zone.
469+
*/
470+
def apply(): Expression = {
471+
LocalTimestamp()
472+
}
473+
}
474+
475+
476+

0 commit comments

Comments
 (0)