Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[function] isnotnull #22702

Closed
wangsimo0 opened this issue Apr 27, 2023 · 3 comments · Fixed by #23117
Closed

[function] isnotnull #22702

wangsimo0 opened this issue Apr 27, 2023 · 3 comments · Fixed by #23117
Assignees

Comments

@wangsimo0
Copy link
Contributor

StarRocks already have a function named isnull.
https://docs.starrocks.io/en-us/latest/sql-reference/sql-functions/utility-functions/isnull
For easy of use, it's better to have a function that isnotnull.

@qmengss
Copy link
Contributor

qmengss commented May 3, 2023

Hi, I am interested in this issue, but I didn't find a function name "isnull" in gensrc/script/functions.py.

@LiShuMing
Copy link
Contributor

yep. isnull is implemented by expression, not by built-in function framework. But it's the same principle as the function.

FE will convert the ISNULL to IsNullPredicate:


        if (functionName.equals(FunctionSet.ISNULL)) {
            List<Expr> params = visit(context.expression(), Expr.class);
            if (params.size() != 1) {
                throw new ParsingException(PARSER_ERROR_MSG.wrongNumOfArgs(functionName), pos);
            }
            return new IsNullPredicate(params.get(0), false, pos);
        }

IsNullPredicate will be converted to VectorizedIsNullPredicate in the BE

public class IsNullPredicate extends Predicate {

    static Function isNullFN = new Function(new FunctionName("is_null_pred"),
            new Type[] {Type.INVALID}, Type.BOOLEAN, false);
    static Function isNotNullFN = new Function(new FunctionName("is_not_null_pred"),
            new Type[] {Type.INVALID}, Type.BOOLEAN, false);
    {
        isNullFN.setBinaryType(TFunctionBinaryType.BUILTIN);
        isNotNullFN.setBinaryType(TFunctionBinaryType.BUILTIN);
    }

}

The implements is like this:

class VectorizedIsNullPredicate final : public Predicate {
public:
    DEFINE_CLASS_CONSTRUCT_FN(VectorizedIsNullPredicate);

    StatusOr<ColumnPtr> evaluate_checked(ExprContext* context, Chunk* ptr) override {
        ASSIGN_OR_RETURN(ColumnPtr column, _children[0]->evaluate_checked(context, ptr));

        if (column->only_null()) {
            return ColumnHelper::create_const_column<TYPE_BOOLEAN>(true, column->size());
        }

        if (!column->is_nullable() || !column->has_null()) {
            return ColumnHelper::create_const_column<TYPE_BOOLEAN>(false, column->size());
        }

        auto col = ColumnHelper::as_raw_column<NullableColumn>(column)->null_column();
        return VectorizedStrictUnaryFunction<isNullImpl>::evaluate<TYPE_NULL, TYPE_BOOLEAN>(col);
    }
};

DEFINE_UNARY_FN_WITH_IMPL(isNotNullImpl, v) {
    return v == 0;
}

@leoyy0316
Copy link
Contributor

@kateshaowanjou Can you assign this issue to me?

@wangsimo0 wangsimo0 added the good first issue Good for newcomers label May 12, 2023
stephen-shelby pushed a commit that referenced this issue May 24, 2023
Fixes #22702

Test
select * from test.t_leo;
+------+------+-------+
| id   | name | money |
+------+------+-------+
|    1 | a    |  NULL |
+------+------+-------+

select isnotnull(money) from test.t_leo;
+-------------------+
| money IS NOT NULL |
+-------------------+
|                 0 |
+-------------------+

select isnotnull(id) from test.t_leo;
+----------------+
| id IS NOT NULL |
+----------------+
|              1 |
+----------------+

Signed-off-by: leoyy0316 <571684903@qq.com>
wxl24life pushed a commit to wxl24life/starrocks that referenced this issue May 25, 2023
Fixes StarRocks#22702

Test
select * from test.t_leo;
+------+------+-------+
| id   | name | money |
+------+------+-------+
|    1 | a    |  NULL |
+------+------+-------+

select isnotnull(money) from test.t_leo;
+-------------------+
| money IS NOT NULL |
+-------------------+
|                 0 |
+-------------------+

select isnotnull(id) from test.t_leo;
+----------------+
| id IS NOT NULL |
+----------------+
|              1 |
+----------------+

Signed-off-by: leoyy0316 <571684903@qq.com>
abc982627271 pushed a commit to abc982627271/starrocks that referenced this issue Jun 5, 2023
Fixes StarRocks#22702

Test
select * from test.t_leo;
+------+------+-------+
| id   | name | money |
+------+------+-------+
|    1 | a    |  NULL |
+------+------+-------+

select isnotnull(money) from test.t_leo;
+-------------------+
| money IS NOT NULL |
+-------------------+
|                 0 |
+-------------------+

select isnotnull(id) from test.t_leo;
+----------------+
| id IS NOT NULL |
+----------------+
|              1 |
+----------------+

Signed-off-by: leoyy0316 <571684903@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants