Skip to content

Commit 2bcb669

Browse files
committed
Update doc and integ tests
1 parent 0faf4f6 commit 2bcb669

File tree

5 files changed

+174
-153
lines changed

5 files changed

+174
-153
lines changed

docs/ppl-lang/functions/ppl-datetime.md

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -411,30 +411,15 @@ Return type: BOOLEAN
411411

412412
Example:
413413

414-
os> source=people | eval earliest = earliest("-1s", now()) | fields earliest | head 1
414+
os> source=relative_timestamp | eval timestamp = relative_timestamp(relative_string) | where earliest("now",timestamp) | sort timestamp | fields description, relative_string
415415
fetched rows / total rows = 1/1
416-
+----------+
417-
| earliest |
418-
|----------|
419-
| True |
420-
+----------+
421-
422-
os> source=people | eval earliest = earliest("now", now()) | fields earliest | head 1
423-
fetched rows / total rows = 1/1
424-
+----------+
425-
| earliest |
426-
|----------|
427-
| True |
428-
+----------+
429-
430-
os> source=people | eval earliest = earliest("+1s", now()) | fields earliest | head 1
431-
fetched rows / total rows = 1/1
432-
+----------+
433-
| earliest |
434-
|----------|
435-
| False |
436-
+----------+
437-
416+
+--------------+-----------------+
417+
| description | relative_string |
418+
+--------------+-----------------+
419+
| Now | NOW |
420+
| Tomorrow | +D@D |
421+
| In one month | +month |
422+
+--------------+-----------------+
438423

439424
### `FROM_UNIXTIME`
440425

@@ -560,29 +545,15 @@ Return type: BOOLEAN
560545

561546
Example:
562547

563-
os> source=people | eval latest = latest("-1s", now()) | fields latest | head 1
564-
fetched rows / total rows = 1/1
565-
+--------+
566-
| latest |
567-
|--------|
568-
| False |
569-
+--------+
570-
571-
os> source=people | eval latest = latest("now", now()) | fields latest | head 1
572-
fetched rows / total rows = 1/1
573-
+--------+
574-
| latest |
575-
|--------|
576-
| True |
577-
+--------+
578-
579-
os> source=people | eval latest = latest("+1s", now()) | fields latest | head 1
548+
os> source=relative_timestamp | eval timestamp = relative_timestamp(relative_string) | where latest("now",timestamp) | sort timestamp | fields description, relative_string
580549
fetched rows / total rows = 1/1
581-
+--------+
582-
| latest |
583-
|--------|
584-
| True |
585-
+--------+
550+
+---------------+-----------------+
551+
| description | relative_string |
552+
+---------------+-----------------+
553+
| Two weeks ago | -2wk |
554+
| Yesterday | -1d@d |
555+
| Now | NOW |
556+
+---------------+-----------------+
586557

587558

588559
### `LOCALTIMESTAMP`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"index": {"_index": "relative_datetime"}}
2+
{"description": "Now", "relative_string": "NOW"}
3+
{"index": {"_index": "relative_datetime"}}
4+
{"description": "Tomorrow", "relative_string": "+D@D"}
5+
{"index": {"_index": "relative_datetime"}}
6+
{"description": "In one month", "relative_string": "+month"}
7+
{"index": {"_index": "relative_datetime"}}
8+
{"description": "Two weeks ago", "relative_string": "-2wk"}
9+
{"index": {"_index": "relative_datetime"}}
10+
{"description": "Yesterday", "relative_string": "-1d@d"}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"mappings": {
3+
"properties": {
4+
"description": {
5+
"type": "text"
6+
},
7+
"relative_string": {
8+
"type": "text"
9+
}
10+
}
11+
}
12+
}

integ-test/src/integration/scala/org/opensearch/flint/spark/FlintSparkSuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ trait FlintSparkSuite extends QueryTest with FlintSuite with OpenSearchSuite wit
229229
| """.stripMargin)
230230
}
231231

232+
protected def createRelativeDateTimeTable(testTable: String): Unit = {
233+
sql(s"""
234+
| CREATE TABLE $testTable
235+
| (
236+
| description STRING,
237+
| relative_string STRING
238+
| )
239+
| USING $tableType $tableOptions
240+
|""".stripMargin)
241+
242+
sql(s"""
243+
| INSERT INTO $testTable
244+
| VALUES ('Now', 'NOW'),
245+
| ('Tomorrow', '+D@D'),
246+
| ('In one month', '+month'),
247+
| ('Two weeks ago', '-2wk'),
248+
| ('Yesterday', '-1d@d')
249+
| """.stripMargin)
250+
}
251+
232252
protected def createNullableStateCountryTable(testTable: String): Unit = {
233253
sql(s"""
234254
| CREATE TABLE $testTable

0 commit comments

Comments
 (0)