diff --git a/src/common/backend/parser/parse_expr.cpp b/src/common/backend/parser/parse_expr.cpp index b7b881b98..3d61bdf04 100644 --- a/src/common/backend/parser/parse_expr.cpp +++ b/src/common/backend/parser/parse_expr.cpp @@ -4156,8 +4156,13 @@ static Node *transformStartWithWhereClauseColumnRef(ParseState *pstate, ColumnRe return NULL; } -PlannedStmt* getCursorStreamFromFuncArg(FuncExpr* funcexpr, CursorExpression** ce) +PlannedStmt* getCursorStreamFromFuncArg(Node* node, CursorExpression** ce) { + if (!IsA(node, FuncExpr)) { + return NULL; + } + + FuncExpr* funcexpr = (FuncExpr*)node; ListCell* lc = NULL; foreach (lc, funcexpr->args) { Node* arg = (Node*)lfirst(lc); diff --git a/src/common/backend/parser/parse_relation.cpp b/src/common/backend/parser/parse_relation.cpp index f92c68b20..1e7660fe6 100755 --- a/src/common/backend/parser/parse_relation.cpp +++ b/src/common/backend/parser/parse_relation.cpp @@ -1792,11 +1792,9 @@ RangeTblEntry* addRangeTableEntryForFunction( * create_functionscan_path need cursorDop to determine * wheather functionscan smp or not. */ - if (IsA(funcexpr, FuncExpr)) { - PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg((FuncExpr*)funcexpr); - if (cursorPstmt != NULL && IsA(cursorPstmt->planTree, Stream)) { - rte->cursorDop = cursorPstmt->planTree->lefttree->dop; - } + PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg(funcexpr); + if (cursorPstmt != NULL && IsA(cursorPstmt->planTree, Stream)) { + rte->cursorDop = cursorPstmt->planTree->lefttree->dop; } eref = makeAlias(alias ? alias->aliasname : funcname, NIL); diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 26683e746..2e25e066f 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -6246,7 +6246,7 @@ static FunctionScan* make_functionscan(List* qptlist, List* qpqual, Index scanre node->funccolcollations = funccolcollations; CursorExpression* ce = NULL; - PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg((FuncExpr*)funcexpr, &ce); + PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg(funcexpr, &ce); if (cursorPstmt == NULL) { return node; } diff --git a/src/gausskernel/optimizer/plan/streamplan_utils.cpp b/src/gausskernel/optimizer/plan/streamplan_utils.cpp index 50ca0f152..3780cf127 100755 --- a/src/gausskernel/optimizer/plan/streamplan_utils.cpp +++ b/src/gausskernel/optimizer/plan/streamplan_utils.cpp @@ -1898,7 +1898,7 @@ void finalize_node_id(Plan* result_plan, int* plan_node_id, int* parent_node_id, } } break; case T_FunctionScan: { - PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg((FuncExpr*)((FunctionScan*)result_plan)->funcexpr); + PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg(((FunctionScan*)result_plan)->funcexpr); if (cursorPstmt != NULL) { cursorPstmt->planTree->cursor_owner_node_id = result_plan->plan_node_id; set_stream_plan_cursor_walker(cursorPstmt->planTree); diff --git a/src/gausskernel/process/stream/execStream.cpp b/src/gausskernel/process/stream/execStream.cpp index 9416ca135..5cec707b7 100755 --- a/src/gausskernel/process/stream/execStream.cpp +++ b/src/gausskernel/process/stream/execStream.cpp @@ -971,7 +971,7 @@ static void InitStreamFlow(StreamFlowCtl* ctl) InitStreamFlow(ctl); } break; case T_FunctionScan: { - PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg((FuncExpr*)((FunctionScan*)oldPlan)->funcexpr); + PlannedStmt* cursorPstmt = getCursorStreamFromFuncArg(((FunctionScan*)oldPlan)->funcexpr); if (cursorPstmt != NULL) { ctl->plan = cursorPstmt->planTree; diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h index 1b9c1a929..fd8b6b2d3 100644 --- a/src/include/parser/parse_expr.h +++ b/src/include/parser/parse_expr.h @@ -39,6 +39,6 @@ extern bool IsQuerySWCBRewrite(Query *query); extern bool IsSWCBRewriteRTE(RangeTblEntry *rte); extern Datum GetTypeZeroValue(Form_pg_attribute att_tup); typedef Datum (*getTypeZeroValueFunc)(Form_pg_attribute att_tup); -extern PlannedStmt* getCursorStreamFromFuncArg(FuncExpr* funcexpr, CursorExpression** ce = NULL); +extern PlannedStmt* getCursorStreamFromFuncArg(Node* node, CursorExpression** ce = NULL); #endif /* PARSE_EXPR_H */ diff --git a/src/test/regress/expected/hw_datatype_2.out b/src/test/regress/expected/hw_datatype_2.out index 191bf070c..9ebab0daa 100644 --- a/src/test/regress/expected/hw_datatype_2.out +++ b/src/test/regress/expected/hw_datatype_2.out @@ -808,6 +808,12 @@ select least(0.9, 1); .9 (1 row) +select * from greatest(1, 1.1); + greatest +---------- + 1.1 +(1 row) + create or replace function test_cast(a numeric) returns int as $$ diff --git a/src/test/regress/sql/hw_datatype_2.sql b/src/test/regress/sql/hw_datatype_2.sql index e42098c15..241e27d49 100644 --- a/src/test/regress/sql/hw_datatype_2.sql +++ b/src/test/regress/sql/hw_datatype_2.sql @@ -319,6 +319,8 @@ select greatest(1.1, 1); select least(1, 0.9); select least(0.9, 1); +select * from greatest(1, 1.1); + create or replace function test_cast(a numeric) returns int as $$