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

Add division by 0 rules in the expression simplification #3663

Closed
HaoYang670 opened this issue Sep 30, 2022 · 4 comments
Closed

Add division by 0 rules in the expression simplification #3663

HaoYang670 opened this issue Sep 30, 2022 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@HaoYang670
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

❯ create table t as select 1 as a;

❯ explain select a / 0 from t;
+---------------+--------------------------------------------------+
| plan_type     | plan                                             |
+---------------+--------------------------------------------------+
| logical_plan  | Projection: #t.a / Int64(0)                      |
|               |   TableScan: t projection=[a]                    |
| physical_plan | ProjectionExec: expr=[a@0 / 0 as t.a / Int64(0)] |
|               |   MemoryExec: partitions=1, partition_sizes=[1]  |
|               |                                                  |
+---------------+--------------------------------------------------+select a / 0 from t;
ArrowError(DivideByZero)

❯ explain select 1 / 0 from t;
+---------------+----------------------------------------------------+
| plan_type     | plan                                               |
+---------------+----------------------------------------------------+
| logical_plan  | Projection: Int64(NULL) AS Int64(1) / Int64(0)     |
|               |   TableScan: t projection=[a]                      |
| physical_plan | ProjectionExec: expr=[NULL as Int64(1) / Int64(0)] |
|               |   MemoryExec: partitions=1, partition_sizes=[1]    |
|               |                                                    |
+---------------+----------------------------------------------------+
2 rows in set. Query took 0.004 seconds.

Describe the solution you'd like
A clear and concise description of what you want to happen.

When the divisor is the scalar zero, We could one of these:

  1. Simplify the expression to null -> A / 0 -> NULL
  2. Give the DivideByZero error: A / 0 -> Err(DivideByZero)

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@HaoYang670 HaoYang670 added enhancement New feature or request good first issue Good for newcomers labels Sep 30, 2022
@askoa
Copy link
Contributor

askoa commented Oct 2, 2022

Per the below comment, we should not simplify errors as it might be unreachable during execution.

#3669 (comment)

cc: @alamb

@alamb
Copy link
Contributor

alamb commented Oct 3, 2022

Update here is that postgres errors too so we will keep the erroring behavior. Thanks @askoa

@retikulum
Copy link
Contributor

Didn't #3824 close this or am I missing something?

@alamb
Copy link
Contributor

alamb commented Oct 31, 2022

I agree that #3824 closed this -- thanks @retikulum

@alamb alamb closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants