diff --git a/contrib/dolphin/expected/test_condition.out b/contrib/dolphin/expected/test_condition.out index 65ee7b38af3e5667e82af0ba7b0354a4d5a244b9..7644b3a145e1a993dada588ccbccbb604d63fffe 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 492c68dabbeb415bfbb279d4f547fef0a7d17daa..57c4b058374e12a9b25b5cf7c58c442ac90e465f 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 0f3cb986aa4a9cbe4e395806d02d93614fb872b7..7db6d95d458c8246818ec43495eed7bc2221e9ab 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 7dc8df15341184f4940ceff6ae18b8070436d8ad..4cd9bbc20f6849105f03633fca126abc475fc44e 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;