@@ -1014,6 +1014,17 @@ public void testNotFoundFieldInNestedFunction() {
10141014 line 1:23: Unknown column [avg]""" , error ("from test | stats c = avg by missing + 1, not_found" ));
10151015 }
10161016
1017+ public void testMultipleAggsOutsideStats () {
1018+ assertEquals (
1019+ """
1020+ 1:71: aggregate function [avg(salary)] not allowed outside STATS command
1021+ line 1:96: aggregate function [median(emp_no)] not allowed outside STATS command
1022+ line 1:22: aggregate function [sum(salary)] not allowed outside STATS command
1023+ line 1:39: aggregate function [avg(languages)] not allowed outside STATS command""" ,
1024+ error ("from test | eval s = sum(salary), l = avg(languages) | where salary > avg(salary) and emp_no > median(emp_no)" )
1025+ );
1026+ }
1027+
10171028 public void testSpatialSort () {
10181029 String prefix = "ROW wkt = [\" POINT(42.9711 -14.7553)\" , \" POINT(75.8093 22.7277)\" ] | MV_EXPAND wkt " ;
10191030 assertEquals ("1:130: cannot sort on geo_point" , error (prefix + "| EVAL shape = TO_GEOPOINT(wkt) | limit 5 | sort shape" ));
@@ -2107,10 +2118,53 @@ public void testChangePoint_valueNumeric() {
21072118 }
21082119
21092120 public void testSortByAggregate () {
2110- assertEquals ("1:18: Aggregate functions are not allowed in SORT [COUNT]" , error ("ROW a = 1 | SORT count(*)" ));
2111- assertEquals ("1:28: Aggregate functions are not allowed in SORT [COUNT]" , error ("ROW a = 1 | SORT to_string(count(*))" ));
2112- assertEquals ("1:22: Aggregate functions are not allowed in SORT [MAX]" , error ("ROW a = 1 | SORT 1 + max(a)" ));
2113- assertEquals ("1:18: Aggregate functions are not allowed in SORT [COUNT]" , error ("FROM test | SORT count(*)" ));
2121+ assertEquals ("1:18: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 | SORT count(*)" ));
2122+ assertEquals (
2123+ "1:28: aggregate function [count(*)] not allowed outside STATS command" ,
2124+ error ("ROW a = 1 | SORT to_string(count(*))" )
2125+ );
2126+ assertEquals ("1:22: aggregate function [max(a)] not allowed outside STATS command" , error ("ROW a = 1 | SORT 1 + max(a)" ));
2127+ assertEquals ("1:18: aggregate function [count(*)] not allowed outside STATS command" , error ("FROM test | SORT count(*)" ));
2128+ }
2129+
2130+ public void testFilterByAggregate () {
2131+ assertEquals ("1:19: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 | WHERE count(*) > 0" ));
2132+ assertEquals (
2133+ "1:29: aggregate function [count(*)] not allowed outside STATS command" ,
2134+ error ("ROW a = 1 | WHERE to_string(count(*)) IS NOT NULL" )
2135+ );
2136+ assertEquals ("1:23: aggregate function [max(a)] not allowed outside STATS command" , error ("ROW a = 1 | WHERE 1 + max(a) > 0" ));
2137+ assertEquals (
2138+ "1:24: aggregate function [min(languages)] not allowed outside STATS command" ,
2139+ error ("FROM employees | WHERE min(languages) > 2" )
2140+ );
2141+ }
2142+
2143+ public void testDissectByAggregate () {
2144+ assertEquals (
2145+ "1:21: aggregate function [min(first_name)] not allowed outside STATS command" ,
2146+ error ("from test | dissect min(first_name) \" %{foo}\" " )
2147+ );
2148+ assertEquals (
2149+ "1:21: aggregate function [avg(salary)] not allowed outside STATS command" ,
2150+ error ("from test | dissect avg(salary) \" %{foo}\" " )
2151+ );
2152+ }
2153+
2154+ public void testGrokByAggregate () {
2155+ assertEquals (
2156+ "1:18: aggregate function [max(last_name)] not allowed outside STATS command" ,
2157+ error ("from test | grok max(last_name) \" %{WORD:foo}\" " )
2158+ );
2159+ assertEquals (
2160+ "1:18: aggregate function [sum(salary)] not allowed outside STATS command" ,
2161+ error ("from test | grok sum(salary) \" %{WORD:foo}\" " )
2162+ );
2163+ }
2164+
2165+ public void testAggregateInRow () {
2166+ assertEquals ("1:13: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 + count(*)" ));
2167+ assertEquals ("1:9: aggregate function [avg(2)] not allowed outside STATS command" , error ("ROW a = avg(2)" ));
21142168 }
21152169
21162170 public void testLookupJoinDataTypeMismatch () {
0 commit comments