summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-09-07 17:40:09 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2017-11-01 23:17:14 +0530
commit02a4a4b512ace75bbe66065c136d697e83a4d9ff (patch)
treeb84f113b206a752c2ec7d4f2b674995a0362c662
parentb5c104d00a264e250cc008c6f2a42e8a2b18f385 (diff)
downloadmariadb-git-02a4a4b512ace75bbe66065c136d697e83a4d9ff.tar.gz
Added fix_fields for percentile function to check the type of argument and to ensure that only numeric arguments are allowed
-rw-r--r--sql/item_windowfunc.cc54
-rw-r--r--sql/share/errmsg-utf8.txt4
2 files changed, 46 insertions, 12 deletions
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index 4022c3ddf70..f941900646e 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -109,15 +109,6 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
return true;
}
- if (only_single_element_order_list())
- {
- if (window_spec->order_list->elements != 1)
- {
- my_error(ER_NOT_SINGLE_ELEMENT_ORDER_LIST, 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=.... ?
@@ -182,9 +173,11 @@ bool Item_window_func::check_result_type_of_order_item()
{
if (only_single_element_order_list())
{
- Item_result rtype= window_spec->order_list->first->item[0]->result_type();
+ Item_result rtype= window_spec->order_list->first->item[0]->cmp_type();
+ // TODO (varun) : support date type in percentile_cont function
if (rtype != REAL_RESULT && rtype != INT_RESULT &&
- rtype != DECIMAL_RESULT && window_func()->sum_func() == Item_sum::PERCENTILE_CONT_FUNC)
+ rtype != DECIMAL_RESULT && rtype != TIME_RESULT
+ window_func()->sum_func() == Item_sum::PERCENTILE_CONT_FUNC)
{
my_error(ER_WRONG_TYPE_FOR_PERCENTILE_CONT, MYF(0));
return TRUE;
@@ -243,6 +236,45 @@ void Item_sum_percentile_cont::setup_window_func(THD *thd, Window_spec *window_s
floor_value->setup(thd, order_item);
floor_value->store(order_item);
}
+bool Item_sum_percentile_cont::fix_fields(THD *thd, Item **ref)
+{
+ bool res;
+ res= Item_sum_num::fix_fields(thd, ref);
+ if (res)
+ return res;
+
+ switch(args[0]->cmp_type())
+ {
+ case DECIMAL_RESULT:
+ case REAL_RESULT:
+ case INT_RESULT:
+ break;
+ default:
+ my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0));
+ return TRUE;
+ }
+ return res;
+}
+bool Item_sum_percentile_disc::fix_fields(THD *thd, Item **ref)
+{
+ bool res;
+ res= Item_sum_num::fix_fields(thd, ref);
+ if (res)
+ return res;
+
+ switch(args[0]->cmp_type())
+ {
+ case DECIMAL_RESULT:
+ case REAL_RESULT:
+ case INT_RESULT:
+ break;
+ default:
+ my_error(ER_WRONG_TYPE_OF_ARGUMENT, MYF(0));
+ return TRUE;
+ }
+ return res;
+
+}
bool Item_sum_dense_rank::add()
{
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 1011d540e51..415d47df36e 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7793,4 +7793,6 @@ ER_WRONG_TYPE_FOR_PERCENTILE_CONT
ER_ARGUMENT_NOT_CONSTANT
eng "Argument to the percentile functions is not a constant"
ER_ARGUMENT_OUT_OF_RANGE
- eng "Argument to the percentile functions does not belong to the range [0,1]" \ No newline at end of file
+ eng "Argument to the percentile functions does not belong to the range [0,1]"
+ER_WRONG_TYPE_OF_ARGUMENT
+ eng "Numeric values are only allowed as arguments to percentile functions" \ No newline at end of file