From aa0c94f20c5c9acd08d3facb0781a7b7de0b9470 Mon Sep 17 00:00:00 2001 From: flynn Date: Tue, 5 Sep 2023 13:53:15 +0000 Subject: [PATCH] Handle Null in function isZeroOrNull --- src/Functions/isZeroOrNull.cpp | 18 ++++++++++++++---- .../02872_is_zero_or_null.reference | 1 + .../0_stateless/02872_is_zero_or_null.sql | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/queries/0_stateless/02872_is_zero_or_null.reference create mode 100644 tests/queries/0_stateless/02872_is_zero_or_null.sql diff --git a/src/Functions/isZeroOrNull.cpp b/src/Functions/isZeroOrNull.cpp index bc0ac299a23..119fb2f67fd 100644 --- a/src/Functions/isZeroOrNull.cpp +++ b/src/Functions/isZeroOrNull.cpp @@ -44,14 +44,18 @@ public: DataTypePtr getReturnTypeImpl(const DataTypes & types) const override { - if (!isNumber(removeNullable(types.at(0)))) - throw Exception(ErrorCodes::BAD_ARGUMENTS, "The argument of function {} must have simple numeric type, possibly Nullable", name); + if (!isNumber(removeNullable(types.at(0))) && !isNothing(removeNullable(types.at(0)))) + throw Exception( + ErrorCodes::BAD_ARGUMENTS, "The argument of function {} must have simple numeric type, possibly Nullable or Null", name); return std::make_shared(); } ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override { + if (isNothing(removeNullable(arguments[0].type))) + return DataTypeUInt8{}.createColumnConst(input_rows_count, 1); + const ColumnPtr & input_column = arguments[0].column; ColumnPtr res; @@ -72,7 +76,10 @@ public: return true; })) { - throw Exception(ErrorCodes::ILLEGAL_COLUMN, "The argument of function {} must have simple numeric type, possibly Nullable", name); + throw Exception( + ErrorCodes::ILLEGAL_COLUMN, + "The argument of function {} must have simple numeric type, possibly Nullable or Null", + name); } } else @@ -89,7 +96,10 @@ public: return true; })) { - throw Exception(ErrorCodes::ILLEGAL_COLUMN, "The argument of function {} must have simple numeric type, possibly Nullable", name); + throw Exception( + ErrorCodes::ILLEGAL_COLUMN, + "The argument of function {} must have simple numeric type, possibly Nullable or Null", + name); } } diff --git a/tests/queries/0_stateless/02872_is_zero_or_null.reference b/tests/queries/0_stateless/02872_is_zero_or_null.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02872_is_zero_or_null.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02872_is_zero_or_null.sql b/tests/queries/0_stateless/02872_is_zero_or_null.sql new file mode 100644 index 00000000000..98830027603 --- /dev/null +++ b/tests/queries/0_stateless/02872_is_zero_or_null.sql @@ -0,0 +1 @@ +select isZeroOrNull(Null);