Skip to content

Commit 5849d9f

Browse files
committed
Span expression should always be first in by list if exist
Signed-off-by: penghuo <penghuo@gmail.com>
1 parent f186d04 commit 5849d9f

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

docs/user/ppl/cmd/stats.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ stats <aggregation>... [by-clause]
3939

4040
* by-clause: optional.
4141

42-
* Syntax: by [field]... [span-expression].
42+
* Syntax: by [span-expression,] [field,]...
4343
* Description: The by clause could be the fields and expressions like scalar functions and aggregation functions. Besides, the span clause can be used to split specific field into buckets in the same interval, the stats then does the aggregation by these span buckets.
4444
* Default: If no <by-clause> is specified, the stats command returns only one row, which is the aggregation over the entire result set.
4545

@@ -372,7 +372,7 @@ The example gets the count of age by the interval of 10 years and group by gende
372372

373373
PPL query::
374374

375-
os> source=accounts | stats count() as cnt by gender span(age, 5) as age_span
375+
os> source=accounts | stats count() as cnt by span(age, 5) as age_span, gender
376376
fetched rows / total rows = 3/3
377377
+-------+------------+----------+
378378
| cnt | age_span | gender |

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ byClause
101101
statsByClause
102102
: BY fieldList
103103
| BY bySpanClause
104-
| BY fieldList bySpanClause
104+
| BY bySpanClause COMMA fieldList
105105
;
106106

107107
bySpanClause

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void testStatsCommandWithSpan() {
294294
defaultStatsArgs()
295295
));
296296

297-
assertEqual("source=t | stats avg(price) by b span(timestamp, 1h)",
297+
assertEqual("source=t | stats avg(price) by span(timestamp, 1h), b",
298298
agg(
299299
relation("t"),
300300
exprList(
@@ -306,7 +306,7 @@ public void testStatsCommandWithSpan() {
306306
defaultStatsArgs()
307307
));
308308

309-
assertEqual("source=t | stats avg(price) by f1, f2 span(timestamp, 1h)",
309+
assertEqual("source=t | stats avg(price) by span(timestamp, 1h), f1, f2",
310310
agg(
311311
relation("t"),
312312
exprList(

0 commit comments

Comments
 (0)