You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/04/20 10:01:52 UTC
[GitHub] [spark] ulysses-you opened a new pull request, #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
ulysses-you opened a new pull request, #36281:
URL: https://github.com/apache/spark/pull/36281
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
- Improve `DistinctKeyVisitor` that support propagate empty set
- Small improvement for match alias
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Make distinct keys can be used to optimize more case, see comment https://github.com/apache/spark/pull/36117#discussion_r853755920
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Improve performance
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
add test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1104847575
@wangyum what's wrong with that code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36281:
URL: https://github.com/apache/spark/pull/36281#discussion_r854157760
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/DistinctKeyVisitor.scala:
##########
@@ -29,25 +29,21 @@ object DistinctKeyVisitor extends LogicalPlanVisitor[Set[ExpressionSet]] {
private def projectDistinctKeys(
keys: Set[ExpressionSet], projectList: Seq[NamedExpression]): Set[ExpressionSet] = {
val outputSet = ExpressionSet(projectList.map(_.toAttribute))
- val aliases = projectList.filter(_.isInstanceOf[Alias])
+ val aliases = projectList.collect {
+ // TODO: Expand distinctKeys for redundant aliases on the same expression
+ case alias: Alias if alias.child.deterministic => alias.child.canonicalized -> alias
+ }.toMap
if (aliases.isEmpty) {
keys.filter(_.subsetOf(outputSet))
} else {
- val aliasedDistinctKeys = keys.map { expressionSet =>
- expressionSet.map { expression =>
- expression transform {
- case expr: Expression =>
- // TODO: Expand distinctKeys for redundant aliases on the same expression
- aliases
- .collectFirst { case a: Alias if a.child.semanticEquals(expr) => a.toAttribute }
- .getOrElse(expr)
- }
- }
- }
+ val aliasedDistinctKeys = keys.map(_.map(_.transform {
+ case expr: Expression =>
+ aliases.get(expr.canonicalized).map(_.toAttribute).getOrElse(expr)
+ }))
Review Comment:
```suggestion
val aliasedDistinctKeys = keys.map(_.map(_.transform {
case expr: Expression =>
aliases.get(expr.canonicalized).map(_.toAttribute).getOrElse(expr)
}))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
wangyum commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1105288407
I'm ok if your do not think it is needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1105199450
I don't see why empty expression set is special. If the framework has bugs and produces incorrect distinct keys, we will have query correctness bugs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
URL: https://github.com/apache/spark/pull/36281
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1106464959
thank you @wangyum @cloud-fan
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1105144661
if we get an unexpected empty ExpressionSet it should be a bug .. shall we trust the framework ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36281:
URL: https://github.com/apache/spark/pull/36281#discussion_r854158255
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/DistinctKeyVisitor.scala:
##########
@@ -69,7 +65,9 @@ object DistinctKeyVisitor extends LogicalPlanVisitor[Set[ExpressionSet]] {
override def default(p: LogicalPlan): Set[ExpressionSet] = Set.empty[ExpressionSet]
override def visitAggregate(p: Aggregate): Set[ExpressionSet] = {
- val groupingExps = ExpressionSet(p.groupingExpressions) // handle group by a, a
+ // handle group by a, a
+ // handle global aggregate
Review Comment:
```suggestion
// handle group by a, a and global aggregate
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ulysses-you commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1103743296
cc @cloud-fan @sigmod @wangyum
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #36281:
URL: https://github.com/apache/spark/pull/36281#discussion_r854157991
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/DistinctKeyVisitor.scala:
##########
@@ -29,25 +29,21 @@ object DistinctKeyVisitor extends LogicalPlanVisitor[Set[ExpressionSet]] {
private def projectDistinctKeys(
keys: Set[ExpressionSet], projectList: Seq[NamedExpression]): Set[ExpressionSet] = {
val outputSet = ExpressionSet(projectList.map(_.toAttribute))
- val aliases = projectList.filter(_.isInstanceOf[Alias])
+ val aliases = projectList.collect {
+ // TODO: Expand distinctKeys for redundant aliases on the same expression
+ case alias: Alias if alias.child.deterministic => alias.child.canonicalized -> alias
+ }.toMap
if (aliases.isEmpty) {
keys.filter(_.subsetOf(outputSet))
} else {
- val aliasedDistinctKeys = keys.map { expressionSet =>
- expressionSet.map { expression =>
- expression transform {
- case expr: Expression =>
- // TODO: Expand distinctKeys for redundant aliases on the same expression
- aliases
- .collectFirst { case a: Alias if a.child.semanticEquals(expr) => a.toAttribute }
- .getOrElse(expr)
- }
- }
- }
+ val aliasedDistinctKeys = keys.map(_.map(_.transform {
+ case expr: Expression =>
+ aliases.get(expr.canonicalized).map(_.toAttribute).getOrElse(expr)
+ }))
Review Comment:
nit: fix indentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1105370479
My point is empty expression set is informative and we shouldn't skip it. It means the data is distinct by Nil, so it has at most 1 row and can override any other distict keys.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wangyum commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
wangyum commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1105102545
For example:
```scala
Set[ExpressionSet](ExpressionSet()).exists(_.subsetOf(ExpressionSet(ae.aggregateFunction.children.filterNot(_.foldable))))
```
It is always true, it may have potential problems.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #36281: [SPARK-38832][SQL][FOLLOWUP] Support propagate empty expression set for distinct key
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #36281:
URL: https://github.com/apache/spark/pull/36281#issuecomment-1106338049
thanks, merging to master!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org