Commit 18747a4b authored by Varun Gupta's avatar Varun Gupta

Added value field to Item_sum_percentile_disc

Check for single element in the order_list is added
parent 129626f1
......@@ -108,6 +108,17 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
my_error(ER_NO_ORDER_LIST_IN_WINDOW_SPEC, MYF(0), window_func()->func_name());
return true;
}
if (only_single_element_order_list())
{
// need to change the error, the error should say that we have more than one element in the order list
if (window_spec->order_list->elements != 1)
{
my_error(ER_NO_ORDER_LIST_IN_WINDOW_SPEC, MYF(0), window_func()->func_name());
return true;
}
}
/*
TODO: why the last parameter is 'ref' in this call? What if window_func
decides to substitute itself for something else and does *ref=.... ?
......@@ -194,6 +205,11 @@ void Item_sum_dense_rank::setup_window_func(THD *thd, Window_spec *window_spec)
clear();
}
void Item_sum_percentile_disc::setup_window_func(THD *thd, Window_spec *window_spec)
{
setup_percentile_func(thd, window_spec->order_list);
}
bool Item_sum_dense_rank::add()
{
if (peer_tracker->check_if_next_group() || first_add)
......
......@@ -705,7 +705,7 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist
{
public:
Item_sum_percentile_disc(THD *thd, Item* arg) : Item_sum_cume_dist(thd, arg)
{}
value(NULL) {}
double val_real()
{
......@@ -753,7 +753,23 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_sum_percentile_disc>(thd, mem_root, this); }
void setup_window_func(THD *thd, Window_spec *window_spec);
void setup_percentile_func(THD *thd, SQL_I_List<ORDER> *list)
{
value= new_Cached_item(thd, list->first->item[0], FALSE);
}
void cleanup()
{
if (value)
{
delete value;
value= NULL;
}
Item_sum_num::cleanup();
}
private:
Cached_item *value;
};
......@@ -871,6 +887,17 @@ class Item_window_func : public Item_func_or_sum
}
}
bool only_single_element_order_list() const
{
switch(window_func()->sum_func()){
case Item_sum::PERCENTILE_CONT_FUNC:
case Item_sum::PERCENTILE_DISC_FUNC:
return true;
default:
return false;
}
}
/*
Computation functions.
TODO: consoder merging these with class Group_bound_tracker.
......
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