@@ -1005,6 +1005,17 @@ public void testNotFoundFieldInNestedFunction() {
10051005 line 1:23: Unknown column [avg]""" , error ("from test | stats c = avg by missing + 1, not_found" ));
10061006 }
10071007
1008+ public void testMultipleAggsOutsideStats () {
1009+ assertEquals (
1010+ """
1011+ 1:71: aggregate function [avg(salary)] not allowed outside STATS command
1012+ line 1:96: aggregate function [median(emp_no)] not allowed outside STATS command
1013+ line 1:22: aggregate function [sum(salary)] not allowed outside STATS command
1014+ line 1:39: aggregate function [avg(languages)] not allowed outside STATS command""" ,
1015+ error ("from test | eval s = sum(salary), l = avg(languages) | where salary > avg(salary) and emp_no > median(emp_no)" )
1016+ );
1017+ }
1018+
10081019 public void testSpatialSort () {
10091020 String prefix = "ROW wkt = [\" POINT(42.9711 -14.7553)\" , \" POINT(75.8093 22.7277)\" ] | MV_EXPAND wkt " ;
10101021 assertEquals ("1:130: cannot sort on geo_point" , error (prefix + "| EVAL shape = TO_GEOPOINT(wkt) | limit 5 | sort shape" ));
@@ -2032,10 +2043,53 @@ public void testCategorizeWithFilteredAggregations() {
20322043 }
20332044
20342045 public void testSortByAggregate () {
2035- assertEquals ("1:18: Aggregate functions are not allowed in SORT [COUNT]" , error ("ROW a = 1 | SORT count(*)" ));
2036- assertEquals ("1:28: Aggregate functions are not allowed in SORT [COUNT]" , error ("ROW a = 1 | SORT to_string(count(*))" ));
2037- assertEquals ("1:22: Aggregate functions are not allowed in SORT [MAX]" , error ("ROW a = 1 | SORT 1 + max(a)" ));
2038- assertEquals ("1:18: Aggregate functions are not allowed in SORT [COUNT]" , error ("FROM test | SORT count(*)" ));
2046+ assertEquals ("1:18: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 | SORT count(*)" ));
2047+ assertEquals (
2048+ "1:28: aggregate function [count(*)] not allowed outside STATS command" ,
2049+ error ("ROW a = 1 | SORT to_string(count(*))" )
2050+ );
2051+ assertEquals ("1:22: aggregate function [max(a)] not allowed outside STATS command" , error ("ROW a = 1 | SORT 1 + max(a)" ));
2052+ assertEquals ("1:18: aggregate function [count(*)] not allowed outside STATS command" , error ("FROM test | SORT count(*)" ));
2053+ }
2054+
2055+ public void testFilterByAggregate () {
2056+ assertEquals ("1:19: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 | WHERE count(*) > 0" ));
2057+ assertEquals (
2058+ "1:29: aggregate function [count(*)] not allowed outside STATS command" ,
2059+ error ("ROW a = 1 | WHERE to_string(count(*)) IS NOT NULL" )
2060+ );
2061+ assertEquals ("1:23: aggregate function [max(a)] not allowed outside STATS command" , error ("ROW a = 1 | WHERE 1 + max(a) > 0" ));
2062+ assertEquals (
2063+ "1:24: aggregate function [min(languages)] not allowed outside STATS command" ,
2064+ error ("FROM employees | WHERE min(languages) > 2" )
2065+ );
2066+ }
2067+
2068+ public void testDissectByAggregate () {
2069+ assertEquals (
2070+ "1:21: aggregate function [min(first_name)] not allowed outside STATS command" ,
2071+ error ("from test | dissect min(first_name) \" %{foo}\" " )
2072+ );
2073+ assertEquals (
2074+ "1:21: aggregate function [avg(salary)] not allowed outside STATS command" ,
2075+ error ("from test | dissect avg(salary) \" %{foo}\" " )
2076+ );
2077+ }
2078+
2079+ public void testGrokByAggregate () {
2080+ assertEquals (
2081+ "1:18: aggregate function [max(last_name)] not allowed outside STATS command" ,
2082+ error ("from test | grok max(last_name) \" %{WORD:foo}\" " )
2083+ );
2084+ assertEquals (
2085+ "1:18: aggregate function [sum(salary)] not allowed outside STATS command" ,
2086+ error ("from test | grok sum(salary) \" %{WORD:foo}\" " )
2087+ );
2088+ }
2089+
2090+ public void testAggregateInRow () {
2091+ assertEquals ("1:13: aggregate function [count(*)] not allowed outside STATS command" , error ("ROW a = 1 + count(*)" ));
2092+ assertEquals ("1:9: aggregate function [avg(2)] not allowed outside STATS command" , error ("ROW a = avg(2)" ));
20392093 }
20402094
20412095 public void testLookupJoinDataTypeMismatch () {
0 commit comments