GitHub user davies opened a pull request:
https://github.com/apache/spark/pull/11585
[SPARK-13751] [SQL] generate better code for Filter
## What changes were proposed in this pull request?
This PR improve the codegen of Filter by:
1. filter out the rows early if it have null value in it that will cause
the condition result in null or false. After this, we could simplify the
condition, because the input are not nullable anymore.
2. Split the condition as conjunctive predicates, then check them one by
one.
Here is a piece of generated code for Filter in TPCDS Q55:
```java
/* 369 */ /*** CONSUME: Filter ((((isnotnull(d_moy#149) &&
isnotnull(d_year#147)) && (d_moy#149 = 11)) && (d_year#147 = 1999)) &&
isnotnull(d_date_sk#141)) */
/* 370 */ /* input[0, int] */
/* 371 */ boolean agg_isNull15 = rdd_row.isNullAt(0);
/* 372 */ int agg_value15 = agg_isNull15 ? -1 : (rdd_row.getInt(0));
/* 373 */ /* input[1, int] */
/* 374 */ boolean agg_isNull16 = rdd_row.isNullAt(1);
/* 375 */ int agg_value16 = agg_isNull16 ? -1 : (rdd_row.getInt(1));
/* 376 */ /* input[2, int] */
/* 377 */ boolean agg_isNull17 = rdd_row.isNullAt(2);
/* 378 */ int agg_value17 = agg_isNull17 ? -1 : (rdd_row.getInt(2));
/* 379 */
/* 380 */ if (agg_isNull15) continue;
/* 381 */ if (agg_isNull16) continue;
/* 382 */ if (agg_isNull17) continue;
/* 383 */
/* 384 */ /* (input[1, int] = 11) */
/* 385 */ boolean filter_value6 = false;
/* 386 */ filter_value6 = agg_value16 == 11;
/* 387 */ if ( !filter_value6) continue;
/* 388 */
/* 389 */ /* (input[2, int] = 1999) */
/* 390 */ boolean filter_value9 = false;
/* 391 */ filter_value9 = agg_value17 == 1999;
/* 392 */ if ( !filter_value9) continue;
/* 393 */
/* 394 */ filter_metricValue1.add(1);
```
## How was this patch tested?
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/davies/spark gen_filter
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/11585.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #11585
----
commit edc934fa2123df86403352eff00b4e3f6bc7941c
Author: Davies Liu <[email protected]>
Date: 2016-03-08T19:49:32Z
generate better code for Filter
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]