Skip to content

Commit 4fef581

Browse files
committed
Address review comments
Signed-off-by: currantw <taylor.curran@improving.com>
1 parent 282f3f6 commit 4fef581

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,12 @@ made up of two optional components.
831831
The special relative timestamp string `now`, corresponding to the current timestamp, is also supported.
832832

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

838841
The relative timestamp string is case-insensitive.
839842

ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/BuiltinFunctionTransformer.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,21 @@ public interface BuiltinFunctionTransformer {
182182
// Relative time functions
183183
.put(
184184
RELATIVE_TIMESTAMP,
185-
BuiltinFunctionTransformer::buildRelativeTimestampExpression)
185+
args -> buildRelativeTimestamp(args.get(0)))
186186
.put(
187187
EARLIEST,
188-
args ->
189-
LessThanOrEqual$.MODULE$.apply(
190-
buildRelativeTimestampExpression(List.of(args.get(0))),
191-
args.get(1)))
188+
args -> {
189+
Expression relativeTimestamp = buildRelativeTimestamp(args.get(0));
190+
Expression timestamp = args.get(1);
191+
return LessThanOrEqual$.MODULE$.apply(relativeTimestamp, timestamp);
192+
})
192193
.put(
193194
LATEST,
194-
args ->
195-
GreaterThanOrEqual$.MODULE$.apply(
196-
buildRelativeTimestampExpression(List.of(args.get(0))),
197-
args.get(1)))
195+
args -> {
196+
Expression relativeTimestamp = buildRelativeTimestamp(args.get(0));
197+
Expression timestamp = args.get(1);
198+
return GreaterThanOrEqual$.MODULE$.apply(relativeTimestamp, timestamp);
199+
})
198200
.build();
199201

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

240-
private static Expression buildRelativeTimestampExpression(List<Expression> args) {
242+
private static Expression buildRelativeTimestamp(Expression relativeStringExpression) {
241243
return SerializableUdf.visit(
242244
RELATIVE_TIMESTAMP.getName().getFunctionName(),
243-
List.of(args.get(0), CurrentTimestamp$.MODULE$.apply(), CurrentTimeZone$.MODULE$.apply()));
245+
List.of(relativeStringExpression, CurrentTimestamp$.MODULE$.apply(), CurrentTimeZone$.MODULE$.apply()));
244246
}
245247
}

0 commit comments

Comments
 (0)