From 58f7fb882eaf0d0a784f9e006b3ee1e2407a379a Mon Sep 17 00:00:00 2001 From: LINxiansheng Date: Wed, 11 Aug 2021 17:50:35 +0800 Subject: [PATCH] Merge pull request from GitHub pr175 --- deps/oblib/src/lib/ob_name_def.h | 1 + src/sql/CMakeLists.txt | 1 + .../code_generator/ob_static_engine_cg.cpp | 7 +- .../engine/expr/ob_expr_eval_functions.cpp | 2 + src/sql/engine/expr/ob_expr_export_set.cpp | 268 +++++++++++++++ src/sql/engine/expr/ob_expr_export_set.h | 42 +++ src/sql/engine/expr/ob_expr_operator.cpp | 6 +- .../engine/expr/ob_expr_operator_factory.cpp | 2 + .../engine/expr/ob_expr_regexp_context.cpp | 2 +- src/sql/engine/expr/ob_expr_uid.cpp | 7 +- src/sql/parser/ob_item_type.h | 2 + src/sql/parser/type_name.c | 1 + .../expr/r/mysql/expr_export_set.result | 315 ++++++++++++++++++ .../test_suite/expr/t/expr_export_set.test | 151 +++++++++ 14 files changed, 800 insertions(+), 7 deletions(-) create mode 100644 src/sql/engine/expr/ob_expr_export_set.cpp create mode 100644 src/sql/engine/expr/ob_expr_export_set.h create mode 100644 test/mysql_test/test_suite/expr/r/mysql/expr_export_set.result create mode 100644 test/mysql_test/test_suite/expr/t/expr_export_set.test diff --git a/deps/oblib/src/lib/ob_name_def.h b/deps/oblib/src/lib/ob_name_def.h index 5e3f09cf9..c42497675 100644 --- a/deps/oblib/src/lib/ob_name_def.h +++ b/deps/oblib/src/lib/ob_name_def.h @@ -434,6 +434,7 @@ #define N_REPLACE "replace" #define N_TRANSLATE "translate" #define N_CONCAT "concat" +#define N_EXPORT_SET "export_set" #define N_CONCAT_WS "concat_ws" #define N_TO_OUTFILE_ROW "to_outfile_row" #define N_INSTR "instr" diff --git a/src/sql/CMakeLists.txt b/src/sql/CMakeLists.txt index cd66b292e..23a666f3a 100644 --- a/src/sql/CMakeLists.txt +++ b/src/sql/CMakeLists.txt @@ -346,6 +346,7 @@ ob_set_subtarget(ob_sql engine engine/expr/ob_expr_regexp_like.cpp engine/expr/ob_expr_repeat.cpp engine/expr/ob_expr_replace.cpp + engine/expr/ob_expr_export_set.cpp engine/expr/ob_expr_translate.cpp engine/expr/ob_expr_pi.cpp engine/expr/ob_expr_pi.h diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index a4a1595e4..80cceff64 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -234,9 +234,12 @@ int ObStaticEngineCG::postorder_generate_op( } if (is_subplan) { cur_op_exprs_.reset(); - cur_op_exprs_.assign(tmp_cur_op_exprs); cur_op_self_produced_exprs_.reset(); - cur_op_self_produced_exprs_.assign(tmp_cur_op_self_produced_exprs); + if (OB_FAIL(cur_op_exprs_.assign(tmp_cur_op_exprs))) { + LOG_WARN("assign exprs failed", K(ret)); + } else if (OB_FAIL(cur_op_self_produced_exprs_.assign(tmp_cur_op_self_produced_exprs))) { + LOG_WARN("assign exprs failed", K(ret)); + } } return ret; diff --git a/src/sql/engine/expr/ob_expr_eval_functions.cpp b/src/sql/engine/expr/ob_expr_eval_functions.cpp index d2d595b0c..39fd9fd6a 100644 --- a/src/sql/engine/expr/ob_expr_eval_functions.cpp +++ b/src/sql/engine/expr/ob_expr_eval_functions.cpp @@ -69,6 +69,7 @@ #include "ob_expr_regexp_replace.h" #include "ob_expr_regexp_substr.h" #include "ob_expr_repeat.h" +#include "ob_expr_export_set.h" #include "ob_expr_replace.h" #include "ob_expr_func_dump.h" #include "ob_expr_func_part_hash.h" @@ -663,6 +664,7 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = { ObExprTimeFormat::calc_time_format, /* 407 */ ObExprMakedate::calc_makedate, /* 408 */ ObExprPeriodAdd::calc_periodadd, /* 409 */ + ObExprExportSet::eval_export_set, /* 401 */ }; REG_SER_FUNC_ARRAY(OB_SFA_SQL_EXPR_EVAL, g_expr_eval_functions, ARRAYSIZEOF(g_expr_eval_functions)); diff --git a/src/sql/engine/expr/ob_expr_export_set.cpp b/src/sql/engine/expr/ob_expr_export_set.cpp new file mode 100644 index 000000000..128e96845 --- /dev/null +++ b/src/sql/engine/expr/ob_expr_export_set.cpp @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#define USING_LOG_PREFIX SQL_ENG + +#include "sql/engine/expr/ob_expr_export_set.h" +#include "lib/oblog/ob_log.h" +#include "share/object/ob_obj_cast.h" +#include "sql/session/ob_sql_session_info.h" +using namespace oceanbase::common; +namespace oceanbase { +namespace sql { + +ObExprExportSet::ObExprExportSet(ObIAllocator& alloc) + : ObStringExprOperator(alloc, T_FUN_SYS_EXPORT_SET, N_EXPORT_SET, MORE_THAN_TWO) +{ + need_charset_convert_ = false; +} + +ObExprExportSet::~ObExprExportSet() +{} + +int ObExprExportSet::calc_result_typeN(ObExprResType& type, ObExprResType* types_array, + int64_t param_num, common::ObExprTypeCtx& type_ctx) const +{ + int ret = OB_SUCCESS; + if (3 != param_num && 4 != param_num && 5 != param_num) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("Export_Set() should have three or four or five arguments", K(ret), K(param_num)); + } else if (OB_ISNULL(types_array) || OB_ISNULL(type_ctx.get_session())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected error. types_array or session null", K(ret), KP(types_array), + KP(type_ctx.get_session())); + } else { + // deduce length + // Maximum occurrences of on and of in result + const uint64_t MAX_BIT_NUM = 64; + // Maximum occurrences of sep in result + const uint64_t MAX_SEP_NUM = 63; + const int64_t on_len = types_array[1].get_length(); + const int64_t off_len = types_array[2].get_length(); + int64_t sep_len = 1; + int64_t str_num = 2; + const uint64_t max_len = std::max(on_len, off_len); + // when bits exceed uint_max or int_min, ob is not compatible to mysql. + types_array[0].set_calc_type(common::ObBitType); + types_array[1].set_calc_type(common::ObVarcharType); + types_array[2].set_calc_type(common::ObVarcharType); + if (3 < param_num) { + sep_len = types_array[3].get_length(); + str_num = 3; + types_array[3].set_calc_type(common::ObVarcharType); + if (4 < param_num) { + types_array[4].set_calc_type(common::ObIntType); + } + } + common::ObLength len = static_cast(MAX_BIT_NUM * max_len + + MAX_SEP_NUM * sep_len); + type.set_length(len); + type.set_varchar(); + // set collation_type for string type + OZ(ObExprOperator::aggregate_charsets_for_string_result_with_comparison( + type, &types_array[1], str_num, type_ctx.get_coll_type())); + for (int64_t i = 1; OB_SUCC(ret) && i <= str_num; ++i) { + types_array[i].set_calc_meta(type); + } + } + return ret; +} + +int ObExprExportSet::calc_resultN(ObObj& result, const ObObj* objs_array, int64_t param_num, + ObExprCtx& expr_ctx) const +{ + int ret = OB_SUCCESS; + if (OB_ISNULL(expr_ctx.calc_buf_)) { + ret = OB_NOT_INIT; + LOG_WARN("calc_buf of expr_ctx is NULL", K(ret)); + } else if (3 == param_num) { + ObObj tmp_n_bits; + ObObj tmp_sep; + tmp_n_bits.set_int(64); + tmp_sep.set_string(common::ObVarcharType, ObCharsetUtils::get_const_str( + objs_array[1].get_collation_type(), ',')); + if (OB_FAIL(calc_export_set(result, objs_array[0], objs_array[1], objs_array[2], + tmp_sep, tmp_n_bits, expr_ctx))) { + LOG_WARN("calc_export_set failed", K(ret)); + } + } else if (4 == param_num) { + ObObj tmp_n_bits; + tmp_n_bits.set_int(64); + if (OB_FAIL(calc_export_set(result, objs_array[0], objs_array[1], objs_array[2], + objs_array[3], tmp_n_bits, expr_ctx))) { + LOG_WARN("calc_export_set failed", K(ret)); + } + } else if (5 == param_num) { + if (OB_FAIL(calc_export_set(result, objs_array[0], objs_array[1], objs_array[2], + objs_array[3], objs_array[4], expr_ctx))) { + LOG_WARN("calc_export_set failed", K(ret)); + } + } + + return ret; +} + +int ObExprExportSet::calc_export_set(ObObj& result, const ObObj& bits, const ObObj& on, + const ObObj& off, const ObObj& sep, const ObObj& n_bits, ObExprCtx& expr_ctx) const +{ + int ret = OB_SUCCESS; + if (bits.is_null() || on.is_null() || off.is_null() || sep.is_null() || n_bits.is_null()) { + result.set_null(); + } else if (OB_ISNULL(expr_ctx.calc_buf_)) { + ret = OB_NOT_INIT; + LOG_WARN("varchar buffer not init", K(ret)); + } else { + uint64_t local_bits; + ObString local_on; + ObString local_off; + ObString local_sep; + int64_t local_n_bits; + ObString res; + local_on = on.get_string(); + local_off = off.get_string(); + local_sep = sep.get_string(); + if (OB_FAIL(bits.get_bit(local_bits))) { + LOG_WARN("fail to get bit", K(ret), K(bits)); + } else if (OB_FAIL(n_bits.get_int(local_n_bits))) { + LOG_WARN("fail to get int", K(ret), K(n_bits)); + } else if (OB_FAIL(calc_export_set_inner(res, local_bits, local_on, local_off, + local_sep, local_n_bits, *expr_ctx.calc_buf_))) { + LOG_WARN("do export set failed", K(ret)); + } else { + result.set_string(result_type_.get_type(), res); + result.set_collation(result_type_); + } + } + return ret; +} + +int ObExprExportSet::calc_export_set_inner(ObString& ret_str, const uint64_t bits, + const ObString& on, const ObString& off, const ObString& sep, const int64_t n_bits, + ObExprStringBuf& string_buf) +{ + int ret = OB_SUCCESS; + if (OB_UNLIKELY(n_bits == 0)) { + // Return empty string + ret_str.reset(); + } else if (OB_UNLIKELY(on.length() <= 0 && off.length() <= 0 && sep.length() <= 0)) { + ret_str.reset(); + } else { + const uint64_t MAX_BIT_NUM = 64UL; + uint64_t local_n_bits = static_cast(n_bits); + local_n_bits = std::min(MAX_BIT_NUM, local_n_bits); + const int64_t length_on = on.length(); + const int64_t length_off = off.length(); + const int64_t length_sep = sep.length(); + int64_t tot_length = 0; // total length for the result. + uint64_t i; + const uint64_t mask = 1; + //compute tot_length and save ans + tot_length += (local_n_bits - 1) * length_sep; + for (i = 0; i < local_n_bits; ++i) { + if (bits & (mask << i)){ + tot_length += length_on; + } else { + tot_length += length_off; + } + } + // Avoid realloc + if (OB_UNLIKELY(tot_length <= 0)) { + // tot_length equals to 0 indicates that length_to is zero and "to" is empty string + ret_str.reset(); + } else { + char* buf = static_cast(string_buf.alloc(tot_length)); + if (OB_ISNULL(buf)) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_ERROR("alloc memory failed.", K(ret), K(tot_length)); + } else { + // Core function + char* tmp_buf = buf; + if (local_n_bits > 0) { + if (bits & mask) { + MEMCPY(tmp_buf, on.ptr(), length_on); + tmp_buf += length_on; + } else { + MEMCPY(tmp_buf, off.ptr(), length_off); + tmp_buf += length_off; + } + } + for (i = 1; i < local_n_bits; ++i) { + MEMCPY(tmp_buf, sep.ptr(), length_sep); + tmp_buf += length_sep; + if (bits & (mask << i)) { + MEMCPY(tmp_buf, on.ptr(), length_on); + tmp_buf += length_on; + } else { + MEMCPY(tmp_buf, off.ptr(), length_off); + tmp_buf += length_off; + } + } + ret_str.assign_ptr(buf, static_cast(tot_length)); + } + } + } + return ret; +} + +int ObExprExportSet::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& rt_expr) const +{ + int ret = OB_SUCCESS; + CK(3 == rt_expr.arg_cnt_ || 4 == rt_expr.arg_cnt_ || 5 == rt_expr.arg_cnt_); + rt_expr.eval_func_ = &eval_export_set; + return ret; +} + +int ObExprExportSet::eval_export_set(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum) +{ + int ret = OB_SUCCESS; + ObDatum* bits = NULL; + ObDatum* on = NULL; + ObDatum* off = NULL; + ObDatum* sep = NULL; + ObDatum* n_bits = NULL; + int64_t max_size = 0; + if (OB_FAIL(expr.eval_param_value(ctx, bits, on, off, sep, n_bits))) { + LOG_WARN("evaluate parameters failed", K(ret)); + } else if (bits->is_null() || on->is_null() || off->is_null()) { + expr_datum.set_null(); + } else if (OB_NOT_NULL(sep) && sep->is_null()) { + expr_datum.set_null(); + } else if (OB_NOT_NULL(n_bits) && n_bits->is_null()) { + expr_datum.set_null(); + } else { + ObExprStrResAlloc expr_res_alloc(expr, ctx); + ObString output; + //default parm + ObString sep_parm; + int64_t n_bits_parm; + if (OB_ISNULL(sep)) { + sep_parm = ObCharsetUtils::get_const_str(expr.datum_meta_.cs_type_, ','); + } else { + sep_parm = sep->get_string(); + } + if (OB_ISNULL(n_bits)) { + n_bits_parm = 64; + } else { + n_bits_parm = n_bits->get_uint64(); + } + if (OB_FAIL(calc_export_set_inner(output, bits->get_uint64(), on->get_string(), + off->get_string(), sep_parm, n_bits_parm, expr_res_alloc))) { + LOG_WARN("do export set failed", K(ret)); + } else { + expr_datum.set_string(output); + } + } + return ret; +} + +} // namespace sql +} // namespace oceanbase diff --git a/src/sql/engine/expr/ob_expr_export_set.h b/src/sql/engine/expr/ob_expr_export_set.h new file mode 100644 index 000000000..bcc2998e7 --- /dev/null +++ b/src/sql/engine/expr/ob_expr_export_set.h @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#ifndef OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_EXPORT_SET_ +#define OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_EXPORT_SET_ + +#include "sql/engine/expr/ob_expr_operator.h" + +namespace oceanbase { +namespace sql { +class ObExprExportSet : public ObStringExprOperator { +public: + explicit ObExprExportSet(common::ObIAllocator& alloc); + virtual ~ObExprExportSet(); + virtual int calc_result_typeN( + ObExprResType& type, ObExprResType* types_array, int64_t param_num, common::ObExprTypeCtx& type_ctx) const; + virtual int calc_resultN( + common::ObObj& result, const common::ObObj* objs_array, int64_t param_num, common::ObExprCtx& expr_ctx) const; + virtual int calc_export_set(common::ObObj& result, const common::ObObj& bits, const common::ObObj& on, + const common::ObObj& off, const common::ObObj& sep, const common::ObObj& n_bits, common::ObExprCtx& expr_ctx) const; + virtual int cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const override; + static int eval_export_set(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum); +private: + // disallow copy + DISALLOW_COPY_AND_ASSIGN(ObExprExportSet); + // helper func + static int calc_export_set_inner(ObString& ret_str, const uint64_t bits, const ObString& on, const ObString& off, + const ObString& sep, const int64_t n_bits, ObExprStringBuf& string_buf); +}; +} // namespace sql +} // namespace oceanbase + +#endif // OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_EXPORT_SET_ diff --git a/src/sql/engine/expr/ob_expr_operator.cpp b/src/sql/engine/expr/ob_expr_operator.cpp index 1b1e9dbc7..bf0cadb11 100644 --- a/src/sql/engine/expr/ob_expr_operator.cpp +++ b/src/sql/engine/expr/ob_expr_operator.cpp @@ -4776,8 +4776,10 @@ int ObRelationalExprOperator::cg_row_cmp_expr(const int row_dimension, ObIAlloca ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected error", K(ret)); } - - if (OB_UNLIKELY(left_row->arg_cnt_ != right_row->arg_cnt_)) { + if (OB_ISNULL(right_row) || OB_ISNULL(left_row)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("right_row or left_row is null ptr", K(ret), K(right_row), K(left_row)); + } else if (OB_UNLIKELY(left_row->arg_cnt_ != right_row->arg_cnt_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected row cnt", K(left_row->arg_cnt_), K(right_row->arg_cnt_)); } diff --git a/src/sql/engine/expr/ob_expr_operator_factory.cpp b/src/sql/engine/expr/ob_expr_operator_factory.cpp index 5b965dd23..e4b1ed863 100644 --- a/src/sql/engine/expr/ob_expr_operator_factory.cpp +++ b/src/sql/engine/expr/ob_expr_operator_factory.cpp @@ -143,6 +143,7 @@ #include "sql/engine/expr/ob_expr_merging_frozen_time.h" #include "sql/engine/expr/ob_expr_remainder.h" #include "sql/engine/expr/ob_expr_repeat.h" +#include "sql/engine/expr/ob_expr_export_set.h" #include "sql/engine/expr/ob_expr_replace.h" #include "sql/engine/expr/ob_expr_translate.h" #include "sql/engine/expr/ob_expr_func_part_hash.h" @@ -535,6 +536,7 @@ void ObExprOperatorFactory::register_expr_operators() REG_OP(ObExprFuncCeiling); REG_OP(ObExprFuncDump); REG_OP(ObExprRepeat); + REG_OP(ObExprExportSet); REG_OP(ObExprReplace); REG_OP(ObExprFuncPartOldHash); REG_OP(ObExprFuncPartHash); diff --git a/src/sql/engine/expr/ob_expr_regexp_context.cpp b/src/sql/engine/expr/ob_expr_regexp_context.cpp index b395c070a..7c423e190 100644 --- a/src/sql/engine/expr/ob_expr_regexp_context.cpp +++ b/src/sql/engine/expr/ob_expr_regexp_context.cpp @@ -376,7 +376,7 @@ int ObExprRegexContext::like(const ObString& text, int64_t occurrence, bool& sub } else if (text.length() < 0 || (text.length() > 0 && OB_ISNULL(text.ptr()))) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid param, source text is null", K(ret), K(text)); - } else if (reg_.re_nsub >= 0) { + } else { size_t nsub = reg_.re_nsub; ob_regmatch_t pmatch[nsub + 1]; int error = 0; diff --git a/src/sql/engine/expr/ob_expr_uid.cpp b/src/sql/engine/expr/ob_expr_uid.cpp index 782901d5c..88a5e247d 100644 --- a/src/sql/engine/expr/ob_expr_uid.cpp +++ b/src/sql/engine/expr/ob_expr_uid.cpp @@ -61,8 +61,11 @@ int ObExprUid::calc_result0(ObObj& result, ObExprCtx& expr_ctx) const const uint64_t sess_uid = session_info->get_user_id(); // result.set_uint64_value(sess_uid); number::ObNumber num; - num.from(sess_uid, *(expr_ctx.calc_buf_)); - result.set_number(num); + if (OB_FAIL(num.from(sess_uid, *(expr_ctx.calc_buf_)))) { + LOG_WARN("convert int to number failed", K(ret), K(sess_uid)); + } else { + result.set_number(num); + } } return ret; } diff --git a/src/sql/parser/ob_item_type.h b/src/sql/parser/ob_item_type.h index 1a714a2a7..bf68f8b9b 100644 --- a/src/sql/parser/ob_item_type.h +++ b/src/sql/parser/ob_item_type.h @@ -426,6 +426,8 @@ typedef enum ObItemType { T_FUN_SYS_QUARTER = 711, T_FUN_SYS_BIT_LENGTH = 712, T_FUN_SYS_PI = 713, + T_FUN_SYS_EXPORT_SET = 714, + ///< @note add new mysql only function type before this line T_MYSQL_ONLY_SYS_MAX_OP = 800, diff --git a/src/sql/parser/type_name.c b/src/sql/parser/type_name.c index 22b334a3e..a3c5b5e49 100644 --- a/src/sql/parser/type_name.c +++ b/src/sql/parser/type_name.c @@ -1552,6 +1552,7 @@ const char* get_type_name(int type) case T_HASH_PARTITION_LIST : return "T_HASH_PARTITION_LIST"; case T_RANGE_PARTITION_LIST : return "T_RANGE_PARTITION_LIST"; case T_LIST_PARTITION_LIST : return "T_LIST_PARTITION_LIST"; + case T_FUN_SYS_EXPORT_SET : return "T_FUN_SYS_EXPORT_SET"; default:return "Unknown"; } } diff --git a/test/mysql_test/test_suite/expr/r/mysql/expr_export_set.result b/test/mysql_test/test_suite/expr/r/mysql/expr_export_set.result new file mode 100644 index 000000000..f641a31ab --- /dev/null +++ b/test/mysql_test/test_suite/expr/r/mysql/expr_export_set.result @@ -0,0 +1,315 @@ +================ expression export_set ================ +select export_set(0,"Y","N","-",5); +export_set(0,"Y","N","-",5) +N-N-N-N-N +select export_set(7,"Y","N","-",5); +export_set(7,"Y","N","-",5) +Y-Y-Y-N-N +select export_set(11,"Y","N","-",5); +export_set(11,"Y","N","-",5) +Y-Y-N-Y-N +select export_set(20,"Y","N","-",5); +export_set(20,"Y","N","-",5) +N-N-Y-N-Y +select export_set(9,"","","-",5); +export_set(9,"","","-",5) +---- +select export_set(9,"Y","N","-",5); +export_set(9,"Y","N","-",5) +Y-N-N-Y-N +select export_set(9,"左","右","-",5); +export_set(9,"左","右","-",5) +左-右-右-左-右 +select export_set(9,"上","下","-",5); +export_set(9,"上","下","-",5) +上-下-下-上-下 +select export_set(5,"Y","N",".",5); +export_set(5,"Y","N",".",5) +Y.N.Y.N.N +select export_set(5,"Y","N","=",5); +export_set(5,"Y","N","=",5) +Y=N=Y=N=N +select export_set(5,"Y","N","????????",5); +export_set(5,"Y","N","????????",5) +Y????????N????????Y????????N????????N +select export_set(100,"Y","N",".",3); +export_set(100,"Y","N",".",3) +N.N.Y +select export_set(100,"Y","N",".",5); +export_set(100,"Y","N",".",5) +N.N.Y.N.N +select export_set(100,"Y","N",".",7); +export_set(100,"Y","N",".",7) +N.N.Y.N.N.Y.Y +select export_set(100,"Y","N",".",10); +export_set(100,"Y","N",".",10) +N.N.Y.N.N.Y.Y.N.N.N +select export_set(null,"Y","N",".",5); +export_set(null,"Y","N",".",5) +NULL +select export_set(0,"Y","N",".",5); +export_set(0,"Y","N",".",5) +N.N.N.N.N +select export_set(5,null,"N",".",5); +export_set(5,null,"N",".",5) +NULL +select export_set(5,'',"N",".",5); +export_set(5,'',"N",".",5) +.N..N.N +select export_set(5,"Y",null,".",5); +export_set(5,"Y",null,".",5) +NULL +select export_set(5,"Y",'',".",5); +export_set(5,"Y",'',".",5) +Y..Y.. +select export_set(5,"Y","N",null,5); +export_set(5,"Y","N",null,5) +NULL +select export_set(5,"Y","N",'',5); +export_set(5,"Y","N",'',5) +YNYNN +select export_set(5,"Y","N",".",null); +export_set(5,"Y","N",".",null) +NULL +select export_set(5,"Y","N",".",0); +export_set(5,"Y","N",".",0) + +select export_set(55555555555555,"YY","NN",".",0); +export_set(55555555555555,"YY","NN",".",0) + +select export_set(55555555555555,"YY","NN",".......",0); +export_set(55555555555555,"YY","NN",".......",0) + +select export_set(100,'',1); +export_set(100,'',1) +1,1,,1,1,,,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 +select export_set(100,1,''); +export_set(100,1,'') +,,1,,,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +select export_set(100,1,0,''); +export_set(100,1,0,'') +0010011000000000000000000000000000000000000000000000000000000000 +select export_set(1000,'',1); +export_set(1000,'',1) +1,1,1,,1,,,,,,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 +select export_set(1000,1,''); +export_set(1000,1,'') +,,,1,,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +select export_set(1000,1,0,''); +export_set(1000,1,0,'') +0001011111000000000000000000000000000000000000000000000000000000 +select export_set(8,"Y","N"); +export_set(8,"Y","N") +N,N,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +select export_set(88,"Y","N"); +export_set(88,"Y","N") +N,N,N,Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +select export_set(888,"Y","N"); +export_set(888,"Y","N") +N,N,N,Y,Y,Y,Y,N,Y,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +select export_set(8888,"Y","N"); +export_set(8888,"Y","N") +N,N,N,Y,Y,Y,N,Y,N,Y,N,N,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +select export_set(8,"1","0"); +export_set(8,"1","0") +0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(8,"X","Y"); +export_set(8,"X","Y") +Y,Y,Y,X,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y +select export_set(8,"Y","N",'+'); +export_set(8,"Y","N",'+') +N+N+N+Y+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N+N +select export_set(8,"1","0",'*'); +export_set(8,"1","0",'*') +0*0*0*1*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0*0 +select export_set(8,"X","Y",'*'); +export_set(8,"X","Y",'*') +Y*Y*Y*X*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y*Y +select export_set(7,1,0,"-",5); +export_set(7,1,0,"-",5) +1-1-1-0-0 +select export_set(7,11,00,"-",5); +export_set(7,11,00,"-",5) +11-11-11-0-0 +select export_set(7,111,000,"-",5); +export_set(7,111,000,"-",5) +111-111-111-0-0 +select export_set(7,111,000,5,5); +export_set(7,111,000,5,5) +111511151115050 +select export_set(true,1,0); +export_set(true,1,0) +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(true,"1","0"); +export_set(true,"1","0") +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(false,1,0); +export_set(false,1,0) +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(false,"1","0"); +export_set(false,"1","0") +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(1.4,1,0); +export_set(1.4,1,0) +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(2.4,1,0); +export_set(2.4,1,0) +0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +select export_set(1.4,"y","n"); +export_set(1.4,"y","n") +y,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n +select export_set(2.4,"y","n"); +export_set(2.4,"y","n") +n,y,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n,n +select export_set(9223372036854775808,"Y","N"); +export_set(9223372036854775808,"Y","N") +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(9223372036854775809,"Y","N"); +export_set(9223372036854775809,"Y","N") +Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(-9223372036854775808,"Y","N"); +export_set(-9223372036854775808,"Y","N") +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(18446744073709551615,"Y","N"); +export_set(18446744073709551615,"Y","N") +Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y +select export_set(9223372036854775808,"Y","N",",",92233720368547758080000000000); +export_set(9223372036854775808,"Y","N",",",92233720368547758080000000000) +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(9223372036854775808,"Y","N",",",9223372036854775808); +export_set(9223372036854775808,"Y","N",",",9223372036854775808) +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(9223372036854775809,"Y","N",",",9223372036854775809); +export_set(9223372036854775809,"Y","N",",",9223372036854775809) +Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(9223372036854775809,"Y","N",",",9223372036854775809000000000000); +export_set(9223372036854775809,"Y","N",",",9223372036854775809000000000000) +Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(-9223372036854775808,"Y","N",",",-9223372036854775808); +export_set(-9223372036854775808,"Y","N",",",-9223372036854775808) +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(-9223372036854775808,"Y","N",",",-9223372036854775808000000000); +export_set(-9223372036854775808,"Y","N",",",-9223372036854775808000000000) +N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,Y +select export_set(18446744073709551615,"Y","N",",",18446744073709551615); +export_set(18446744073709551615,"Y","N",",",18446744073709551615) +Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y +select export_set(18446744073709551615,"Y","N",",",1844674407370955161500000000000); +export_set(18446744073709551615,"Y","N",",",1844674407370955161500000000000) +Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y,Y +select export_set(); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(1); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(1,2); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(""); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set("",""); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(5,5); +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(a,2,3); +ERROR 42S22: Unknown column 'a' in 'field list' +select export_set(1,2,3,a); +ERROR 42S22: Unknown column 'a' in 'field list' +select export_set(1,2,3,4,a); +ERROR 42S22: Unknown column 'a' in 'field list' +drop table if exists test; +create table test(c1 int, c2 varchar(20), c3 varchar(20), c4 varchar(20), c5 int); +insert into test values(11,"Y","N",",",10); +insert into test values(null,"Y","N",",",10); +insert into test values(11,null,"N",",",10); +insert into test values(11,"Y",null,",",10); +insert into test values(11,"Y","N",null,10); +insert into test values(11,"Y","N",",",null); +insert into test values(null,null,null,null,null); +select export_set(c1,c2,c3,c4,c5) from test; +export_set(c1,c2,c3,c4,c5) +Y,Y,N,Y,N,N,N,N,N,N +NULL +NULL +NULL +NULL +NULL +NULL +select export_set(c1,c2,c3,c4) from test; +export_set(c1,c2,c3,c4) +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +NULL +NULL +NULL +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +select export_set(c1,c2,c3) from test; +export_set(c1,c2,c3) +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +NULL +NULL +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +insert into test values(100000,"+","-",",",1000000); +insert into test values(55555555,"+","-",",",100000); +insert into test values(7777777,"+","-",",",10000); +select export_set(c1,c2,c3,c4,5) from test; +export_set(c1,c2,c3,c4,5) +Y,Y,N,Y,N +NULL +NULL +NULL +NULL +Y,Y,N,Y,N +NULL +-,-,-,-,- ++,+,-,-,- ++,-,-,-,+ +select export_set(c1,c2,c3,'??',5) from test; +export_set(c1,c2,c3,'??',5) +Y??Y??N??Y??N +NULL +NULL +NULL +Y??Y??N??Y??N +Y??Y??N??Y??N +NULL +-??-??-??-??- ++??+??-??-??- ++??-??-??-??+ +select export_set(c1,c2,c3) from test; +export_set(c1,c2,c3) +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +NULL +NULL +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +Y,Y,N,Y,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N +NULL +-,-,-,-,-,+,-,+,-,+,+,-,-,-,-,+,+,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,- ++,+,-,-,-,+,+,+,+,-,+,-,+,+,-,+,+,+,+,+,-,-,+,-,+,+,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,- ++,-,-,-,+,+,+,+,+,-,+,+,-,+,-,+,-,+,+,-,+,+,+,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,- +select export_set(c1) from test; +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set(c1,c2) from test; +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +select export_set() from test; +ERROR 42000: Incorrect parameter count in the call to native function 'export_set' +drop table test; +drop table if exists t1; +create table t1 as select export_set(0,"Y","N","-",5); +desc t1; +Field Type Null Key Default Extra +export_set(0,"Y","N","-",5) varchar(127) YES NULL +drop table t1; +create table t1 as select export_set(99,"YYY","NX","---",77); +desc t1; +Field Type Null Key Default Extra +export_set(99,"YYY","NX","---",77) varchar(381) YES NULL +drop table t1; +create table t1 as select export_set(99,"1","11","111",77); +desc t1; +Field Type Null Key Default Extra +export_set(99,"1","11","111",77) varchar(317) YES NULL +drop table t1; diff --git a/test/mysql_test/test_suite/expr/t/expr_export_set.test b/test/mysql_test/test_suite/expr/t/expr_export_set.test new file mode 100644 index 000000000..46ced4031 --- /dev/null +++ b/test/mysql_test/test_suite/expr/t/expr_export_set.test @@ -0,0 +1,151 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log +#/--disableabortonerror/ +#/test for export_set function in ob_expr_export_set.cpp/ +--enable_abort_on_error +--echo ================ expression export_set ================ + +# 基本检查 +select export_set(0,"Y","N","-",5); +select export_set(7,"Y","N","-",5); +select export_set(11,"Y","N","-",5); +select export_set(20,"Y","N","-",5); +select export_set(9,"","","-",5); +select export_set(9,"Y","N","-",5); +select export_set(9,"左","右","-",5); +select export_set(9,"上","下","-",5); +select export_set(5,"Y","N",".",5); +select export_set(5,"Y","N","=",5); +select export_set(5,"Y","N","????????",5); +select export_set(100,"Y","N",".",3); +select export_set(100,"Y","N",".",5); +select export_set(100,"Y","N",".",7); +select export_set(100,"Y","N",".",10); + +# 参数NULL检查 +select export_set(null,"Y","N",".",5); +select export_set(0,"Y","N",".",5); +select export_set(5,null,"N",".",5); +select export_set(5,'',"N",".",5); +select export_set(5,"Y",null,".",5); +select export_set(5,"Y",'',".",5); +select export_set(5,"Y","N",null,5); +select export_set(5,"Y","N",'',5); +select export_set(5,"Y","N",".",null); +select export_set(5,"Y","N",".",0); +select export_set(55555555555555,"YY","NN",".",0); +select export_set(55555555555555,"YY","NN",".......",0); +select export_set(100,'',1); +select export_set(100,1,''); +select export_set(100,1,0,''); +select export_set(1000,'',1); +select export_set(1000,1,''); +select export_set(1000,1,0,''); + +# 默认参数检查 +select export_set(8,"Y","N"); +select export_set(88,"Y","N"); +select export_set(888,"Y","N"); +select export_set(8888,"Y","N"); +select export_set(8,"1","0"); +select export_set(8,"X","Y"); +select export_set(8,"Y","N",'+'); +select export_set(8,"1","0",'*'); +select export_set(8,"X","Y",'*'); + +# 参数类型不同 +select export_set(7,1,0,"-",5); +select export_set(7,11,00,"-",5); +select export_set(7,111,000,"-",5); +select export_set(7,111,000,5,5); +select export_set(true,1,0); +select export_set(true,"1","0"); +select export_set(false,1,0); +select export_set(false,"1","0"); +select export_set(1.4,1,0); +select export_set(2.4,1,0); +select export_set(1.4,"y","n"); +select export_set(2.4,"y","n"); + +# 边界检查 +# 超过uint64的上界,int64的下界,ob对溢出的处理和mysql不同,这是mysql的bug,不兼容 +# 目前保证-9223372036854775808到18446744073709551615与mysql兼容 +# select export_set(1111111111111111111111111111111111111111111111111111,"Y","N"); +select export_set(9223372036854775808,"Y","N"); +select export_set(9223372036854775809,"Y","N"); +select export_set(-9223372036854775808,"Y","N"); +select export_set(18446744073709551615,"Y","N"); +select export_set(9223372036854775808,"Y","N",",",92233720368547758080000000000); +select export_set(9223372036854775808,"Y","N",",",9223372036854775808); +select export_set(9223372036854775809,"Y","N",",",9223372036854775809); +select export_set(9223372036854775809,"Y","N",",",9223372036854775809000000000000); +select export_set(-9223372036854775808,"Y","N",",",-9223372036854775808); +select export_set(-9223372036854775808,"Y","N",",",-9223372036854775808000000000); +select export_set(18446744073709551615,"Y","N",",",18446744073709551615); +select export_set(18446744073709551615,"Y","N",",",1844674407370955161500000000000); + +# 参数错误检查 +--error 1582 +select export_set(); +--error 1582 +select export_set(1); +--error 1582 +select export_set(1,2); +--error 1582 +select export_set(""); +--error 1582 +select export_set("",""); +--error 1582 +select export_set(5,5); +--error 1054 +select export_set(a,2,3); +--error 1054 +select export_set(1,2,3,a); +--error 1054 +select export_set(1,2,3,4,a); + +# 用表数据做参数 +--disable_warnings +drop table if exists test; +--enable_warnings +create table test(c1 int, c2 varchar(20), c3 varchar(20), c4 varchar(20), c5 int); +insert into test values(11,"Y","N",",",10); +insert into test values(null,"Y","N",",",10); +insert into test values(11,null,"N",",",10); +insert into test values(11,"Y",null,",",10); +insert into test values(11,"Y","N",null,10); +insert into test values(11,"Y","N",",",null); +insert into test values(null,null,null,null,null); +select export_set(c1,c2,c3,c4,c5) from test; +select export_set(c1,c2,c3,c4) from test; +select export_set(c1,c2,c3) from test; +insert into test values(100000,"+","-",",",1000000); +insert into test values(55555555,"+","-",",",100000); +insert into test values(7777777,"+","-",",",10000); +select export_set(c1,c2,c3,c4,5) from test; +select export_set(c1,c2,c3,'??',5) from test; +select export_set(c1,c2,c3) from test; +--error 1582 +select export_set(c1) from test; +--error 1582 +select export_set(c1,c2) from test; +--error 1582 +select export_set() from test; + +drop table test; + +# ctas cases +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 as select export_set(0,"Y","N","-",5); +desc t1; +drop table t1; +create table t1 as select export_set(99,"YYY","NX","---",77); +desc t1; +drop table t1; +create table t1 as select export_set(99,"1","11","111",77); +desc t1; +drop table t1; +