Skip to content

inconsistent behavior for divide zero: divide_opt and divide_scalar #4669

@liukun4515

Description

@liukun4515
    From this changes, I find some inconsistent behavior for `divide` about `zero`.
❯ \d left
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion    | public       | left       | c           | Int32     | YES         |
+---------------+--------------+------------+-------------+-----------+-------------+
1 row in set. Query took 0.054 seconds.
❯ select c/0 from left;
ArrowError(DivideByZero)
❯ select 10/0;
+----------------------+
| Int64(10) / Int64(0) |
+----------------------+
|                      |
+----------------------+

The difference is from the arrow-rs kernel divide_scalar and divide_opt.

In the divide_scalar, it will check the zero for the right, but in the divide_opt, the result will be replaced with NULL if the right value is zero.

cc @alamb

Originally posted by @liukun4515 in #4648 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions