Merge pull request #54316 from ucasfl/isNull

Fix isZeroOrNull(NULL)
This commit is contained in:
Robert Schulze 2023-09-06 10:38:22 +02:00 committed by GitHub
commit 8f6cd157b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 6 deletions

View File

@ -92,6 +92,50 @@ Result:
└───┘
```
## isZeroOrNull
Returns whether the argument is 0 (zero) or [NULL](../../sql-reference/syntax.md#null-literal).
``` sql
isZeroOrNull(x)
```
**Arguments:**
- `x` — A value of non-compound data type.
**Returned value**
- `1` if `x` is 0 (zero) or `NULL`.
- `0` else.
**Example**
Table:
``` text
┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │ 0 │
│ 3 │ 3 │
└───┴──────┘
```
Query:
``` sql
SELECT x FROM t_null WHERE isZeroOrNull(y);
```
Result:
``` text
┌─x─┐
│ 1 │
│ 2 │
└───┘
```
## coalesce
Returns the leftmost non-`NULL` argument.

View File

@ -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<DataTypeUInt8>();
}
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);
}
}

View File

@ -20,3 +20,5 @@ world
3
---
4
---
1

View File

@ -27,3 +27,7 @@ SELECT count() FROM
UNION ALL
SELECT * FROM test WHERE isZeroOrNull(x != 'xyz')
);
SELECT '---';
select isZeroOrNull(Null);

View File

@ -1329,10 +1329,10 @@ ddl
deallocation
deallocations
debian
decodeHTMLComponent
decodeURLComponent
decodeURLFormComponent
decodeXMLComponent
decodeHTMLComponent
decompressor
decrypt
decrypted
@ -1558,6 +1558,7 @@ gzipped
hadoop
halfMD
halfday
hardlink
hardlinks
hasAll
hasAny
@ -1637,6 +1638,7 @@ isNotNull
isNull
isValidJSON
isValidUTF
isZeroOrNull
iteratively
jaccard
javaHash
@ -2582,4 +2584,3 @@ znode
znodes
zookeeperSessionUptime
zstd
hardlink