summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-06-26 02:15:19 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2017-11-01 23:13:01 +0530
commit18747a4baa9cc68766eaa7a40e92f8c3d873631a (patch)
tree172c5d732cbf99b62afe71f4fd379713f07f9576 /sql
parent129626f171377c247b71bdda602a554829e4f848 (diff)
downloadmariadb-git-18747a4baa9cc68766eaa7a40e92f8c3d873631a.tar.gz
Added value field to Item_sum_percentile_disc
Check for single element in the order_list is added
Diffstat (limited to 'sql')
-rw-r--r--sql/item_windowfunc.cc16
-rw-r--r--sql/item_windowfunc.h29
2 files changed, 44 insertions, 1 deletions
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index 835a3cbfdae..50a8c5d82cd 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -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)
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index ac695729fc5..3a774a2ff57 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -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 @@ public:
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 @@ public:
}
}
+ 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.