Commit 4f4f8f3f authored by Varun Gupta's avatar Varun Gupta

Added the median function to the parser , it should behave as a...

Added the median function to the parser , it should behave as a percentile_cont function with its argument fixed to 0.5
parent 02a4a4b5
......@@ -737,6 +737,7 @@ static SYMBOL sql_functions[] = {
{ "LAG", SYM(LAG_SYM)},
{ "LEAD", SYM(LEAD_SYM)},
{ "MAX", SYM(MAX_SYM)},
{ "MEDIAN", SYM(MEDIAN_SYM)},
{ "MID", SYM(SUBSTRING)}, /* unireg function */
{ "MIN", SYM(MIN_SYM)},
{ "NOW", SYM(NOW_SYM)},
......
......@@ -1236,6 +1236,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token MAX_STATEMENT_TIME_SYM
%token MAX_USER_CONNECTIONS_SYM
%token MAXVALUE_SYM /* SQL-2003-N */
%token MEDIAN_SYM
%token MEDIUMBLOB
%token MEDIUMINT
%token MEDIUMTEXT
......@@ -1737,6 +1738,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
window_func
simple_window_func
inverse_distribution_function
percentile_function
inverse_distribution_function_def
function_call_keyword
function_call_nonkeyword
......@@ -10703,12 +10705,11 @@ simple_window_func:
}
;
inverse_distribution_function:
inverse_distribution_function_def WITHIN GROUP_SYM
'('
{ Select->prepare_add_window_spec(thd); }
order_by_single_element_list ')' OVER_SYM
'(' opt_window_ref opt_window_partition_clause ')'
percentile_function OVER_SYM
'(' opt_window_partition_clause ')'
{
LEX *lex= Lex;
if (Select->add_window_spec(thd, lex->win_ref,
......@@ -10725,6 +10726,29 @@ inverse_distribution_function:
}
;
percentile_function:
inverse_distribution_function_def WITHIN GROUP_SYM '('
{ Select->prepare_add_window_spec(thd); }
order_by_single_element_list ')'
{
$$= $1;
}
| MEDIAN_SYM '(' expr ')'
{
Item *args= new (thd->mem_root) Item_decimal(thd, "0.5", 3,
thd->charset());
if (($$ == NULL) || (thd->is_error()))
{
MYSQL_YYABORT;
}
if (add_order_to_list(thd, $3,FALSE)) MYSQL_YYABORT;
$$= new (thd->mem_root) Item_sum_percentile_cont(thd, args);
if ($$ == NULL)
MYSQL_YYABORT;
}
;
inverse_distribution_function_def:
PERCENTILE_CONT_SYM '(' expr ')'
{
......
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