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

[DISCUSS]Is the current way of handling "division by zero calculation" reasonable? #1963

Open
Benxiaohai001 opened this issue Jan 25, 2024 · 0 comments

Comments

@Benxiaohai001
Copy link
Member

Benxiaohai001 commented Jan 25, 2024

Describe the issue
A clear and concise description of issue.
Is the current way of handling "division by zero calculation" reasonable?
current solution:

public ❯ select 1/0;
+---------------------+
| Int64(1) / Int64(0) |
+---------------------+
|                     |
+---------------------+
Query took 0.031 seconds.
public ❯ select 1+1;
+---------------------+
| Int64(1) + Int64(1) |
+---------------------+
| 2                   |
+---------------------+
Query took 0.007 seconds.
public ❯ select 10/(1-1);
+---------------------------------+
| Int64(10) / Int64(1) - Int64(1) |
+---------------------------------+
|                                 |
+---------------------------------+
Query took 0.004 seconds.
public ❯ select 10/(1-1.0);
+-----------------------------------+
| Int64(10) / Int64(1) - Float64(1) |
+-----------------------------------+
|                                   |
+-----------------------------------+
Query took 0.007 seconds.
public ❯ create table tb1(f0 bigint, f1 bigint, tags(t1));
Query took 0.009 seconds.
public ❯ insert into tb1(time, t0, f0, f1)value(now(), 't1', 1, 0);
422 Unprocessable Entity, details: {"error_code":"010009","error_message":"sql parser error: Expected SELECT, VALUES, or a subquery in the query body, found: value"}
public ❯ insert into tb1(time, t0, f0, f1)values(now(), 't1', 1, 0);
422 Unprocessable Entity, details: {"error_code":"010044","error_message":"Semantic error: Insert column 't0' does not exist in target table, expect time,t1,f0,f1"}
public ❯ insert into tb1(time, t1, f0, f1)values(now(), 't1', 1, 0);
+------+
| rows |
+------+
| 1    |
+------+
Query took 0.029 seconds.
public ❯ select * from tb1;
+----------------------------+----+----+----+
| time                       | t1 | f0 | f1 |
+----------------------------+----+----+----+
| 2024-01-25T10:03:38.031529 | t1 | 1  | 0  |
+----------------------------+----+----+----+
Query took 0.006 seconds.
public ❯ select f0/f1 from tb1;
+-----------------+
| tb1.f0 / tb1.f1 |
+-----------------+
|                 |
+-----------------+
Query took 0.004 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
+-----------------+
Query took 0.003 seconds.
public ❯ select now(), f1, 1, 1 from tb1;
422 Unprocessable Entity, details: {"error_code":"010001","error_message":"Datafusion: Error during planning: Projections require unique expression names but the expression \"Int64(1)\" at position 2 and \"Int64(1)\" at position 3 have the same name. Consider aliasing (\"AS\") one of them."}
public ❯ select now(), f1, 1 from tb1;
+-----------------------------+----+----------+
| now()                       | f1 | Int64(1) |
+-----------------------------+----+----------+
| 2024-01-25T10:09:42.811251Z | 0  | 1        |
+-----------------------------+----+----------+
Query took 0.003 seconds.
public ❯ select 1/0, 1 from tb1;
+---------------------+----------+
| Int64(1) / Int64(0) | Int64(1) |
+---------------------+----------+
|                     | 1        |
+---------------------+----------+
Query took 0.003 seconds.
public ❯ select 1/0, 1;
+---------------------+----------+
| Int64(1) / Int64(0) | Int64(1) |
+---------------------+----------+
|                     | 1        |
+---------------------+----------+
Query took 0.002 seconds.
public ❯ insert into tb1(time, t1, f0, f1)values(now(), 't1', 0, 1);
+------+
| rows |
+------+
| 1    |
+------+
Query took 0.005 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
|                 |
+-----------------+
Query took 0.002 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
|                 |
+-----------------+
Query took 0.002 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
|                 |
+-----------------+
Query took 0.003 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
|                 |
+-----------------+
Query took 0.003 seconds.
public ❯ select f1/f0 from tb1;
+-----------------+
| tb1.f1 / tb1.f0 |
+-----------------+
| 0               |
|                 |
+-----------------+
Query took 0.002 seconds.

image
image
image
PG solution:

postgres=# select 1/0;
ERROR:  division by zero

mysql solution:

mysql> select 1/0;
+------+
| 1/0  |
+------+
| NULL |
+------+
1 row in set, 1 warning (0.00 sec)

What you like us to do
Please give us some advices

Additional context
Add any other context about the issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant