Skip to content
Permalink
Browse files
Added fix_fields for percentile function to check the type of argumen…
…t and to ensure that only numeric arguments are allowed
  • Loading branch information
varunraiko committed Nov 1, 2017
1 parent b5c104d commit 02a4a4b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
@@ -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()
{
@@ -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]"
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"

0 comments on commit 02a4a4b

Please sign in to comment.