From 9ad3dcacd6dca448dd793e716399ca631d18ad2a Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Aug 2020 04:56:07 +0300 Subject: [PATCH 1/3] Fix function if with nullable constexpr as cond that is not literal NULL --- src/Functions/if.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Functions/if.cpp b/src/Functions/if.cpp index f6505571382..cc4667219b1 100644 --- a/src/Functions/if.cpp +++ b/src/Functions/if.cpp @@ -701,19 +701,13 @@ private: if (cond_is_true) { - if (result_column.type->equals(*column1.type)) - { - result_column.column = std::move(column1.column); - return true; - } + result_column.column = castColumn(column1, result_column.type); + return true; } else if (cond_is_false || cond_is_null) { - if (result_column.type->equals(*column2.type)) - { - result_column.column = std::move(column2.column); - return true; - } + result_column.column = castColumn(column2, result_column.type); + return true; } if (const auto * nullable = checkAndGetColumn(*not_const_condition)) From b47a02f20bc9bb58657e21e6f13f8ac5a131263d Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Aug 2020 05:00:08 +0300 Subject: [PATCH 2/3] Add test --- tests/queries/0_stateless/01423_if_nullable_cond.reference | 1 + tests/queries/0_stateless/01423_if_nullable_cond.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/queries/0_stateless/01423_if_nullable_cond.reference create mode 100644 tests/queries/0_stateless/01423_if_nullable_cond.sql diff --git a/tests/queries/0_stateless/01423_if_nullable_cond.reference b/tests/queries/0_stateless/01423_if_nullable_cond.reference new file mode 100644 index 00000000000..f48898c83a6 --- /dev/null +++ b/tests/queries/0_stateless/01423_if_nullable_cond.reference @@ -0,0 +1 @@ +-1 Nullable(Int16) Nullable(Int16), Const(size = 1, Nullable(size = 1, Int16(size = 1), UInt8(size = 1))) diff --git a/tests/queries/0_stateless/01423_if_nullable_cond.sql b/tests/queries/0_stateless/01423_if_nullable_cond.sql new file mode 100644 index 00000000000..9c56e9dbe26 --- /dev/null +++ b/tests/queries/0_stateless/01423_if_nullable_cond.sql @@ -0,0 +1 @@ +SELECT CAST(null, 'Nullable(UInt8)') = 1 ? CAST(null, 'Nullable(UInt8)') : -1 AS x, toTypeName(x), dumpColumnStructure(x); From 18843eb7f6c349dad07c1ca1cd15ca9a9c53c69a Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 2 Aug 2020 17:36:05 +0300 Subject: [PATCH 3/3] Update test --- tests/queries/0_stateless/00735_conditional.reference | 4 ++++ tests/queries/0_stateless/00735_conditional.sql | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/queries/0_stateless/00735_conditional.reference b/tests/queries/0_stateless/00735_conditional.reference index 2d5040a336d..b37fce430ec 100644 --- a/tests/queries/0_stateless/00735_conditional.reference +++ b/tests/queries/0_stateless/00735_conditional.reference @@ -42,6 +42,7 @@ value vs value 0 1 1 Int64 UInt8 Int64 0 1 1 Int64 UInt16 Int64 0 1 1 Int64 UInt32 Int64 +0 1 1 Int64 Decimal(9, 0) Decimal(18, 0) 0 1 1 Int64 Decimal(18, 0) Decimal(18, 0) 0 1 1 Int64 Decimal(38, 0) Decimal(38, 0) 0 1 1 UInt8 Int8 Int16 @@ -80,12 +81,15 @@ value vs value 0 1 1 UInt32 UInt64 UInt64 0 1 1 UInt32 Float32 Float64 0 1 1 UInt32 Float64 Float64 +0 1 1 UInt32 Decimal(9, 0) Decimal(18, 0) 0 1 1 UInt32 Decimal(18, 0) Decimal(18, 0) 0 1 1 UInt32 Decimal(38, 0) Decimal(38, 0) 0 1 1 UInt64 UInt8 UInt64 0 1 1 UInt64 UInt16 UInt64 0 1 1 UInt64 UInt32 UInt64 0 1 1 UInt64 UInt64 UInt64 +0 1 1 UInt64 Decimal(9, 0) Decimal(38, 0) +0 1 1 UInt64 Decimal(18, 0) Decimal(38, 0) 0 1 1 UInt64 Decimal(38, 0) Decimal(38, 0) 1970-01-01 1970-01-02 1970-01-02 Date Date Date 2000-01-01 2000-01-01 00:00:01 2000-01-01 00:00:01 Date DateTime(\'Europe/Moscow\') DateTime diff --git a/tests/queries/0_stateless/00735_conditional.sql b/tests/queries/0_stateless/00735_conditional.sql index dc9d916930e..0c272ac69f8 100644 --- a/tests/queries/0_stateless/00735_conditional.sql +++ b/tests/queries/0_stateless/00735_conditional.sql @@ -66,7 +66,7 @@ SELECT toInt64(0) AS x, toFloat64(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x) SELECT toInt64(0) AS x, toDate(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } SELECT toInt64(0) AS x, toDateTime(1, 'Europe/Moscow') AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } SELECT toInt64(0) AS x, toUUID(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } -SELECT toInt64(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } +SELECT toInt64(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toInt64(0) AS x, toDecimal64(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toInt64(0) AS x, toDecimal128(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); @@ -117,7 +117,7 @@ SELECT toUInt32(0) AS x, toFloat64(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x SELECT toUInt32(0) AS x, toDate(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } SELECT toUInt32(0) AS x, toDateTime(1, 'Europe/Moscow') AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } SELECT toUInt32(0) AS x, toUUID(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } -SELECT toUInt32(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } +SELECT toUInt32(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toUInt32(0) AS x, toDecimal64(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toUInt32(0) AS x, toDecimal128(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); @@ -134,8 +134,8 @@ SELECT toUInt64(0) AS x, toFloat64(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x SELECT toUInt64(0) AS x, toDate(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } SELECT toUInt64(0) AS x, toDateTime(1, 'Europe/Moscow') AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } SELECT toUInt64(0) AS x, toUUID(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 386 } -SELECT toUInt64(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } -SELECT toUInt64(0) AS x, toDecimal64(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 } +SELECT toUInt64(0) AS x, toDecimal32(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); +SELECT toUInt64(0) AS x, toDecimal64(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toUInt64(0) AS x, toDecimal128(1, 0) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); SELECT toDate(0) AS x, toInt8(1) AS y, ((x > y) ? x : y) AS z, toTypeName(x), toTypeName(y), toTypeName(z); -- { serverError 43 }