Fix print window function bug
This commit is contained in:
parent
2c86db0c46
commit
f6c64ffeb2
@ -5029,7 +5029,6 @@ int ObWindow::assign(const ObWindow &other)
|
||||
void ObWinFunRawExpr::clear_child()
|
||||
{
|
||||
func_type_ = T_MAX;
|
||||
is_distinct_ = false;
|
||||
func_params_.reset();
|
||||
partition_exprs_.reset();
|
||||
order_items_.reset();
|
||||
@ -5058,7 +5057,6 @@ int ObWinFunRawExpr::assign(const ObRawExpr &other)
|
||||
LOG_WARN("failed to assign lower bound", K(ret));
|
||||
} else {
|
||||
func_type_ = tmp.func_type_;
|
||||
is_distinct_ = tmp.is_distinct_;
|
||||
is_ignore_null_ = tmp.is_ignore_null_;
|
||||
is_from_first_ = tmp.is_from_first_;
|
||||
agg_expr_ = tmp.agg_expr_;
|
||||
|
@ -4283,7 +4283,6 @@ public:
|
||||
: ObRawExpr(),
|
||||
ObWindow(),
|
||||
func_type_(T_MAX),
|
||||
is_distinct_(false),
|
||||
is_ignore_null_(false),
|
||||
is_from_first_(false),
|
||||
agg_expr_(NULL),
|
||||
@ -4295,7 +4294,6 @@ public:
|
||||
: ObRawExpr(alloc),
|
||||
ObWindow(),
|
||||
func_type_(T_MAX),
|
||||
is_distinct_(false),
|
||||
is_ignore_null_(false),
|
||||
is_from_first_(false),
|
||||
agg_expr_(NULL),
|
||||
@ -4312,8 +4310,6 @@ public:
|
||||
const common::ObIArray<ObRawExpr *> &new_exprs);
|
||||
inline void set_func_type(ObItemType func_type)
|
||||
{ func_type_ = func_type; }
|
||||
inline void set_is_distinct(bool is_distinct)
|
||||
{ is_distinct_ = is_distinct; }
|
||||
inline void set_is_ignore_null(bool is_ignore_null)
|
||||
{ is_ignore_null_ = is_ignore_null; }
|
||||
inline void set_is_from_first(bool is_from_first)
|
||||
@ -4323,7 +4319,6 @@ public:
|
||||
inline void set_agg_expr(ObAggFunRawExpr *agg_expr)
|
||||
{ agg_expr_ = agg_expr; }
|
||||
inline ObItemType get_func_type() const { return func_type_; }
|
||||
inline bool is_distinct() { return is_distinct_; }
|
||||
inline bool is_ignore_null() { return is_ignore_null_; }
|
||||
inline bool is_from_first() { return is_from_first_; }
|
||||
inline const common::ObIArray<ObRawExpr *> &get_func_params() const { return func_params_; }
|
||||
@ -4369,7 +4364,6 @@ public:
|
||||
N_EXPR_INFO, info_,
|
||||
N_REL_ID, rel_ids_,
|
||||
K_(func_type),
|
||||
K_(is_distinct),
|
||||
K_(func_params),
|
||||
K_(partition_exprs),
|
||||
K_(order_items),
|
||||
@ -4384,7 +4378,6 @@ public:
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObWinFunRawExpr);
|
||||
ObItemType func_type_;
|
||||
bool is_distinct_;
|
||||
bool is_ignore_null_;
|
||||
bool is_from_first_;
|
||||
common::ObArray<ObRawExpr *, common::ModulePageAllocator, true> func_params_;
|
||||
|
@ -3266,13 +3266,17 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
case T_FUN_JSON_OBJECTAGG:
|
||||
SET_SYMBOL_IF_EMPTY("json_objectagg");
|
||||
case T_FUN_PL_AGG_UDF: {
|
||||
if (type == T_FUN_PL_AGG_UDF) {
|
||||
if (OB_ISNULL(expr->get_pl_agg_udf_expr()) ||
|
||||
OB_UNLIKELY(!expr->get_pl_agg_udf_expr()->is_udf_expr())) {
|
||||
if (OB_ISNULL(expr->get_agg_expr())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), KPC(expr));
|
||||
} else if (type == T_FUN_PL_AGG_UDF) {
|
||||
ObRawExpr *udf_expr = expr->get_agg_expr()->get_pl_agg_udf_expr();
|
||||
if (OB_ISNULL(udf_expr) ||
|
||||
OB_UNLIKELY(!udf_expr->is_udf_expr())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
LOG_WARN("get unexpected null", K(ret), KPC(expr));
|
||||
} else {
|
||||
symbol = static_cast<ObUDFRawExpr*>(expr->get_pl_agg_udf_expr())->get_func_name();
|
||||
symbol = static_cast<ObUDFRawExpr*>(udf_expr)->get_func_name();
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -3280,7 +3284,7 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
}
|
||||
// distinct, default 'all', not print
|
||||
if (OB_SUCC(ret)) {
|
||||
if (expr->is_distinct()) {
|
||||
if (expr->get_agg_expr()->is_param_distinct()) {
|
||||
DATA_PRINTF("distinct ");
|
||||
}
|
||||
}
|
||||
@ -3305,7 +3309,8 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
}
|
||||
DATA_PRINTF(")");
|
||||
DATA_PRINTF(" over(");
|
||||
if (OB_FAIL(print_partition_exprs(expr))) {
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(print_partition_exprs(expr))) {
|
||||
LOG_WARN("failed to print partition exprs.", K(ret));
|
||||
} else if (OB_FAIL(print_order_items(expr))) {
|
||||
LOG_WARN("failed to print order items.", K(ret));
|
||||
@ -3462,72 +3467,9 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
break;
|
||||
}
|
||||
case T_FUN_GROUP_CONCAT: {
|
||||
// mysql: group_concat(distinct c1,c2+1 order by c1 desc separator ',')
|
||||
// oracle: listagg(c1,',') within group(order by c1);
|
||||
if (lib::is_oracle_mode()) {
|
||||
SET_SYMBOL_IF_EMPTY("listagg");
|
||||
} else {
|
||||
SET_SYMBOL_IF_EMPTY("group_concat");
|
||||
if (OB_FAIL(print(expr->get_agg_expr()))) {
|
||||
LOG_WARN("failed to print agg expr", K(ret));
|
||||
}
|
||||
DATA_PRINTF("%.*s(", LEN_AND_PTR(symbol));
|
||||
// distinct
|
||||
if (OB_SUCC(ret)) {
|
||||
if (expr->is_distinct()) {
|
||||
DATA_PRINTF("distinct ");
|
||||
}
|
||||
}
|
||||
// expr list
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < expr->get_agg_expr()->get_real_param_count(); ++i) {
|
||||
PRINT_EXPR(expr->get_agg_expr()->get_real_param_exprs().at(i));
|
||||
DATA_PRINTF(",");
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
--*pos_;
|
||||
}
|
||||
if (lib::is_oracle_mode() && 0 == expr->get_order_items().count()) {// oracle 模式 listagg 支持无 within group
|
||||
/* do nothing */
|
||||
} else if (lib::is_oracle_mode()) {
|
||||
DATA_PRINTF(") within group (");
|
||||
// order by
|
||||
if (OB_SUCC(ret)) {
|
||||
const ObIArray<OrderItem> &order_items = expr->get_agg_expr()->get_order_items();
|
||||
int64_t order_item_size = order_items.count();
|
||||
if (order_item_size > 0) {
|
||||
DATA_PRINTF(" order by ");
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < order_item_size; ++i) {
|
||||
const OrderItem &order_item = order_items.at(i);
|
||||
PRINT_EXPR(order_item.expr_);
|
||||
if (OB_SUCC(ret)) {
|
||||
if (lib::is_mysql_mode()) {
|
||||
if (is_descending_direction(order_item.order_type_)) {
|
||||
DATA_PRINTF(" desc ");
|
||||
}
|
||||
} else if (order_item.order_type_ == NULLS_FIRST_ASC) {
|
||||
DATA_PRINTF(" asc nulls first ");
|
||||
} else if (order_item.order_type_ == NULLS_LAST_ASC) {//use default value
|
||||
/*do nothing*/
|
||||
} else if (order_item.order_type_ == NULLS_FIRST_DESC) {//use default value
|
||||
DATA_PRINTF(" desc ");
|
||||
} else if (order_item.order_type_ == NULLS_LAST_DESC) {
|
||||
DATA_PRINTF(" desc nulls last ");
|
||||
} else {/*do nothing*/}
|
||||
}
|
||||
DATA_PRINTF(",");
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
--*pos_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// separator
|
||||
if (OB_SUCC(ret)) {
|
||||
if (expr->get_agg_expr()->get_separator_param_expr()) {
|
||||
DATA_PRINTF(" separator ");
|
||||
PRINT_EXPR(expr->get_agg_expr()->get_separator_param_expr());
|
||||
}
|
||||
}
|
||||
DATA_PRINTF(")");
|
||||
if (OB_SUCC(ret)) {
|
||||
DATA_PRINTF(" over(");
|
||||
if (OB_FAIL(print_partition_exprs(expr))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user