Commit 33b839b2 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-20280 PERCENTILE_DISC() rejects temporal and string input

parent f22093ad
......@@ -99,7 +99,14 @@ Tatiana
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
select score, percentile_disc(0.5) within group(order by name) over (partition by score) from t1;
ERROR HY000: Numeric datatype is required for percentile_disc function
score percentile_disc(0.5) within group(order by name) over (partition by score)
3.0000 Chun
3.0000 Chun
4.0000 Tata
4.0000 Tata
4.0000 Tata
7.0000 Chun
7.0000 Chun
#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_disc function does not belong to the range [0,1]
......@@ -452,7 +459,7 @@ Lord of the Ladybirds 30000000000.00
Lord of the Ladybirds 30000000000.00
DROP TABLE t2, t1;
#
# MDEV-20272 PERCENTILE_DISC() crashes on a temporal type input
# MDEV-20280 PERCENTILE_DISC() rejects temporal and string input
#
CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating TIME);
INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5);
......@@ -463,5 +470,28 @@ INSERT INTO t1 VALUES ('Lady of the Flies', 5);
SELECT name, PERCENTILE_DISC(0.5)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
ERROR HY000: Numeric datatype is required for percentile_disc function
name pc
Lady of the Flies 00:00:02
Lady of the Flies 00:00:02
Lady of the Flies 00:00:02
Lord of the Ladybirds 00:00:03
Lord of the Ladybirds 00:00:03
SELECT name, PERCENTILE_DISC(0)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
name pc
Lady of the Flies 00:00:01
Lady of the Flies 00:00:01
Lady of the Flies 00:00:01
Lord of the Ladybirds 00:00:03
Lord of the Ladybirds 00:00:03
SELECT name, PERCENTILE_DISC(1)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
name pc
Lady of the Flies 00:00:05
Lady of the Flies 00:00:05
Lady of the Flies 00:00:05
Lord of the Ladybirds 00:00:05
Lord of the Ladybirds 00:00:05
DROP TABLE t1;
......@@ -61,7 +61,7 @@ select name from t1 a where (select percentile_disc(0.5) within group (order by
--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 #parameter value should be in the range of [0,1]
......@@ -212,7 +212,7 @@ DROP TABLE t2, t1;
--echo #
--echo # MDEV-20272 PERCENTILE_DISC() crashes on a temporal type input
--echo # MDEV-20280 PERCENTILE_DISC() rejects temporal and string input
--echo #
CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating TIME);
......@@ -221,8 +221,13 @@ INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3);
INSERT INTO t1 VALUES ('Lady of the Flies', 1);
INSERT INTO t1 VALUES ('Lady of the Flies', 2);
INSERT INTO t1 VALUES ('Lady of the Flies', 5);
--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC
SELECT name, PERCENTILE_DISC(0.5)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
SELECT name, PERCENTILE_DISC(0)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
SELECT name, PERCENTILE_DISC(1)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
DROP TABLE t1;
......@@ -2021,3 +2021,40 @@ b ::1
DROP TABLE t2;
DROP TABLE t1;
DROP FUNCTION aggregate_min_inet6;
#
# MDEV-20280 PERCENTILE_DISC() rejects temporal and string input
#
CREATE TABLE t1 (name CHAR(30), star_rating INET6);
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::5');
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::3');
INSERT INTO t1 VALUES ('Lady of the Flies', '::1');
INSERT INTO t1 VALUES ('Lady of the Flies', '::2');
INSERT INTO t1 VALUES ('Lady of the Flies', '::5');
SELECT name, PERCENTILE_DISC(0.5)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
name pc
Lady of the Flies ::2
Lady of the Flies ::2
Lady of the Flies ::2
Lord of the Ladybirds ::3
Lord of the Ladybirds ::3
SELECT name, PERCENTILE_DISC(0)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
name pc
Lady of the Flies ::1
Lady of the Flies ::1
Lady of the Flies ::1
Lord of the Ladybirds ::3
Lord of the Ladybirds ::3
SELECT name, PERCENTILE_DISC(1)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
name pc
Lady of the Flies ::5
Lady of the Flies ::5
Lady of the Flies ::5
Lord of the Ladybirds ::5
Lord of the Ladybirds ::5
DROP TABLE t1;
......@@ -1494,3 +1494,25 @@ DROP TABLE t2;
DROP TABLE t1;
DROP FUNCTION aggregate_min_inet6;
--echo #
--echo # MDEV-20280 PERCENTILE_DISC() rejects temporal and string input
--echo #
CREATE TABLE t1 (name CHAR(30), star_rating INET6);
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::5');
INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::3');
INSERT INTO t1 VALUES ('Lady of the Flies', '::1');
INSERT INTO t1 VALUES ('Lady of the Flies', '::2');
INSERT INTO t1 VALUES ('Lady of the Flies', '::5');
SELECT name, PERCENTILE_DISC(0.5)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
SELECT name, PERCENTILE_DISC(0)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
SELECT name, PERCENTILE_DISC(1)
WITHIN GROUP (ORDER BY star_rating)
OVER (PARTITION BY name) AS pc FROM t1;
DROP TABLE t1;
......@@ -187,13 +187,6 @@ bool Item_window_func::check_result_type_of_order_item()
case Item_sum::PERCENTILE_DISC_FUNC:
{
Item *src_item= window_spec->order_list->first->item[0];
Item_result rtype= src_item->cmp_type();
// TODO-10.5: Fix MDEV-20280 PERCENTILE_DISC() rejects temporal and string input
if (rtype != REAL_RESULT && rtype != INT_RESULT && rtype != DECIMAL_RESULT)
{
my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name());
return true;
}
Item_sum_percentile_disc *func=
static_cast<Item_sum_percentile_disc*>(window_func());
func->set_handler(src_item->type_handler());
......
......@@ -779,12 +779,23 @@ class Item_sum_percentile_disc : public Item_sum_num,
if (get_row_count() == 0 || get_arg(0)->is_null())
{
null_value= true;
return 0;
return true;
}
null_value= false;
return value->get_date(thd, ltime, fuzzydate);
}
bool val_native(THD *thd, Native *to)
{
if (get_row_count() == 0 || get_arg(0)->is_null())
{
null_value= true;
return true;
}
null_value= false;
return value->val_native(thd, to);
}
bool add()
{
Item *arg= get_arg(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment