From f27699ccda630f915f5ce238326ca24e73a8c5aa Mon Sep 17 00:00:00 2001 From: feng lv Date: Tue, 30 Nov 2021 03:12:12 +0000 Subject: [PATCH] Enable comparison betwwen Decimal and Float add tests update test --- src/DataTypes/IDataType.h | 2 +- src/Functions/FunctionsComparison.h | 2 +- ..._comparison_betwwen_decimal_and_float.reference | 13 +++++++++++++ .../02124_comparison_betwwen_decimal_and_float.sql | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.reference create mode 100644 tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.sql diff --git a/src/DataTypes/IDataType.h b/src/DataTypes/IDataType.h index fc42d678d57..3b0f73bfdeb 100644 --- a/src/DataTypes/IDataType.h +++ b/src/DataTypes/IDataType.h @@ -487,7 +487,7 @@ inline bool isNotCreatable(const T & data_type) inline bool isNotDecimalButComparableToDecimal(const DataTypePtr & data_type) { WhichDataType which(data_type); - return which.isInt() || which.isUInt(); + return which.isInt() || which.isUInt() || which.isFloat(); } inline bool isCompilableType(const DataTypePtr & data_type) diff --git a/src/Functions/FunctionsComparison.h b/src/Functions/FunctionsComparison.h index 945090781dc..3f5146935cb 100644 --- a/src/Functions/FunctionsComparison.h +++ b/src/Functions/FunctionsComparison.h @@ -687,7 +687,7 @@ private: return (res = DecimalComparison::apply(col_left, col_right)) != nullptr; }; - if (!callOnBasicTypes(left_number, right_number, call)) + if (!callOnBasicTypes(left_number, right_number, call)) throw Exception("Wrong call for " + getName() + " with " + col_left.type->getName() + " and " + col_right.type->getName(), ErrorCodes::LOGICAL_ERROR); diff --git a/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.reference b/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.reference new file mode 100644 index 00000000000..eebbb0f7d4c --- /dev/null +++ b/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.reference @@ -0,0 +1,13 @@ +0 +1 +0 +1 +0 +0 +0 +1 +0 +1 +0 +0 +1 diff --git a/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.sql b/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.sql new file mode 100644 index 00000000000..a2ab6c120f0 --- /dev/null +++ b/tests/queries/0_stateless/02124_comparison_betwwen_decimal_and_float.sql @@ -0,0 +1,14 @@ +select CAST(1.0, 'Decimal(15,2)') > CAST(1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') = CAST(1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') < CAST(1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') > CAST(-1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') = CAST(-1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') < CAST(-1, 'Float64'); +select CAST(1.0, 'Decimal(15,2)') > CAST(1, 'Float32'); +select CAST(1.0, 'Decimal(15,2)') = CAST(1, 'Float32'); +select CAST(1.0, 'Decimal(15,2)') < CAST(1, 'Float32'); +select CAST(1.0, 'Decimal(15,2)') > CAST(-1, 'Float32'); +select CAST(1.0, 'Decimal(15,2)') = CAST(-1, 'Float32'); +select CAST(1.0, 'Decimal(15,2)') < CAST(-1, 'Float32'); + +SELECT toDecimal32('11.00', 2) > 1.;