@@ -397,6 +397,44 @@ Example:
397397 +-------------------------------+
398398
399399
400+ ### ` EARLIEST `
401+
402+ ** Description:**
403+
404+ ** Usage:** earliest(string, timestamp) returns whether the timestamp defined by the given relative string is earlier
405+ than or at the same time as the specified timestamp.
406+
407+ Argument type: STRING, TIMESTAMP
408+
409+ Return type: BOOLEAN
410+
411+ Example:
412+
413+ os> source=people | eval earliest = earliest("-1s", now()) | fields earliest | head 1
414+ fetched rows / total rows = 1/1
415+ +----------+
416+ | earliest |
417+ |----------|
418+ | True |
419+ +----------+
420+
421+ os> source=people | eval earliest = earliest("now", now()) | fields earliest | head 1
422+ fetched rows / total rows = 1/1
423+ +----------+
424+ | earliest |
425+ |----------|
426+ | True |
427+ +----------+
428+
429+ os> source=people | eval earliest = earliest("+1s", now()) | fields earliest | head 1
430+ fetched rows / total rows = 1/1
431+ +----------+
432+ | earliest |
433+ |----------|
434+ | False |
435+ +----------+
436+
437+
400438### ` FROM_UNIXTIME `
401439
402440** Description:**
@@ -507,6 +545,44 @@ Example:
507545 +--------------------------+
508546
509547
548+ ### ` LATEST `
549+
550+ ** Description:**
551+
552+ ** Usage:** latest(string, timestamp) returns whether the timestamp defined by the given relative string is later
553+ than or at the same time as the specified timestamp. See [ relative_timestamp] ( #relative_timestamp ) for more details.
554+
555+ Argument type: STRING, TIMESTAMP
556+
557+ Return type: BOOLEAN
558+
559+ Example:
560+
561+ os> source=people | eval latest = latest("-1s", now()) | fields latest | head 1
562+ fetched rows / total rows = 1/1
563+ +--------+
564+ | latest |
565+ |--------|
566+ | False |
567+ +--------+
568+
569+ os> source=people | eval latest = latest("now", now()) | fields latest | head 1
570+ fetched rows / total rows = 1/1
571+ +--------+
572+ | latest |
573+ |--------|
574+ | True |
575+ +--------+
576+
577+ os> source=people | eval latest = latest("+1s", now()) | fields latest | head 1
578+ fetched rows / total rows = 1/1
579+ +--------+
580+ | latest |
581+ |--------|
582+ | True |
583+ +--------+
584+
585+
510586### ` LOCALTIMESTAMP `
511587
512588** Description:**
@@ -738,7 +814,7 @@ Example:
738814** Description:**
739815
740816
741- ** Usage:** relative_timestamp(str ) returns a relative timestamp corresponding to the given relative string and the
817+ ** Usage:** relative_timestamp(string ) returns a relative timestamp corresponding to the given relative string and the
742818current timestamp at the time of query execution.
743819
744820The relative timestamp string has syntax ` [+|-]<offset_time_integer><offset_time_unit>@<snap_time_unit> ` , and is
@@ -750,9 +826,12 @@ made up of two optional components.
750826 specified), and rounds the time <i >down</i > to the start of the specified time unit. For example, ` @wk ` is the start
751827 of the current week (Sunday is considered to be the first day of the week).
752828
753- The special relative timestamp string ` now ` , corresponding to the current timestamp, is also supported. The current
754- timestamp is determined once at the start of query execution, and is used for all relative timestamp calculations for
755- that query.
829+ The special relative timestamp string ` now ` , corresponding to the current timestamp, is also supported.
830+
831+ The current timestamp is determined once at the start of query execution, and is used for all relative timestamp
832+ calculations for that query. The Spark session time zone (` spark.sql.session.timeZone ` ) is used for determining
833+ relative timestamps, and accounts for changes in the time zone offset (e.g. daylight savings time); as a result, adding
834+ one day (` +1d ` ) is not the same as adding twenty-four hours (` +24h ` ).
756835
757836The relative timestamp string is case-insensitive.
758837
0 commit comments