Skip to content

Commit e3f904b

Browse files
committed
Update documentation of stats to reflect that span can be used without specifying a field
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent c637bb2 commit e3f904b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

core/src/main/java/org/opensearch/sql/ast/expression/Span.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
@RequiredArgsConstructor
2121
@ToString
2222
public class Span extends UnresolvedExpression {
23+
/** When field is {@code null}, span implicitly refers to {@code @timestamp} field */
2324
@Nullable private final UnresolvedExpression field;
25+
2426
private final UnresolvedExpression value;
2527
private final SpanUnit unit;
2628

docs/user/ppl/cmd/stats.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ stats <aggregation>... [by-clause]
4545

4646
* span-expression: optional, at most one.
4747

48-
* Syntax: span(field_expr, interval_expr)
49-
* Description: The unit of the interval expression is the natural unit by default. If the field is a date and time type field, and the interval is in date/time units, you will need to specify the unit in the interval expression. For example, to split the field ``age`` into buckets by 10 years, it looks like ``span(age, 10)``. And here is another example of time span, the span to split a ``timestamp`` field into hourly intervals, it looks like ``span(timestamp, 1h)``.
48+
* Syntax: span([field_expr,] interval_expr)
49+
* Description: The unit of the interval expression is the natural unit by default. If ``field_expr`` is omitted, span will use the implicit ``@timestamp`` field. An error will be thrown if this field doesn't exist. If the field is a date and time type field, and the interval is in date/time units, you will need to specify the unit in the interval expression. For example, to split the field ``age`` into buckets by 10 years, it looks like ``span(age, 10)``. And here is another example of time span, the span to split a ``timestamp`` field into hourly intervals, it looks like ``span(timestamp, 1h)``.
5050

5151
* Available time unit:
5252
+----------------------------+
@@ -525,3 +525,17 @@ PPL query::
525525
| 36 | 30 | M |
526526
+-----+----------+--------+
527527

528+
Example 14: Calculate the count by the implicit @timestamp field
529+
================================================================
530+
531+
This example demonstrates that if you omit the field parameter in the span function, it will automatically use the implicit ``@timestamp`` field.
532+
533+
PPL query::
534+
535+
PPL> source=big5 | stats count() by span(1month)
536+
fetched rows / total rows = 1/1
537+
+---------+---------------------+
538+
| count() | span(1month) |
539+
|---------+---------------------|
540+
| 1 | 2023-01-01 00:00:00 |
541+
+---------+---------------------+

0 commit comments

Comments
 (0)