Support MIN/MAX function for enum/set data type
This commit is contained in:
		| @ -1403,6 +1403,28 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr& expr) | |||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|  |       case T_FUN_MAX: | ||||||
|  |       case T_FUN_MIN: { | ||||||
|  |         ObRawExpr *child_expr = NULL; | ||||||
|  |         if (OB_ISNULL(child_expr = expr.get_param_expr(0))) { | ||||||
|  |           ret = OB_ERR_UNEXPECTED; | ||||||
|  |           LOG_WARN("param expr is null"); | ||||||
|  |         } else if (OB_UNLIKELY(ob_is_enumset_tc(child_expr->get_data_type()))) { | ||||||
|  |           // To compatible with MySQL, we need to add cast expression that enumset to varchar | ||||||
|  |           // to evalute MIN/MAX aggregate functions. | ||||||
|  |           need_add_cast = true; | ||||||
|  |           const ObExprResType& res_type = child_expr->get_result_type(); | ||||||
|  |           result_type.set_varchar(); | ||||||
|  |           result_type.set_length(res_type.get_length()); | ||||||
|  |           result_type.set_collation_type(res_type.get_collation_type()); | ||||||
|  |           result_type.set_collation_level(CS_LEVEL_IMPLICIT); | ||||||
|  |           expr.set_result_type(result_type); | ||||||
|  |         } else { | ||||||
|  |           expr.set_result_type(child_expr->get_result_type()); | ||||||
|  |           expr.unset_result_flag(OB_MYSQL_NOT_NULL_FLAG); | ||||||
|  |         } | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|       default: { |       default: { | ||||||
|         expr.set_result_type(expr.get_param_expr(0)->get_result_type()); |         expr.set_result_type(expr.get_param_expr(0)->get_result_type()); | ||||||
|         expr.unset_result_flag(OB_MYSQL_NOT_NULL_FLAG); |         expr.unset_result_flag(OB_MYSQL_NOT_NULL_FLAG); | ||||||
|  | |||||||
| @ -667,7 +667,9 @@ int ObRawExprWrapEnumSet::visit(ObCaseOpRawExpr& expr) | |||||||
| int ObRawExprWrapEnumSet::visit(ObAggFunRawExpr& expr) | int ObRawExprWrapEnumSet::visit(ObAggFunRawExpr& expr) | ||||||
| { | { | ||||||
|   int ret = OB_SUCCESS; |   int ret = OB_SUCCESS; | ||||||
|   if (expr.has_enum_set_column() && T_FUN_GROUP_CONCAT == expr.get_expr_type()) { |   if (expr.has_enum_set_column() && (T_FUN_GROUP_CONCAT == expr.get_expr_type() || | ||||||
|  |                                      T_FUN_MAX == expr.get_expr_type() || | ||||||
|  |                                      T_FUN_MIN == expr.get_expr_type())) { | ||||||
|     const ObIArray<ObRawExpr*>& real_parm_exprs = expr.get_real_param_exprs(); |     const ObIArray<ObRawExpr*>& real_parm_exprs = expr.get_real_param_exprs(); | ||||||
|     const bool is_same_need = false; |     const bool is_same_need = false; | ||||||
|     for (int64_t i = 0; OB_SUCC(ret) && i < real_parm_exprs.count(); ++i) { |     for (int64_t i = 0; OB_SUCC(ret) && i < real_parm_exprs.count(); ++i) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 br0
					br0