summaryrefslogtreecommitdiff
path: root/sql/item_windowfunc.h
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2016-04-04 22:03:50 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2016-04-04 22:04:18 +0300
commit960b221c0bb4a35fd59d80b114f1833d51040cca (patch)
tree915403c7d671219d7254ef87b6b271dcf211c4bc /sql/item_windowfunc.h
parentbe3902fceba95254d13e0f74741c3fa2d4a0c9f4 (diff)
downloadmariadb-git-960b221c0bb4a35fd59d80b114f1833d51040cca.tar.gz
Convert ntile to work with expressions as parameters.
Diffstat (limited to 'sql/item_windowfunc.h')
-rw-r--r--sql/item_windowfunc.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index 215ceb14aa7..4c7ca793cd1 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -235,7 +235,10 @@ class Item_sum_window_with_row_count : public Item_sum_num
{
public:
Item_sum_window_with_row_count(THD *thd) : Item_sum_num(thd),
- partition_row_count_(0){}
+ partition_row_count_(0) {}
+
+ Item_sum_window_with_row_count(THD *thd, Item *arg) :
+ Item_sum_num(thd, arg), partition_row_count_(0) {};
void set_row_count(ulonglong count) { partition_row_count_ = count; }
@@ -398,8 +401,9 @@ class Item_sum_cume_dist: public Item_sum_window_with_row_count
class Item_sum_ntile : public Item_sum_window_with_row_count
{
public:
- Item_sum_ntile(THD* thd, ulong num_quantiles) :
- Item_sum_window_with_row_count(thd), num_quantiles_(num_quantiles),
+ Item_sum_ntile(THD* thd, Item* num_quantiles_expr) :
+ Item_sum_window_with_row_count(thd, num_quantiles_expr),
+ num_quantiles_expr_(num_quantiles_expr), num_quantiles_(0),
current_row_count_(0) {};
double val_real()
@@ -451,7 +455,26 @@ class Item_sum_ntile : public Item_sum_window_with_row_count
enum Item_result result_type () const { return INT_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
+ bool fix_fields(THD *thd, Item **ref)
+ {
+ if (Item_sum_window_with_row_count::fix_fields(thd, ref))
+ return true;
+ // TODO-cvicentiu is ref as a parameter here ok?
+ if (!num_quantiles_expr_->fixed)
+ num_quantiles_expr_->fix_fields(thd, ref);
+ longlong expr_value= num_quantiles_expr_->val_int();
+
+ if (expr_value <= 0) {
+ my_error(ER_INVALID_NTILE_ARGUMENT, MYF(0));
+ return true;
+ }
+
+ num_quantiles_= static_cast<ulong>(expr_value);
+ return false;
+ }
+
private:
+ Item* num_quantiles_expr_;
ulong num_quantiles_;
ulong current_row_count_;
};