Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <taylor.curran@improving.com>
  • Loading branch information
currantw committed Jan 16, 2025
1 parent 282f3f6 commit 4fef581
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
9 changes: 6 additions & 3 deletions docs/ppl-lang/functions/ppl-datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,12 @@ made up of two optional components.
The special relative timestamp string `now`, corresponding to the current timestamp, is also supported.

The current timestamp is determined once at the start of query execution, and is used for all relative timestamp
calculations for that query. The Spark session time zone (`spark.sql.session.timeZone`) is used for determining
relative timestamps, and accounts for changes in the time zone offset (e.g. daylight savings time); as a result, adding
one day (`+1d`) is not the same as adding twenty-four hours (`+24h`).
calculations for that query. The Spark session time zone (`spark.sql.session.timeZone`) is used for determining relative
timestamps. Offsets using time units (seconds, minutes, or hours) represent a fixed time period; adding twenty-four
hours (`+24h`) will yield a timestamp that is exactly twenty-four hours later, but which may not have the same local
time (because of daylight savings, for example). Conversely, offsets using date units (days, weeks, months, quarters, or
years) do not represent a fixed time period; adding one day (`+1d`) will yield a timestamp with the same local time,
but which may not be exactly twenty-four hours later.

The relative timestamp string is case-insensitive.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,21 @@ public interface BuiltinFunctionTransformer {
// Relative time functions
.put(
RELATIVE_TIMESTAMP,
BuiltinFunctionTransformer::buildRelativeTimestampExpression)
args -> buildRelativeTimestamp(args.get(0)))
.put(
EARLIEST,
args ->
LessThanOrEqual$.MODULE$.apply(
buildRelativeTimestampExpression(List.of(args.get(0))),
args.get(1)))
args -> {
Expression relativeTimestamp = buildRelativeTimestamp(args.get(0));
Expression timestamp = args.get(1);
return LessThanOrEqual$.MODULE$.apply(relativeTimestamp, timestamp);
})
.put(
LATEST,
args ->
GreaterThanOrEqual$.MODULE$.apply(
buildRelativeTimestampExpression(List.of(args.get(0))),
args.get(1)))
args -> {
Expression relativeTimestamp = buildRelativeTimestamp(args.get(0));
Expression timestamp = args.get(1);
return GreaterThanOrEqual$.MODULE$.apply(relativeTimestamp, timestamp);
})
.build();

static Expression builtinFunction(org.opensearch.sql.ast.expression.Function function, List<Expression> args) {
Expand Down Expand Up @@ -237,9 +239,9 @@ static Expression[] createIntervalArgs(IntervalUnit unit, Expression value) {
return args;
}

private static Expression buildRelativeTimestampExpression(List<Expression> args) {
private static Expression buildRelativeTimestamp(Expression relativeStringExpression) {
return SerializableUdf.visit(
RELATIVE_TIMESTAMP.getName().getFunctionName(),
List.of(args.get(0), CurrentTimestamp$.MODULE$.apply(), CurrentTimeZone$.MODULE$.apply()));
List.of(relativeStringExpression, CurrentTimestamp$.MODULE$.apply(), CurrentTimeZone$.MODULE$.apply()));
}
}

0 comments on commit 4fef581

Please sign in to comment.