Skip to content

Conversation

@gatorsmile
Copy link
Member

What changes were proposed in this pull request?

Remove all the deterministic conditions in a [[Filter]] that are contained in the Child's Constraints.

For example, the first query can be simplified to the second one.

    val queryWithUselessFilter = tr1
      .where("tr1.a".attr > 10 || "tr1.c".attr < 10)
      .join(tr2.where('d.attr < 100), Inner, Some("tr1.a".attr === "tr2.a".attr))
      .where(
        ("tr1.a".attr > 10 || "tr1.c".attr < 10) &&
        'd.attr < 100 &&
        "tr2.a".attr === "tr1.a".attr)
    val query = tr1
      .where("tr1.a".attr > 10 || "tr1.c".attr < 10)
      .join(tr2.where('d.attr < 100), Inner, Some("tr1.a".attr === "tr2.a".attr))

How was this patch tested?

Six test cases are added.

@SparkQA
Copy link

SparkQA commented Feb 27, 2016

Test build #52095 has finished for PR 11406 at commit e50d307.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 27, 2016

Test build #52096 has finished for PR 11406 at commit f889c91.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

comparePlans(optimized, correctAnswer)
}

test("Filter removal #1 -- isNull + LeftOuter") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PruneFiltersSuite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. will do

@SparkQA
Copy link

SparkQA commented Feb 27, 2016

Test build #52111 has finished for PR 11406 at commit b9e68b9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class PruneFiltersSuite extends PlanTest

@SparkQA
Copy link

SparkQA commented Feb 27, 2016

Test build #52112 has finished for PR 11406 at commit c3a504e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

@marmbrus @sameeragarwal Could you please take a look at this rule? Thanks!

} else if (remainingPredicates.isEmpty) {
p
} else {
val newCond = remainingPredicates.reduceOption(And).getOrElse(Literal(true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that you need the type ascription (: LogicalPlan) here or above in the match.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove it. Thanks!

@SparkQA
Copy link

SparkQA commented Mar 5, 2016

Test build #52509 has finished for PR 11406 at commit b71c084.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 7, 2016

Test build #52583 has finished for PR 11406 at commit 83e0f4a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

/**
* Remove all the deterministic conditions in a [[Filter]] that are guaranteed to be true
* given the constraints on the child's output.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like SimplifyFilters is similar in purpose with this rule. Can we merge them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do it. Thanks!

@SparkQA
Copy link

SparkQA commented Mar 8, 2016

Test build #52632 has finished for PR 11406 at commit 7b7b411.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

cc @marmbrus Any comment about this?

After this is merged, I can finish the outer join elimination: #10566

Thanks!

@marmbrus
Copy link
Contributor

marmbrus commented Mar 9, 2016

Thanks, merging to master.

@asfgit asfgit closed this in c6aa356 Mar 9, 2016
roygao94 pushed a commit to roygao94/spark that referenced this pull request Mar 22, 2016
#### What changes were proposed in this pull request?

Remove all the deterministic conditions in a [[Filter]] that are contained in the Child's Constraints.

For example, the first query can be simplified to the second one.

```scala
    val queryWithUselessFilter = tr1
      .where("tr1.a".attr > 10 || "tr1.c".attr < 10)
      .join(tr2.where('d.attr < 100), Inner, Some("tr1.a".attr === "tr2.a".attr))
      .where(
        ("tr1.a".attr > 10 || "tr1.c".attr < 10) &&
        'd.attr < 100 &&
        "tr2.a".attr === "tr1.a".attr)
```
```scala
    val query = tr1
      .where("tr1.a".attr > 10 || "tr1.c".attr < 10)
      .join(tr2.where('d.attr < 100), Inner, Some("tr1.a".attr === "tr2.a".attr))
```
#### How was this patch tested?

Six test cases are added.

Author: gatorsmile <[email protected]>

Closes apache#11406 from gatorsmile/FilterRemoval.
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

Successfully merging this pull request may close these issues.

5 participants