summaryrefslogtreecommitdiff
path: root/sql/item_windowfunc.h
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2016-03-28 22:48:32 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2016-03-28 22:51:42 +0300
commit3544fe0144dd4f6476467a78f0db7502326e8751 (patch)
tree53c5e01cced9ac1428908093044d9252f349b106 /sql/item_windowfunc.h
parentd40d68f23602be9886c1b502fdad9d23bdc9a0fb (diff)
downloadmariadb-git-3544fe0144dd4f6476467a78f0db7502326e8751.tar.gz
Implemented cume_dist function.
Also fixed a bug in row_counts detection, when partition changes.
Diffstat (limited to 'sql/item_windowfunc.h')
-rw-r--r--sql/item_windowfunc.h45
1 files changed, 40 insertions, 5 deletions
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index 1dd483ca9b3..59b739767c8 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -422,27 +422,62 @@ class Item_sum_percent_rank: public Item_sum_window_with_row_count
window ordering of the window partition of R
- NR is defined to be the number of rows in the window partition of R.
- Just like with Item_sum_percent_rank, compuation of this function requires
+ Just like with Item_sum_percent_rank, computation of this function requires
two passes.
*/
-class Item_sum_cume_dist: public Item_sum_percent_rank
+class Item_sum_cume_dist: public Item_sum_window_with_row_count
{
public:
- Item_sum_cume_dist(THD *thd)
- : Item_sum_percent_rank(thd) {}
+ Item_sum_cume_dist(THD *thd) : Item_sum_window_with_row_count(thd),
+ current_row_count_(0) {}
- double val_real() { return 0; }
+ double val_real()
+ {
+ if (get_row_count() == 0)
+ {
+ null_value= true;
+ return 0;
+ }
+ ulonglong partition_row_count= get_row_count();
+ null_value= false;
+ return static_cast<double>(current_row_count_) / partition_row_count;
+ }
+
+ bool add()
+ {
+ current_row_count_++;
+ return false;
+ }
enum Sumfunctype sum_func () const
{
return CUME_DIST_FUNC;
}
+ void clear()
+ {
+ current_row_count_= 0;
+ set_row_count(0);
+ }
+
const char*func_name() const
{
return "cume_dist";
}
+
+ void update_field() {}
+ enum Item_result result_type () const { return REAL_RESULT; }
+ enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
+
+ void fix_length_and_dec()
+ {
+ decimals = 10; // TODO-cvicentiu find out how many decimals the standard
+ // requires.
+ }
+
+ private:
+ ulonglong current_row_count_;
};