summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-10-26 23:55:09 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2017-11-01 23:17:14 +0530
commit4f4f8f3fb120e9d4507766c817323c758a0a1990 (patch)
tree8683fa3cf5dcb8cd6f8c5591881bff997e9f7af3
parent02a4a4b512ace75bbe66065c136d697e83a4d9ff (diff)
downloadmariadb-git-4f4f8f3fb120e9d4507766c817323c758a0a1990.tar.gz
Added the median function to the parser , it should behave as a percentile_cont function with its argument fixed to 0.5
-rw-r--r--sql/lex.h1
-rw-r--r--sql/sql_yacc.yy34
2 files changed, 30 insertions, 5 deletions
diff --git a/sql/lex.h b/sql/lex.h
index 7967d17a5d4..63b0567c5d0 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -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)},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 5fd33fb3249..21ea4d3dbde 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -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 ')'
{