Commit 02a4a4b5 authored by Varun Gupta's avatar Varun Gupta

Added fix_fields for percentile function to check the type of argument and to...

Added fix_fields for percentile function to check the type of argument and to ensure that only numeric arguments are allowed
parent b5c104d0
...@@ -109,15 +109,6 @@ Item_window_func::fix_fields(THD *thd, Item **ref) ...@@ -109,15 +109,6 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
return true; 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 TODO: why the last parameter is 'ref' in this call? What if window_func
decides to substitute itself for something else and does *ref=.... ? decides to substitute itself for something else and does *ref=.... ?
...@@ -182,9 +173,11 @@ bool Item_window_func::check_result_type_of_order_item() ...@@ -182,9 +173,11 @@ bool Item_window_func::check_result_type_of_order_item()
{ {
if (only_single_element_order_list()) 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 && 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)); my_error(ER_WRONG_TYPE_FOR_PERCENTILE_CONT, MYF(0));
return TRUE; return TRUE;
...@@ -243,6 +236,45 @@ void Item_sum_percentile_cont::setup_window_func(THD *thd, Window_spec *window_s ...@@ -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->setup(thd, order_item);
floor_value->store(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() bool Item_sum_dense_rank::add()
{ {
......
...@@ -7794,3 +7794,5 @@ ER_ARGUMENT_NOT_CONSTANT ...@@ -7794,3 +7794,5 @@ ER_ARGUMENT_NOT_CONSTANT
eng "Argument to the percentile functions is not a constant" eng "Argument to the percentile functions is not a constant"
ER_ARGUMENT_OUT_OF_RANGE ER_ARGUMENT_OUT_OF_RANGE
eng "Argument to the percentile functions does not belong to the range [0,1]" 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
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