summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-10-27 20:04:05 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2017-11-01 23:17:15 +0530
commitab5503c8c5aca9c672db5ceb2c3636b598290a21 (patch)
tree9e3b1a3c6ba965f8791afe9735d5aa7a0a154c49
parent40887913ff4bb135d1b11495cd60c7a6f9402b8d (diff)
downloadmariadb-git-ab5503c8c5aca9c672db5ceb2c3636b598290a21.tar.gz
Updates the tests for the percentile functions
-rw-r--r--mysql-test/r/win_percentile.result469
-rw-r--r--mysql-test/t/percentile.test41
-rw-r--r--mysql-test/t/win_percentile.test55
-rw-r--r--sql/item_windowfunc.cc8
-rw-r--r--sql/item_windowfunc.h14
-rw-r--r--sql/sql_window.cc2
6 files changed, 298 insertions, 291 deletions
diff --git a/mysql-test/r/win_percentile.result b/mysql-test/r/win_percentile.result
index b365a995da0..c51e2e6bd51 100644
--- a/mysql-test/r/win_percentile.result
+++ b/mysql-test/r/win_percentile.result
@@ -4,58 +4,88 @@ INSERT INTO t1 VALUES
('Kaolin', 0.5, 3), ('Kaolin', 0.6, 7),
('Kaolin', 0.5, 4),
('Tatiana', 0.8, 4), ('Tata', 0.8, 4);
+#
+# Test invalid syntax
+#
+# Order by clause has more than one element
+select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1
+select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1
+# Order by clause has no element
+select percentile_disc(0.5) within group() over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') over (partition by name) from t1' at line 1
+select percentile_cont(0.5) within group() over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') over (partition by name) from t1' at line 1
+# No parameters to the percentile functions
+select percentile_disc() within group() over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') within group() over (partition by name) from t1' at line 1
+select percentile_cont() within group() over (partition by name) from t1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') within group() over (partition by name) from t1' at line 1
+#
+# Test simple syntax
+#
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
name c
-Chun 5.00000
-Chun 5.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
-no partition clause
+Chun 5.0000000000
+Chun 5.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
+select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
+name c
+Chun 3.0000000000
+Chun 3.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
+# no partition clause
select name, percentile_disc(0.5) within group(order by score) over () from t1;
name percentile_disc(0.5) within group(order by score) over ()
-Chun 4.00000
-Chun 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
+Chun 4.0000000000
+Chun 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
select name, percentile_cont(0.5) within group(order by score) over () from t1;
name percentile_cont(0.5) within group(order by score) over ()
-Chun 4.00000
-Chun 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
-argument set to null
+Chun 4.0000000000
+Chun 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
+# argument set to null
select name, percentile_cont(null) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Numeric values are only allowed as arguments to percentile functions
+ERROR HY000: percentile_cont function only accepts arguments that can be converted to numerical types
select name, percentile_disc(null) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Numeric values are only allowed as arguments to percentile functions
-subqueries having percentile functions
+ERROR HY000: percentile_disc function only accepts arguments that can be converted to numerical types
+#subqueries having percentile functions
select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
name percentile_cont(0.5) within group ( order by score) over (partition by name )
-Chun 5.00000
-Chun 5.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
+Chun 5.0000000000
+Chun 5.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
name percentile_disc(0.5) within group ( order by score) over (partition by name )
-Chun 3.00000
-Chun 3.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
+Chun 3.0000000000
+Chun 3.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5;
name
Chun
@@ -65,241 +95,232 @@ Kaolin
Kaolin
Tatiana
Tata
-disallowed fields in order by
+#disallowed fields in order by
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1;
-ERROR HY000: Numeric datatype is required for Percentile_CONT function
+ERROR HY000: Numeric datatype is required for percentile_cont function
select score, percentile_disc(0.5) within group(order by name) over (partition by score) from t1;
-score percentile_disc(0.5) within group(order by name) over (partition by score)
-3.0000 Chun
-7.0000 Chun
-3.0000 Chun
-7.0000 Chun
-4.0000 Tata
-4.0000 Tata
-4.0000 Tata
-order by clause has more than one element
-select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1
-select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'test) over (partition by name) from t1' at line 1
-parameter value should be in the range of [0,1]
+ERROR HY000: Numeric datatype is required for percentile_disc function
+#parameter value should be in the range of [0,1]
select percentile_disc(1.5) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Argument to the percentile functions does not belong to the range [0,1]
+ERROR HY000: Argument to the percentile_disc function does not belong to the range [0,1]
select percentile_cont(1.5) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Argument to the percentile functions does not belong to the range [0,1]
+ERROR HY000: Argument to the percentile_cont function does not belong to the range [0,1]
+#Argument should remain constant for the entire partition
select name,percentile_cont(test) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Argument to the percentile functions is not a constant
+ERROR HY000: Argument to the percentile_cont function is not a constant for a partition
select name, percentile_disc(test) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Argument to the percentile functions is not a constant
-only numerical types are allowed as argument to percentile functions
+ERROR HY000: Argument to the percentile_disc function is not a constant for a partition
+#only numerical types are allowed as argument to percentile functions
select name, percentile_cont(name) within group(order by score) over (partition by name) from t1;
-ERROR HY000: Numeric values are only allowed as arguments to percentile functions
-complete query with partition column
+ERROR HY000: percentile_cont function only accepts arguments that can be converted to numerical types
+select name, percentile_disc(name) within group(order by score) over (partition by name) from t1;
+ERROR HY000: percentile_disc function only accepts arguments that can be converted to numerical types
+#complete query with partition column
select name,cume_dist() over (partition by name order by score), percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
name cume_dist() over (partition by name order by score) c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 4.00000
-Kaolin 1.0000000000 4.00000
-Kaolin 0.6666666667 4.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 4.0000000000
+Kaolin 1.0000000000 4.0000000000
+Kaolin 0.6666666667 4.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
name c
-Chun 5.00000
-Chun 5.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Kaolin 4.00000
-Tatiana 4.00000
-Tata 4.00000
+Chun 5.0000000000
+Chun 5.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Kaolin 4.0000000000
+Tatiana 4.0000000000
+Tata 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.1) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 3.00000
-Kaolin 1.0000000000 3.00000
-Kaolin 0.6666666667 3.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 3.0000000000
+Kaolin 1.0000000000 3.0000000000
+Kaolin 0.6666666667 3.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.2) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 3.00000
-Kaolin 1.0000000000 3.00000
-Kaolin 0.6666666667 3.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 3.0000000000
+Kaolin 1.0000000000 3.0000000000
+Kaolin 0.6666666667 3.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.3) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 3.00000
-Kaolin 1.0000000000 3.00000
-Kaolin 0.6666666667 3.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 3.0000000000
+Kaolin 1.0000000000 3.0000000000
+Kaolin 0.6666666667 3.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.4) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 4.00000
-Kaolin 1.0000000000 4.00000
-Kaolin 0.6666666667 4.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 4.0000000000
+Kaolin 1.0000000000 4.0000000000
+Kaolin 0.6666666667 4.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 3.00000
-Chun 1.0000000000 3.00000
-Kaolin 0.3333333333 4.00000
-Kaolin 1.0000000000 4.00000
-Kaolin 0.6666666667 4.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 3.0000000000
+Chun 1.0000000000 3.0000000000
+Kaolin 0.3333333333 4.0000000000
+Kaolin 1.0000000000 4.0000000000
+Kaolin 0.6666666667 4.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.6) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 7.00000
-Chun 1.0000000000 7.00000
-Kaolin 0.3333333333 4.00000
-Kaolin 1.0000000000 4.00000
-Kaolin 0.6666666667 4.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 7.0000000000
+Chun 1.0000000000 7.0000000000
+Kaolin 0.3333333333 4.0000000000
+Kaolin 1.0000000000 4.0000000000
+Kaolin 0.6666666667 4.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.7) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 7.00000
-Chun 1.0000000000 7.00000
-Kaolin 0.3333333333 7.00000
-Kaolin 1.0000000000 7.00000
-Kaolin 0.6666666667 7.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 7.0000000000
+Chun 1.0000000000 7.0000000000
+Kaolin 0.3333333333 7.0000000000
+Kaolin 1.0000000000 7.0000000000
+Kaolin 0.6666666667 7.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.8) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 7.00000
-Chun 1.0000000000 7.00000
-Kaolin 0.3333333333 7.00000
-Kaolin 1.0000000000 7.00000
-Kaolin 0.6666666667 7.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 7.0000000000
+Chun 1.0000000000 7.0000000000
+Kaolin 0.3333333333 7.0000000000
+Kaolin 1.0000000000 7.0000000000
+Kaolin 0.6666666667 7.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.9) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 7.00000
-Chun 1.0000000000 7.00000
-Kaolin 0.3333333333 7.00000
-Kaolin 1.0000000000 7.00000
-Kaolin 0.6666666667 7.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 7.0000000000
+Chun 1.0000000000 7.0000000000
+Kaolin 0.3333333333 7.0000000000
+Kaolin 1.0000000000 7.0000000000
+Kaolin 0.6666666667 7.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(1) within group(order by score) over (partition by name) as c from t1;
name b c
-Chun 0.5000000000 7.00000
-Chun 1.0000000000 7.00000
-Kaolin 0.3333333333 7.00000
-Kaolin 1.0000000000 7.00000
-Kaolin 0.6666666667 7.00000
-Tatiana 1.0000000000 4.00000
-Tata 1.0000000000 4.00000
+Chun 0.5000000000 7.0000000000
+Chun 1.0000000000 7.0000000000
+Kaolin 0.3333333333 7.0000000000
+Kaolin 1.0000000000 7.0000000000
+Kaolin 0.6666666667 7.0000000000
+Tatiana 1.0000000000 4.0000000000
+Tata 1.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 3.00000
-5.00000 3.00000
-4.00000 3.00000
-4.00000 3.00000
-4.00000 3.00000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 3.0000000000
+5.0000000000 3.0000000000
+4.0000000000 3.0000000000
+4.0000000000 3.0000000000
+4.0000000000 3.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.1) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 3.40000
-5.00000 3.40000
-4.00000 3.20000
-4.00000 3.20000
-4.00000 3.20000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 3.4000000000
+5.0000000000 3.4000000000
+4.0000000000 3.2000000000
+4.0000000000 3.2000000000
+4.0000000000 3.2000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.2) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 3.80000
-5.00000 3.80000
-4.00000 3.40000
-4.00000 3.40000
-4.00000 3.40000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 3.8000000000
+5.0000000000 3.8000000000
+4.0000000000 3.4000000000
+4.0000000000 3.4000000000
+4.0000000000 3.4000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.3) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 4.20000
-5.00000 4.20000
-4.00000 3.60000
-4.00000 3.60000
-4.00000 3.60000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 4.2000000000
+5.0000000000 4.2000000000
+4.0000000000 3.6000000000
+4.0000000000 3.6000000000
+4.0000000000 3.6000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.4) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 4.60000
-5.00000 4.60000
-4.00000 3.80000
-4.00000 3.80000
-4.00000 3.80000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 4.6000000000
+5.0000000000 4.6000000000
+4.0000000000 3.8000000000
+4.0000000000 3.8000000000
+4.0000000000 3.8000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 5.00000
-5.00000 5.00000
-4.00000 4.00000
-4.00000 4.00000
-4.00000 4.00000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 5.0000000000
+5.0000000000 5.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.6) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 5.40000
-5.00000 5.40000
-4.00000 4.60000
-4.00000 4.60000
-4.00000 4.60000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 5.4000000000
+5.0000000000 5.4000000000
+4.0000000000 4.6000000000
+4.0000000000 4.6000000000
+4.0000000000 4.6000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.7) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 5.80000
-5.00000 5.80000
-4.00000 5.20000
-4.00000 5.20000
-4.00000 5.20000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 5.8000000000
+5.0000000000 5.8000000000
+4.0000000000 5.2000000000
+4.0000000000 5.2000000000
+4.0000000000 5.2000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.8) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 6.20000
-5.00000 6.20000
-4.00000 5.80000
-4.00000 5.80000
-4.00000 5.80000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 6.2000000000
+5.0000000000 6.2000000000
+4.0000000000 5.8000000000
+4.0000000000 5.8000000000
+4.0000000000 5.8000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0.9) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 6.60000
-5.00000 6.60000
-4.00000 6.40000
-4.00000 6.40000
-4.00000 6.40000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 6.6000000000
+5.0000000000 6.6000000000
+4.0000000000 6.4000000000
+4.0000000000 6.4000000000
+4.0000000000 6.4000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(1) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
-5.00000 7.00000
-5.00000 7.00000
-4.00000 7.00000
-4.00000 7.00000
-4.00000 7.00000
-4.00000 4.00000
-4.00000 4.00000
+5.0000000000 7.0000000000
+5.0000000000 7.0000000000
+4.0000000000 7.0000000000
+4.0000000000 7.0000000000
+4.0000000000 7.0000000000
+4.0000000000 4.0000000000
+4.0000000000 4.0000000000
drop table t1;
diff --git a/mysql-test/t/percentile.test b/mysql-test/t/percentile.test
deleted file mode 100644
index 0958fc05e7d..00000000000
--- a/mysql-test/t/percentile.test
+++ /dev/null
@@ -1,41 +0,0 @@
-CREATE TABLE student (name CHAR(10), test double, score TINYINT);
-
-INSERT INTO student VALUES
-('Chun', 0, null), ('Chun', 0, 4),
-('Esben', 1, null), ('Esben', 1, null),
-('Kaolin', 0.5, 56), ('Kaolin', 0.5, 88),
-('Tatiana', 0.8, 2), ('Tatiana', 0.8, 1);
-
-
-
-select name, percentile_disc(0.6) within group(order by score) over (partition by name) from student;
-select name, percentile_disc(test) within group(order by score) over (partition by name) from student;
-select name, percentile_disc(0.4) within group(order by score) over (partition by name) from student;
-
-
-#select name, percentile_cont(null) within group(order by score) over (partition by name) from student;
-#select name, cume_dist() over (partition by name order by score) from student;
-
-
-#normal parsing
-#select percentile_cont(0.5) within group(order by score) over w1 from student
-#window w1 AS (partition by name);
-
-# no partition clause
-#select percentile_cont(0.5) within group(order by score) over () from student;
-
-
-# only one sort allowed
-#select percentile_cont(0.5) within group(order by score) over (partition by name);
-
-#parameter value should be in the range of 0 to 1
-#select percentile_cont(1.5) within group(order by score) over (partition by name);
-
-
-#
-#select rank() over (partition by name order by score ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) from student;
-
-
-
-drop table student;
-
diff --git a/mysql-test/t/win_percentile.test b/mysql-test/t/win_percentile.test
index cab3478241c..468d8cff56b 100644
--- a/mysql-test/t/win_percentile.test
+++ b/mysql-test/t/win_percentile.test
@@ -5,50 +5,77 @@ INSERT INTO t1 VALUES
('Kaolin', 0.5, 4),
('Tatiana', 0.8, 4), ('Tata', 0.8, 4);
+--echo #
+--echo # Test invalid syntax
+--echo #
+
+--echo # Order by clause has more than one element
+--error ER_PARSE_ERROR
+select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1;
+--error ER_PARSE_ERROR
+select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1;
+
+--echo # Order by clause has no element
+--error ER_PARSE_ERROR
+select percentile_disc(0.5) within group() over (partition by name) from t1;
+--error ER_PARSE_ERROR
+select percentile_cont(0.5) within group() over (partition by name) from t1;
+
+--echo # No parameters to the percentile functions
+--error ER_PARSE_ERROR
+select percentile_disc() within group() over (partition by name) from t1;
+--error ER_PARSE_ERROR
+select percentile_cont() within group() over (partition by name) from t1;
+
+
+
+--echo #
+--echo # Test simple syntax
+--echo #
+
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
+select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
---echo no partition clause
+--echo # no partition clause
select name, percentile_disc(0.5) within group(order by score) over () from t1;
select name, percentile_cont(0.5) within group(order by score) over () from t1;
---echo argument set to null
+--echo # argument set to null
--error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_cont(null) within group(order by score) over (partition by name) from t1;
--error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_disc(null) within group(order by score) over (partition by name) from t1;
---echo subqueries having percentile functions
+--echo #subqueries having percentile functions
select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5;
---echo disallowed fields in order by
---error ER_WRONG_TYPE_FOR_PERCENTILE_CONT
+--echo #disallowed fields in order by
+--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1;
+--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC
select score, percentile_disc(0.5) within group(order by name) over (partition by score) from t1;
---echo order by clause has more than one element
---error ER_PARSE_ERROR
-select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1;
---error ER_PARSE_ERROR
-select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1;
-
---echo parameter value should be in the range of [0,1]
+--echo #parameter value should be in the range of [0,1]
--error ER_ARGUMENT_OUT_OF_RANGE
select percentile_disc(1.5) within group(order by score) over (partition by name) from t1;
--error ER_ARGUMENT_OUT_OF_RANGE
select percentile_cont(1.5) within group(order by score) over (partition by name) from t1;
+--echo #Argument should remain constant for the entire partition
--error ER_ARGUMENT_NOT_CONSTANT
select name,percentile_cont(test) within group(order by score) over (partition by name) from t1;
--error ER_ARGUMENT_NOT_CONSTANT
select name, percentile_disc(test) within group(order by score) over (partition by name) from t1;
---echo only numerical types are allowed as argument to percentile functions
+--echo #only numerical types are allowed as argument to percentile functions
--error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_cont(name) within group(order by score) over (partition by name) from t1;
+--error ER_WRONG_TYPE_OF_ARGUMENT
+select name, percentile_disc(name) within group(order by score) over (partition by name) from t1;
---echo complete query with partition column
+--echo #complete query with partition column
select name,cume_dist() over (partition by name order by score), percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index d38befa66bc..8432ab43ad8 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -174,11 +174,11 @@ bool Item_window_func::check_result_type_of_order_item()
if (only_single_element_order_list())
{
Item_result rtype= window_spec->order_list->first->item[0]->cmp_type();
- // TODO (varun) : support date type in percentile_cont function
+ // TODO (varun) : support date type in percentile_cont function
if (rtype != REAL_RESULT && rtype != INT_RESULT &&
rtype != DECIMAL_RESULT && rtype != TIME_RESULT)
{
- my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0));
+ my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name());
return TRUE;
}
setting_handler_for_percentile_functions(rtype);
@@ -249,7 +249,7 @@ bool Item_sum_percentile_cont::fix_fields(THD *thd, Item **ref)
case INT_RESULT:
break;
default:
- my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0));
+ my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0), func_name());
return TRUE;
}
return res;
@@ -268,7 +268,7 @@ bool Item_sum_percentile_disc::fix_fields(THD *thd, Item **ref)
case INT_RESULT:
break;
default:
- my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0));
+ my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0), func_name());
return TRUE;
}
return res;
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index a3056dc222a..849c298f5aa 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -786,7 +786,7 @@ public:
value->store(order_item);
value->cache_value();
if (value->null_value)
- return false;
+ return false;
Item_sum_cume_dist::add();
double val= Item_sum_cume_dist::val_real();
@@ -821,7 +821,7 @@ public:
void fix_length_and_dec()
{
- decimals = 5; // TODO-cvicentiu find out how many decimals the standard
+ decimals = 10; // TODO-cvicentiu find out how many decimals the standard
// requires.
}
@@ -904,24 +904,24 @@ public:
floor_value->store(order_item);
floor_value->cache_value();
if (floor_value->null_value)
- return false;
+ return false;
}
if (floor_val_calculated && !ceil_val_calculated)
{
ceil_value->store(order_item);
ceil_value->cache_value();
if (ceil_value->null_value)
- return false;
+ return false;
}
Item_sum_cume_dist::add();
double val= 1 + prev_value * (get_row_count()-1);
if (!floor_val_calculated && get_row_number() == floor(val))
- floor_val_calculated= true;
+ floor_val_calculated= true;
if (!ceil_val_calculated && get_row_number() == ceil(val))
- ceil_val_calculated= true;
+ ceil_val_calculated= true;
return false;
}
@@ -951,7 +951,7 @@ public:
void fix_length_and_dec()
{
- decimals = 5; // TODO-cvicentiu find out how many decimals the standard
+ decimals = 10; // TODO-cvicentiu find out how many decimals the standard
// requires.
}
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index 059dd8073f5..4bcdca3ca11 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -1765,7 +1765,7 @@ protected:
}
};
-class Frame_unbounded_following_set_count_no_nulls:
+class Frame_unbounded_following_set_count_no_nulls:
public Frame_unbounded_following_set_count
{