mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Added the error
1)ER_ARGUMENT_OUT_OF_RANGE: This error is thrown if the argument of the percentile function is not in the range [0,1] 2)ER_ARGUMENT_NOT_CONSTANT: This error is thrown if the argument of the percnetile function is not constant in the entire partition of the window function
This commit is contained in:
@ -730,7 +730,8 @@ class Item_sum_percentile_disc : public Item_sum_cume_dist,
|
|||||||
public:
|
public:
|
||||||
Item_sum_percentile_disc(THD *thd, Item* arg) : Item_sum_cume_dist(thd, arg),
|
Item_sum_percentile_disc(THD *thd, Item* arg) : Item_sum_cume_dist(thd, arg),
|
||||||
Type_handler_hybrid_field_type(&type_handler_longlong),
|
Type_handler_hybrid_field_type(&type_handler_longlong),
|
||||||
value(NULL), val_calculated(FALSE), first_call(TRUE),prev_value(0), order_item(NULL){}
|
value(NULL), val_calculated(FALSE), first_call(TRUE),
|
||||||
|
prev_value(0), order_item(NULL){}
|
||||||
|
|
||||||
double val_real()
|
double val_real()
|
||||||
{
|
{
|
||||||
@ -780,21 +781,26 @@ public:
|
|||||||
{
|
{
|
||||||
Item *arg = get_arg(0);
|
Item *arg = get_arg(0);
|
||||||
if (arg->is_null())
|
if (arg->is_null())
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (first_call)
|
if (first_call)
|
||||||
{
|
{
|
||||||
prev_value= arg->val_real();
|
prev_value= arg->val_real();
|
||||||
if (prev_value >1 || prev_value < 0)
|
if (prev_value >1 || prev_value < 0)
|
||||||
{
|
{
|
||||||
|
my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(0));
|
||||||
|
has_error= TRUE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
first_call= false;
|
first_call= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(prev_value != arg->val_real())
|
double arg_val= arg->val_real();
|
||||||
|
|
||||||
|
if(prev_value != arg_val)
|
||||||
{
|
{
|
||||||
// TODO(varun) need to add an error here , check the MDEV-12985 for the information
|
my_error(ER_ARGUMENT_NOT_CONSTANT, MYF(0));
|
||||||
|
has_error= TRUE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,6 +827,7 @@ public:
|
|||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
|
has_error= false;
|
||||||
val_calculated= false;
|
val_calculated= false;
|
||||||
first_call= true;
|
first_call= true;
|
||||||
value->clear();
|
value->clear();
|
||||||
@ -890,36 +897,13 @@ public:
|
|||||||
((ceil(val) - val) * floor_value->val_real());
|
((ceil(val) - val) * floor_value->val_real());
|
||||||
|
|
||||||
return ret_val;
|
return ret_val;
|
||||||
|
|
||||||
}
|
|
||||||
longlong val_int()
|
|
||||||
{
|
|
||||||
if (get_row_count() == 0 || get_arg(0)->is_null())
|
|
||||||
{
|
|
||||||
null_value= true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
null_value= false;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my_decimal* val_decimal(my_decimal* dec)
|
|
||||||
{
|
|
||||||
if (get_row_count() == 0 || get_arg(0)->is_null())
|
|
||||||
{
|
|
||||||
null_value= true;
|
|
||||||
return 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
null_value= false;
|
|
||||||
return ceil_value->val_decimal(dec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add()
|
bool add()
|
||||||
{
|
{
|
||||||
Item *arg = get_arg(0);
|
Item *arg = get_arg(0);
|
||||||
if (arg->is_null())
|
if (arg->is_null())
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (first_call)
|
if (first_call)
|
||||||
{
|
{
|
||||||
@ -927,14 +911,17 @@ public:
|
|||||||
prev_value= arg->val_real();
|
prev_value= arg->val_real();
|
||||||
if (prev_value >1 || prev_value < 0)
|
if (prev_value >1 || prev_value < 0)
|
||||||
{
|
{
|
||||||
// TODO(varun) need to add an error here , check the MDEV-12985 for the information
|
my_error(ER_ARGUMENT_OUT_OF_RANGE, MYF(0));
|
||||||
|
has_error= TRUE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_value != arg->val_real())
|
double arg_val= arg->val_real();
|
||||||
|
if(prev_value != arg_val)
|
||||||
{
|
{
|
||||||
// TODO(varun) need to add an error here , check the MDEV-12985 for the information
|
my_error(ER_ARGUMENT_NOT_CONSTANT, MYF(0));
|
||||||
|
has_error= TRUE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -966,12 +953,13 @@ public:
|
|||||||
|
|
||||||
enum Sumfunctype sum_func() const
|
enum Sumfunctype sum_func() const
|
||||||
{
|
{
|
||||||
return PERCENTILE_DISC_FUNC;
|
return PERCENTILE_CONT_FUNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
first_call= true;
|
first_call= true;
|
||||||
|
has_error= false;
|
||||||
floor_value->clear();
|
floor_value->clear();
|
||||||
ceil_value->clear();
|
ceil_value->clear();
|
||||||
floor_val_calculated= false;
|
floor_val_calculated= false;
|
||||||
|
@ -324,7 +324,7 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
|||||||
li.rewind();
|
li.rewind();
|
||||||
while((win_func_item= li++))
|
while((win_func_item= li++))
|
||||||
{
|
{
|
||||||
if (win_func_item->check_order_list())
|
if (win_func_item->check_result_type_of_order_item())
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
@ -1078,12 +1078,13 @@ protected:
|
|||||||
{
|
{
|
||||||
if (perform_no_action)
|
if (perform_no_action)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List_iterator_fast<Item_sum> it(sum_functions);
|
List_iterator_fast<Item_sum> it(sum_functions);
|
||||||
Item_sum *item_sum;
|
Item_sum *item_sum;
|
||||||
while ((item_sum= it++))
|
while ((item_sum= it++))
|
||||||
{
|
{
|
||||||
item_sum->add();
|
item_sum->add();
|
||||||
|
if (item_sum->has_error)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2809,6 +2810,12 @@ bool compute_window_func(THD *thd,
|
|||||||
{
|
{
|
||||||
cursor_manager->notify_cursors_next_row();
|
cursor_manager->notify_cursors_next_row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if we found any error in the window function while calling the add function */
|
||||||
|
|
||||||
|
if (win_func->window_func()->has_error)
|
||||||
|
goto label;
|
||||||
|
|
||||||
/* Return to current row after notifying cursors for each window
|
/* Return to current row after notifying cursors for each window
|
||||||
function. */
|
function. */
|
||||||
tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf);
|
tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf);
|
||||||
@ -2821,6 +2828,7 @@ bool compute_window_func(THD *thd,
|
|||||||
rownum++;
|
rownum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label:
|
||||||
my_free(rowid_buf);
|
my_free(rowid_buf);
|
||||||
partition_trackers.delete_elements();
|
partition_trackers.delete_elements();
|
||||||
end_read_record(&info);
|
end_read_record(&info);
|
||||||
|
Reference in New Issue
Block a user