From d2aa5459a9e16ac630ea4c9852d907d745e4bda6 Mon Sep 17 00:00:00 2001 From: totaj Date: Fri, 15 Sep 2023 19:57:18 +0800 Subject: [PATCH] Fix select case with uint. --- contrib/dolphin/expected/test_condition.out | 24 +++++++++++++++++++ .../include/plugin_parser/parse_oper.h | 10 ++++---- .../dolphin/plugin_parser/parse_coerce.cpp | 22 ++++++++++++++--- contrib/dolphin/sql/test_condition.sql | 12 ++++++++-- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/contrib/dolphin/expected/test_condition.out b/contrib/dolphin/expected/test_condition.out index 65ee7b38a..7644b3a14 100644 --- a/contrib/dolphin/expected/test_condition.out +++ b/contrib/dolphin/expected/test_condition.out @@ -8537,6 +8537,30 @@ select strcmp(blb, txt) from typeset; -1 (1 row) +create table t1 (a int, b bigint unsigned); +create table t2 (c int); +insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997), +(3,11120436154190595086); +insert into t2 (c) values (1), (2), (3); +select case t1.a when 0 then 0 else t1.b end from t1 order by a; + b +---------------------- + 4572794622775114594 + 18196094287899841997 + 11120436154190595086 +(3 rows) + +select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 +join t2 on t1.a=t2.c order by d; + a | d +---+---------------------- + 1 | 4572794622775114594 + 3 | 11120436154190595086 + 2 | 18196094287899841997 +(3 rows) + +drop table t1; +drop table t2; drop schema db_test_condition cascade; NOTICE: drop cascades to table typeset reset current_schema; diff --git a/contrib/dolphin/include/plugin_parser/parse_oper.h b/contrib/dolphin/include/plugin_parser/parse_oper.h index 492c68dab..57c4b0583 100644 --- a/contrib/dolphin/include/plugin_parser/parse_oper.h +++ b/contrib/dolphin/include/plugin_parser/parse_oper.h @@ -50,11 +50,11 @@ extern Oid oprfuncid(Operator op); extern bool IsIntType(Oid typeoid); extern bool IsCharType(Oid typeoid); #ifdef DOLPHIN -extern inline bool IsUnsignedIntType(Oid typeoid); -extern inline bool IsFloatType(Oid typeoid); -extern inline bool IsNumericType(Oid typeoid); -extern inline bool IsDolphinStringType(Oid typeoid); -extern inline bool IsDatetimeType(Oid typeoid); +extern bool IsUnsignedIntType(Oid typeoid); +extern bool IsFloatType(Oid typeoid); +extern bool IsNumericType(Oid typeoid); +extern bool IsDolphinStringType(Oid typeoid); +extern bool IsDatetimeType(Oid typeoid); #endif /* Build expression tree for an operator invocation */ diff --git a/contrib/dolphin/plugin_parser/parse_coerce.cpp b/contrib/dolphin/plugin_parser/parse_coerce.cpp index 0f3cb986a..7db6d95d4 100644 --- a/contrib/dolphin/plugin_parser/parse_coerce.cpp +++ b/contrib/dolphin/plugin_parser/parse_coerce.cpp @@ -31,6 +31,7 @@ #include "plugin_parser/parse_relation.h" #include "plugin_parser/parse_type.h" #ifdef DOLPHIN +#include "plugin_parser/parse_oper.h" #include "plugin_commands/mysqlmode.h" #endif #include "utils/builtins.h" @@ -1934,7 +1935,15 @@ static Oid choose_specific_expr_type(ParseState* pstate, List* exprs, const char } preferType = getBaseType(exprType(preferExpr)); - get_type_category_preferred(preferType, &preferCategory, &pispreferred); +#ifdef DOLPHIN + if (IsUnsignedIntType(preferType)) { + preferCategory = 'N'; + pispreferred = false; + } else +#endif + { + get_type_category_preferred(preferType, &preferCategory, &pispreferred); + } break; } if (lc == NULL) { @@ -1956,8 +1965,15 @@ static Oid choose_specific_expr_type(ParseState* pstate, List* exprs, const char if (nextType != preferType) { TYPCATEGORY nextCategory; bool nispreferred = false; - - get_type_category_preferred(nextType, &nextCategory, &nispreferred); +#ifdef DOLPHIN + if (IsUnsignedIntType(nextType)) { + nextCategory = 'N'; + nispreferred = false; + } else +#endif + { + get_type_category_preferred(nextType, &nextCategory, &nispreferred); + } /* * Both types in different categories, if they are numeric and string type diff --git a/contrib/dolphin/sql/test_condition.sql b/contrib/dolphin/sql/test_condition.sql index 7dc8df153..4cd9bbc20 100644 --- a/contrib/dolphin/sql/test_condition.sql +++ b/contrib/dolphin/sql/test_condition.sql @@ -1285,8 +1285,16 @@ select strcmp(vch, blb) from typeset; select strcmp(vch, txt) from typeset; select strcmp(blb, txt) from typeset; - - +create table t1 (a int, b bigint unsigned); +create table t2 (c int); +insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997), +(3,11120436154190595086); +insert into t2 (c) values (1), (2), (3); +select case t1.a when 0 then 0 else t1.b end from t1 order by a; +select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1 +join t2 on t1.a=t2.c order by d; +drop table t1; +drop table t2; drop schema db_test_condition cascade; reset current_schema; -- Gitee