Skip to content

Commit

Permalink
feat: add isnull function
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Feb 22, 2024
1 parent b8c672c commit b441711
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/common/function/src/scalars/expression/is_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::function::{Function, FunctionContext};

const NAME: &str = "isnull";

/// The function to find remainders
/// The function to check whether an expression is NULL
#[derive(Clone, Debug, Default)]
pub struct IsNullFunction;

Expand Down
91 changes: 61 additions & 30 deletions tests/cases/standalone/common/function/expression.result
Original file line number Diff line number Diff line change
@@ -1,47 +1,78 @@
CREATE TABLE t(a INTEGER, ts timestamp time index);

Affected Rows: 0

INSERT INTO t VALUES (1, 1);

Affected Rows: 1

INSERT INTO t VALUES (null, 2);

Affected Rows: 1

INSERT INTO t VALUES (3, 3);

Affected Rows: 1

SELECT ISNULL(a) from t;

+-------------+
| isnull(t.a) |
+-------------+
| false |
| true |
| false |
+-------------+

SELECT ISNULL(null);

+-------------------------+
| isnull(NULL) |
+-------------------------+
| true |
+-------------------------+
+--------------+
| isnull(NULL) |
+--------------+
| true |
+--------------+

SELECT ISNULL(1);

+-------------------------+
| isnull(1) |
+-------------------------+
| false |
+-------------------------+
+------------------+
| isnull(Int64(1)) |
+------------------+
| false |
+------------------+

SELECT ISNULL(-1);

+-------------------------+
| isnull(-1) |
+-------------------------+
| false |
+-------------------------+
+-------------------+
| isnull(Int64(-1)) |
+-------------------+
| false |
+-------------------+

SELECT ISNULL(1.0);

+-------------------------+
| isnull(1.0) |
+-------------------------+
| false |
+-------------------------+
+--------------------+
| isnull(Float64(1)) |
+--------------------+
| false |
+--------------------+

SELECT ISNULL(true);

+-------------------------+
| isnull(true) |
+-------------------------+
| false |
+-------------------------+
+-----------------------+
| isnull(Boolean(true)) |
+-----------------------+
| false |
+-----------------------+

SELECT ISNULL('string');

+-------------------------+
| isnull(Utf8("string")) |
+-------------------------+
| false |
+-------------------------+
+------------------------+
| isnull(Utf8("string")) |
+------------------------+
| false |
+------------------------+

DROP TABLE t;

Affected Rows: 0

14 changes: 13 additions & 1 deletion tests/cases/standalone/common/function/expression.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
CREATE TABLE t(a INTEGER, ts timestamp time index);

INSERT INTO t VALUES (1, 1);

INSERT INTO t VALUES (null, 2);

INSERT INTO t VALUES (3, 3);

SELECT ISNULL(a) from t;

SELECT ISNULL(null);

SELECT ISNULL(1);
Expand All @@ -8,4 +18,6 @@ SELECT ISNULL(1.0);

SELECT ISNULL(true);

SELECT ISNULL('string');
SELECT ISNULL('string');

DROP TABLE t;

0 comments on commit b441711

Please sign in to comment.