Commit ab5503c8 authored by Varun Gupta's avatar Varun Gupta

Updates the tests for the percentile functions

parent 40887913
This diff is collapsed.
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;
...@@ -5,50 +5,77 @@ INSERT INTO t1 VALUES ...@@ -5,50 +5,77 @@ INSERT INTO t1 VALUES
('Kaolin', 0.5, 4), ('Kaolin', 0.5, 4),
('Tatiana', 0.8, 4), ('Tata', 0.8, 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_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_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; 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 --error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_cont(null) within group(order by score) over (partition by name) from t1; select name, percentile_cont(null) within group(order by score) over (partition by name) from t1;
--error ER_WRONG_TYPE_OF_ARGUMENT --error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_disc(null) within group(order by score) over (partition by name) from t1; 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_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 * 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; 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 --echo #disallowed fields in order by
--error ER_WRONG_TYPE_FOR_PERCENTILE_CONT --error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1; 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; 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 --echo #parameter value should be in the range of [0,1]
--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]
--error ER_ARGUMENT_OUT_OF_RANGE --error ER_ARGUMENT_OUT_OF_RANGE
select percentile_disc(1.5) within group(order by score) over (partition by name) from t1; select percentile_disc(1.5) within group(order by score) over (partition by name) from t1;
--error ER_ARGUMENT_OUT_OF_RANGE --error ER_ARGUMENT_OUT_OF_RANGE
select percentile_cont(1.5) within group(order by score) over (partition by name) from t1; 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 --error ER_ARGUMENT_NOT_CONSTANT
select name,percentile_cont(test) within group(order by score) over (partition by name) from t1; select name,percentile_cont(test) within group(order by score) over (partition by name) from t1;
--error ER_ARGUMENT_NOT_CONSTANT --error ER_ARGUMENT_NOT_CONSTANT
select name, percentile_disc(test) within group(order by score) over (partition by name) from t1; 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 --error ER_WRONG_TYPE_OF_ARGUMENT
select name, percentile_cont(name) within group(order by score) over (partition by name) from t1; 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,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; select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
......
...@@ -174,11 +174,11 @@ bool Item_window_func::check_result_type_of_order_item() ...@@ -174,11 +174,11 @@ bool Item_window_func::check_result_type_of_order_item()
if (only_single_element_order_list()) if (only_single_element_order_list())
{ {
Item_result rtype= window_spec->order_list->first->item[0]->cmp_type(); 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 && if (rtype != REAL_RESULT && rtype != INT_RESULT &&
rtype != DECIMAL_RESULT && rtype != TIME_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; return TRUE;
} }
setting_handler_for_percentile_functions(rtype); setting_handler_for_percentile_functions(rtype);
...@@ -249,7 +249,7 @@ bool Item_sum_percentile_cont::fix_fields(THD *thd, Item **ref) ...@@ -249,7 +249,7 @@ bool Item_sum_percentile_cont::fix_fields(THD *thd, Item **ref)
case INT_RESULT: case INT_RESULT:
break; break;
default: default:
my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0)); my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0), func_name());
return TRUE; return TRUE;
} }
return res; return res;
...@@ -268,7 +268,7 @@ bool Item_sum_percentile_disc::fix_fields(THD *thd, Item **ref) ...@@ -268,7 +268,7 @@ bool Item_sum_percentile_disc::fix_fields(THD *thd, Item **ref)
case INT_RESULT: case INT_RESULT:
break; break;
default: default:
my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0)); my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0), func_name());
return TRUE; return TRUE;
} }
return res; return res;
......
...@@ -786,7 +786,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist, ...@@ -786,7 +786,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
value->store(order_item); value->store(order_item);
value->cache_value(); value->cache_value();
if (value->null_value) if (value->null_value)
return false; return false;
Item_sum_cume_dist::add(); Item_sum_cume_dist::add();
double val= Item_sum_cume_dist::val_real(); double val= Item_sum_cume_dist::val_real();
...@@ -821,7 +821,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist, ...@@ -821,7 +821,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
void fix_length_and_dec() 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. // requires.
} }
...@@ -904,24 +904,24 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist, ...@@ -904,24 +904,24 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
floor_value->store(order_item); floor_value->store(order_item);
floor_value->cache_value(); floor_value->cache_value();
if (floor_value->null_value) if (floor_value->null_value)
return false; return false;
} }
if (floor_val_calculated && !ceil_val_calculated) if (floor_val_calculated && !ceil_val_calculated)
{ {
ceil_value->store(order_item); ceil_value->store(order_item);
ceil_value->cache_value(); ceil_value->cache_value();
if (ceil_value->null_value) if (ceil_value->null_value)
return false; return false;
} }
Item_sum_cume_dist::add(); Item_sum_cume_dist::add();
double val= 1 + prev_value * (get_row_count()-1); double val= 1 + prev_value * (get_row_count()-1);
if (!floor_val_calculated && get_row_number() == floor(val)) 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)) if (!ceil_val_calculated && get_row_number() == ceil(val))
ceil_val_calculated= true; ceil_val_calculated= true;
return false; return false;
} }
...@@ -951,7 +951,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist, ...@@ -951,7 +951,7 @@ class Item_sum_percentile_cont : public Item_sum_cume_dist,
void fix_length_and_dec() 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. // requires.
} }
......
...@@ -1765,7 +1765,7 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following ...@@ -1765,7 +1765,7 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
} }
}; };
class Frame_unbounded_following_set_count_no_nulls: class Frame_unbounded_following_set_count_no_nulls:
public Frame_unbounded_following_set_count public Frame_unbounded_following_set_count
{ {
......
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