Skip to content

Commit

Permalink
Review comments: add more documentation, add ignored tests for earlie…
Browse files Browse the repository at this point in the history
…st and latest.

Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Jan 9, 2025
1 parent a117ba2 commit 6eb2b60
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/ppl-lang/PPL-Example-Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,9 @@ _- **Limitation: another command usage of (relation) subquery is in `appendcols`
- `source = table | eval cdate = CAST('2012-08-07' as date), ctime = cast('2012-08-07T08:07:06' as timestamp) | fields cdate, ctime`
- `source = table | eval chained_cast = cast(cast("true" as boolean) as integer) | fields chained_cast`

#### **relative_timestamp**
[See additional function details](functions/ppl-datetime#RELATIVE_TIMESTAMP)
- `source = table | eval one_hour_ago = relative_timestamp("-1h") | where timestamp < one_hour_ago`
- `source = table | eval start_of_today = relative_timestamp("@d") | where timestamp > start_of_today`
- `source = table | eval last_saturday = relative_timestamp("-1d@w6") | where timestamp >= last_saturday`
---
1 change: 1 addition & 0 deletions docs/ppl-lang/ppl-where-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ PPL query:
| eval factor = case(a > 15, a - 14, isnull(b), a - 7, a < 3, a + 1 else 1)
| where case(factor = 2, 'even', factor = 4, 'even', factor = 6, 'even', factor = 8, 'even' else 'odd') = 'even'
| stats count() by factor`
- `source = table | where timestamp >= relative_timestamp("-1d@w6")`
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,32 @@ class FlintSparkPPLBuiltInDateTimeFunctionITSuite
assertSameRows(Seq(Row(1)), frame)
}

// TODO #957: Support earliest
ignore("test EARLIEST") {
var frame = sql(s"""
| source = $testTable
| | eval earliest_hour_before = earliest(now(), "-1h")
| | eval earliest_now = earliest(now(), "now")
| | eval earliest_hour_after = earliest(now(), "+1h")
| | fields earliest_hour_before, earliest_now, earliest_hour_after
| | head 1
| """.stripMargin)
assertSameRows(Seq(Row(true), Row(true), Row(false)), frame)
}

// TODO #957: Support latest
ignore("test LATEST") {
var frame = sql(s"""
| source = $testTable
| | eval latest_hour_before = latest(now(), "-1h")
| | eval latest_now = latest(now(), "now")
| | eval latest_hour_after = latest(now(), "+1h")
| | fields latest_hour_before, latest_now, latest_hour_after
| | head 1
| """.stripMargin)
assertSameRows(Seq(Row(false), Row(true), Row(true)), frame)
}

test("test CURRENT_TIME is not supported") {
val ex = intercept[UnsupportedOperationException](sql(s"""
| source = $testTable
Expand Down

0 comments on commit 6eb2b60

Please sign in to comment.