[to #48700654] fix parser & resolver of user defined window function to support calling with database name
This commit is contained in:
@ -3362,6 +3362,7 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
case T_FUN_JSON_OBJECTAGG:
|
||||
SET_SYMBOL_IF_EMPTY("json_objectagg");
|
||||
case T_FUN_PL_AGG_UDF: {
|
||||
ObString database;
|
||||
if (OB_ISNULL(expr->get_agg_expr())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), KPC(expr));
|
||||
@ -3372,11 +3373,26 @@ int ObRawExprPrinter::print(ObWinFunRawExpr *expr)
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), KPC(expr));
|
||||
} else {
|
||||
symbol = static_cast<ObUDFRawExpr*>(udf_expr)->get_func_name();
|
||||
ObUDFRawExpr* udf = static_cast<ObUDFRawExpr*>(udf_expr);
|
||||
database = udf->get_database_name();
|
||||
symbol = udf->get_func_name();
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
DATA_PRINTF("%.*s(", LEN_AND_PTR(symbol));
|
||||
if(!database.empty()){
|
||||
PRINT_QUOT;
|
||||
DATA_PRINTF("%.*s", LEN_AND_PTR(database));
|
||||
PRINT_QUOT;
|
||||
DATA_PRINTF(".");
|
||||
}
|
||||
if (T_FUN_PL_AGG_UDF == type) {
|
||||
PRINT_QUOT;
|
||||
DATA_PRINTF("%.*s", LEN_AND_PTR(symbol));
|
||||
PRINT_QUOT;
|
||||
} else {
|
||||
DATA_PRINTF("%.*s", LEN_AND_PTR(symbol));
|
||||
}
|
||||
DATA_PRINTF("(");
|
||||
}
|
||||
// distinct, default 'all', not print
|
||||
if (OB_SUCC(ret)) {
|
||||
|
||||
@ -6291,12 +6291,29 @@ int ObRawExprResolverImpl::process_window_function_node(const ParseNode *node, O
|
||||
T_OBJ_ACCESS_REF, 2))) {
|
||||
LOG_WARN("failed to new parse node", K(ret), K(obj_access_node));
|
||||
} else {
|
||||
agg_udf_node->children_[0] = func_node->children_[0];
|
||||
agg_udf_node->children_[1] = func_node->children_[1];
|
||||
agg_udf_node->children_[2] = func_node->children_[2];
|
||||
obj_access_node->children_[0] = agg_udf_node;
|
||||
obj_access_node->children_[1] = NULL;
|
||||
func_node = obj_access_node;
|
||||
// structure of T_FUN_PL_AGG_UDF: refer to sql_parser_oracle_mode.y
|
||||
CK (OB_NOT_NULL(func_node->children_[0])
|
||||
&& T_EXPR_LIST == func_node->children_[0]->type_
|
||||
&& 2 == func_node->children_[0]->num_child_);
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
agg_udf_node->children_[0] = func_node->children_[0]->children_[0]; // restore IDENT node
|
||||
agg_udf_node->children_[1] = func_node->children_[1];
|
||||
agg_udf_node->children_[2] = func_node->children_[2];
|
||||
|
||||
obj_access_node->children_[0] = agg_udf_node;
|
||||
obj_access_node->children_[1] = nullptr;
|
||||
|
||||
if (nullptr != func_node->children_[0]->children_[1]) { // check if database name is present
|
||||
ParseNode *parent_obj_access = nullptr;
|
||||
OZ (ObRawExprUtils::new_parse_node(parent_obj_access, ctx_.expr_factory_,T_OBJ_ACCESS_REF, 2));
|
||||
OX (parent_obj_access->children_[0] = func_node->children_[0]->children_[1]);
|
||||
OX (parent_obj_access->children_[1] = obj_access_node);
|
||||
OX (obj_access_node = parent_obj_access);
|
||||
}
|
||||
|
||||
OX (func_node = obj_access_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
|
||||
Reference in New Issue
Block a user