apache / apache/datafusion

Support predicate pruning on `Expr::Case` expressions

Open
#1,692 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
In certain situations , IOx is likely going to make predicates that look like the following

```sql
CASE
WHEN col IS NULL THEN ''
ELSE col
END
```
that basically map `null` to the empty string

We would like to use such predicates in order to prune out Chunks (or parquet record groups)

**Describe the solution you'd like**
I would like `CaseExpr` to be added to the list of expression types supported by predicate pruning in `build_predicate_expression`:
https://github.com/apache/arrow-datafusion/blob/03075d5f4b3fdfd8f82144fcd409418832a4bf69/datafusion/src/physical_optimizer/pruning.rs#L640-L699

The tricky bit of this PR would be figuring out what the transformation is and in what circumstances it can be applied

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

**Additional context**
See https://github.com/influxdata/influxdb_iox/pull/3557 for more details

Contributor guide

Open the contributing guide

Research direction

Start in datafusion/src/physical_optimizer/pruning.rs at build_predicate_expression, especially the expression types currently supported around the linked lines. Determine the safe transformation and applicable conditions for Expr::Case, then verify that predicates like the NULL-to-empty-string example can prune chunks or parquet record groups without incorrect results.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.