From 97a37edc970f8619ffd23394b61fe310d705d0ef Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 15 Oct 2018 09:35:19 -0700 Subject: MDEV-17137: Syntax errors with VIEW using MEDIAN The syntax error happened because we had not implemented a different print for percentile functions. The syntax is a bit different when we use percentile functions as window functions in comparision to normal window functions. Implemented a seperate print function for percentile functions --- sql/item_windowfunc.cc | 17 +++++++++++++++++ sql/item_windowfunc.h | 1 + sql/sql_window.cc | 19 ++++++++++++++++--- sql/sql_window.h | 2 ++ 4 files changed, 36 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 3ad0527384d..2db396d3065 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -545,6 +545,11 @@ void Item_sum_hybrid_simple::update_field() void Item_window_func::print(String *str, enum_query_type query_type) { + if (only_single_element_order_list()) + { + print_for_percentile_functions(str, query_type); + return; + } window_func()->print(str, query_type); str->append(" over "); #ifndef DBUG_OFF @@ -554,3 +559,15 @@ void Item_window_func::print(String *str, enum_query_type query_type) #endif window_spec->print(str, query_type); } +void Item_window_func::print_for_percentile_functions(String *str, enum_query_type query_type) +{ + window_func()->print(str, query_type); + str->append(" within group "); + str->append('('); + window_spec->print_order(str,query_type); + str->append(')'); + str->append(" over "); + str->append('('); + window_spec->print_partition(str,query_type); + str->append(')'); +} diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index b3e23748246..9ba60c3956d 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -1155,6 +1155,7 @@ private: */ bool force_return_blank; bool read_value_from_result_field; + void print_for_percentile_functions(String *str, enum_query_type query_type); public: void set_phase_to_initial() diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 38fdd8ab80b..e4d69f2fa5e 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -82,19 +82,32 @@ void Window_spec::print(String *str, enum_query_type query_type) { str->append('('); + print_partition(str, query_type); + print_order(str, query_type); + + if (window_frame) + window_frame->print(str, query_type); + str->append(')'); +} + +void +Window_spec::print_partition(String *str, enum_query_type query_type) +{ if (partition_list->first) { str->append(STRING_WITH_LEN(" partition by ")); st_select_lex::print_order(str, partition_list->first, query_type); } +} + +void +Window_spec::print_order(String *str, enum_query_type query_type) +{ if (order_list->first) { str->append(STRING_WITH_LEN(" order by ")); st_select_lex::print_order(str, order_list->first, query_type); } - if (window_frame) - window_frame->print(str, query_type); - str->append(')'); } bool diff --git a/sql/sql_window.h b/sql/sql_window.h index 392f89e8f03..bf59f00d764 100644 --- a/sql/sql_window.h +++ b/sql/sql_window.h @@ -147,6 +147,8 @@ class Window_spec : public Sql_alloc } void print(String *str, enum_query_type query_type); + void print_order(String *str, enum_query_type query_type); + void print_partition(String *str, enum_query_type query_type); }; -- cgit v1.2.1