Eric Yang created SPARK-62395:
---------------------------------
Summary: Filters that compare a multi-branch CASE WHEN with a
literal are not pushed down to data sources
Key: SPARK-62395
URL: https://issues.apache.org/jira/browse/SPARK-62395
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 5.0.0
Reporter: Eric Yang
A filter that compares a CASE WHEN with more than one WHEN branch against a
literal is not pushed down to the data source, so the scan reads all the data
instead of skipping row groups. SPARK-62393 covers the two-way CASE WHEN and
IF; this is the multi-branch case. It is common in views that define a category
column, which queries then filter by value.
{code:java}
CREATE TABLE t USING parquet AS SELECT id FROM range(2000000);
CREATE TEMP VIEW v AS SELECT id,
CASE WHEN id > 1999995 THEN 'top5' WHEN id > 1999990 THEN 'next5' ELSE 'rest'
END AS bucket
FROM t;
SELECT count(*) FROM v WHERE bucket = 'next5';
-- PushedFilters: [], reads 2,000,000 rows
SELECT count(*) FROM t WHERE id > 1999990 AND id <= 1999995;
-- PushedFilters: [IsNotNull(id), GreaterThan(id,1999990),
LessThanOrEqual(id,1999995)], reads 20,000 rows
{code}
Both queries return 5. Writing the CASE directly in the WHERE clause behaves
the same: PushedFilters: [], reads 2,000,000 rows.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]