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 2021/12/13 14:45:23 UTC

[GitHub] [spark] cloud-fan opened a new pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

cloud-fan opened a new pull request #34883:
URL: https://github.com/apache/spark/pull/34883


   <!--
   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.
   -->
   `Expression.canonicalized` is very slow with a large expression tree, because its time complexity is O(n^2). To understand this performance issue, let's take a closer look at the related source code. First of all, `Expression.canonicalized` is recursive, as its default implementation is
   ```
   lazy val canonicalized: Expression = {
     val canonicalizedChildren = children.map(_.canonicalized)
     Canonicalize.execute(withNewChildren(canonicalizedChildren))
   }
   ```
   
   However,  `Canonicalize.execute` is also recursive when dealing with commutative operators, as it needs to collect all the commutative operators in the expression tree, and reorder them.
   
   Let's say that we have a deep expression tree with 1000 `And`: `And(c1, And(c2, And(c3, ...)))`. If we call its `canonicalized` method, we first reorder 2 `And`s in a small subtree, then reorder 3 `And`s in a larger subtree, ... and finally reorder 1000 `And`s in the complete tree. This is O(n^2).
   
   To make it O(n), this PR makes the following changes:
   1. Introduce `Expression.roughlyCanonicalized`, which recursively canonicalize each expression node in the tree, without changing the tree structure (thus no commutative operators reordering).
   2. `Expression.canonicalized` just reorders the commutative operators in `roughlyCanonicalized`.
   3. `Canonicalize` only reorders commutative operators now. Other logics are moved to the corresponding expressions' `roughlyCanonicalized` override.
   
   After this PR, when we canonicalize a deep expression tree with 1000 `And`, we first traverse the expression tree once, to make it roughly canonicailized (name, nullability, etc. are normalized). Then we call `Canonicalize` once to reorder `And`s, which also traverse the tree only once.
   
   ### 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.
   -->
   Fix a performance issue when `Expression.canonicalized` can be very slow.
   
   ### 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'.
   -->
   no
   
   ### 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.
   -->
   pass the existing tests and run a benchmark manually
   ```
   test("benchmark") {
     val col = Literal(true)
     var and = And(col, col)
     var i = 0
     while (i < 2000) {
       and = And(and, col)
       i += 1
     }
     and.canonicalized
   }
   ```
   Before this PR, it takes 10 seconds, now it takes 200 ms.


-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r769160607



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,34 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Expression canonicalization is done in 2 phases:
+  //   1. Recursively canonicalize each node in the expression tree. This does not change the tree
+  //      structure and is more like "node-local" canonicalization.
+  //   2. Find adjacent commutative operators in the expression tree, reorder them to get a
+  //      static order and remove cosmetic variations. This may change the tree structure
+  //      dramatically and is more like a "global" canonicalization.
+  //
+  // The first phase is done by `preCanonicalized`. It's a `lazy val` which recursively calls
+  // `preCanonicalized` on the children. This means that almost every node in the expression tree
+  // will instantiate the `preCanonicalized` variable, which is good for performance as you can
+  // reuse the canonicalization result of the children when you construct a new expression node.
+  //
+  // The second phase is done by `canonicalized`, which simply calls `Canonicalize` and is kind of
+  // the actual "user-facing API" of expression canonicalization. Only the root node of the
+  // expression tree will instantiate the `canonicalized` variable. This is different from
+  // `preCanonicalized`, because `canonicalized` does "global" canonicalization and most of the time
+  // you cannot reuse the canonicalization result of the children.
+
+  /**
+   * An internal lazy val to implement expression canonicalization. It should only be called in
+   * `canonicalized`, or in subclass's `preCanonicalized` when the subclass overrides this lazy val
+   * to provide custom canonicalization logic.
+   */
+  lazy val preCanonicalized: Expression = {

Review comment:
       Shall we explicitly make it `protected` since this isn't supposed to call anywhere outside but only within `canonicalized`?




-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992838338


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50618/
   


-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-994095881


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146190/
   


-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992915159


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50618/
   


-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768251362



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node
+  // without changing the structure of the expression tree.
+  // This method should only be called in `canonicalized` or subclass's `roughlyCanonicalized`.
+  // Subclasses (especially leaf nodes) should override this method to customize the
+  // canonicalization logic. Some basic canonicalization rules:
+  //  - Names and nullability hints for `DataType`s are stripped. See the override in
+  //    `AttributeReference` and `GetStructField`.
+  //  - TimeZoneId for [[Cast]] and [[AnsiCast]] are stripped if `needsTimeZone` is false.
+  //  - Rearrange the inputs of certain predicate expressions according to the `hashCode` of inputs.
+  lazy val roughlyCanonicalized: Expression = {

Review comment:
       Yeah .. or `fastCanonicalized`?




-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r769114686



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,34 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Expression canonicalization is done in 2 phases:
+  //   1. Recursively canonicalize each node in the expression tree. This does not change the tree
+  //      structure and is more like "node-local" canonicalization.
+  //   2. Find adjacent commutative operators in the expression tree, reorder them to get a
+  //      static order and remove cosmetic variations. This may change the tree structure
+  //      dramatically and is more like a "global" canonicalization.
+  //
+  // The first phase is done by `preCanonicalized`. It's a `lazy val` which recursively calls
+  // `preCanonicalized` on the children. This means that almost every node in the expression tree
+  // will instantiate the `preCanonicalized` variable, which is good for performance as you can
+  // reuse the canonicalization result of the children when you construct a new expression node.
+  //
+  // The second phase is done by `canonicalized`, which simply calls `Canonicalize` and is kind of
+  // the actual "user-facing API" of expression canonicalization. Only the root node of the
+  // expression tree will instantiate the `canonicalized` variable. This is different from
+  // `preCanonicalized`, because `canonicalized` does "global" canonicalization and most of the time
+  // you cannot reuse the canonicalization result of the children.

Review comment:
       Looks good, thanks!




-- 
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] HyukjinKwon commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-994199386


   Merged 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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r769160607



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,34 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Expression canonicalization is done in 2 phases:
+  //   1. Recursively canonicalize each node in the expression tree. This does not change the tree
+  //      structure and is more like "node-local" canonicalization.
+  //   2. Find adjacent commutative operators in the expression tree, reorder them to get a
+  //      static order and remove cosmetic variations. This may change the tree structure
+  //      dramatically and is more like a "global" canonicalization.
+  //
+  // The first phase is done by `preCanonicalized`. It's a `lazy val` which recursively calls
+  // `preCanonicalized` on the children. This means that almost every node in the expression tree
+  // will instantiate the `preCanonicalized` variable, which is good for performance as you can
+  // reuse the canonicalization result of the children when you construct a new expression node.
+  //
+  // The second phase is done by `canonicalized`, which simply calls `Canonicalize` and is kind of
+  // the actual "user-facing API" of expression canonicalization. Only the root node of the
+  // expression tree will instantiate the `canonicalized` variable. This is different from
+  // `preCanonicalized`, because `canonicalized` does "global" canonicalization and most of the time
+  // you cannot reuse the canonicalization result of the children.
+
+  /**
+   * An internal lazy val to implement expression canonicalization. It should only be called in
+   * `canonicalized`, or in subclass's `preCanonicalized` when the subclass overrides this lazy val
+   * to provide custom canonicalization logic.
+   */
+  lazy val preCanonicalized: Expression = {

Review comment:
       Shall we explicitly make it `protected` since this isn't supposed to call anywhere outside but only within `canonicalized`?




-- 
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] viirya commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768223821



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node
+  // without changing the structure of the expression tree.
+  // This method should only be called in `canonicalized` or subclass's `roughlyCanonicalized`.
+  // Subclasses (especially leaf nodes) should override this method to customize the
+  // canonicalization logic. Some basic canonicalization rules:
+  //  - Names and nullability hints for `DataType`s are stripped. See the override in
+  //    `AttributeReference` and `GetStructField`.
+  //  - TimeZoneId for [[Cast]] and [[AnsiCast]] are stripped if `needsTimeZone` is false.
+  //  - Rearrange the inputs of certain predicate expressions according to the `hashCode` of inputs.
+  lazy val roughlyCanonicalized: Expression = {

Review comment:
       `preCanonicalized`? `roughlyCanonicalized` looks a bit vague and weird.




-- 
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] SparkQA removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993806320


   **[Test build #146190 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146190/testReport)** for PR 34883 at commit [`6109dd0`](https://github.com/apache/spark/commit/6109dd0a62597f6af41770c3d1739b0302618bcf).


-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992698317


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146141/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992617302


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50613/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993806320


   **[Test build #146190 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146190/testReport)** for PR 34883 at commit [`6109dd0`](https://github.com/apache/spark/commit/6109dd0a62597f6af41770c3d1739b0302618bcf).


-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-994095881


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146190/
   


-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992691664


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50613/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992902072


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50618/
   


-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993029537


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146145/
   


-- 
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 change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768886464



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,34 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Expression canonicalization is done in 2 phases:
+  //   1. Recursively canonicalize each node in the expression tree. This does not change the tree
+  //      structure and is more like "node-local" canonicalization.
+  //   2. Find adjacent commutative operators in the expression tree, reorder them to get a
+  //      static order and remove cosmetic variations. This may change the tree structure
+  //      dramatically and is more like a "global" canonicalization.
+  //
+  // The first phase is done by `preCanonicalized`. It's a `lazy val` which recursively calls
+  // `preCanonicalized` on the children. This means that almost every node in the expression tree
+  // will instantiate the `preCanonicalized` variable, which is good for performance as you can
+  // reuse the canonicalization result of the children when you construct a new expression node.
+  //
+  // The second phase is done by `canonicalized`, which simply calls `Canonicalize` and is kind of
+  // the actual "user-facing API" of expression canonicalization. Only the root node of the
+  // expression tree will instantiate the `canonicalized` variable. This is different from
+  // `preCanonicalized`, because `canonicalized` does "global" canonicalization and most of the time
+  // you cannot reuse the canonicalization result of the children.

Review comment:
       @HyukjinKwon please let me know if the comment above makes sense to you




-- 
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] SparkQA removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992580341


   **[Test build #146141 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146141/testReport)** for PR 34883 at commit [`76ff503`](https://github.com/apache/spark/commit/76ff503b723b84443d85a7ace7740f93a8b6b39c).


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993879088


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50664/
   


-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992698317


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146141/
   


-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992691664


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50613/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993843484


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50664/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-994085435


   **[Test build #146190 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146190/testReport)** for PR 34883 at commit [`6109dd0`](https://github.com/apache/spark/commit/6109dd0a62597f6af41770c3d1739b0302618bcf).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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] HyukjinKwon closed pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #34883:
URL: https://github.com/apache/spark/pull/34883


   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992580341


   **[Test build #146141 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146141/testReport)** for PR 34883 at commit [`76ff503`](https://github.com/apache/spark/commit/76ff503b723b84443d85a7ace7740f93a8b6b39c).


-- 
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 change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r767824415



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Canonicalize.scala
##########
@@ -18,48 +18,17 @@
 package org.apache.spark.sql.catalyst.expressions
 
 /**
- * Rewrites an expression using rules that are guaranteed preserve the result while attempting
- * to remove cosmetic variations. Deterministic expressions that are `equal` after canonicalization
- * will always return the same answer given the same input (i.e. false positives should not be
- * possible). However, it is possible that two canonical expressions that are not equal will in fact
- * return the same answer given any input (i.e. false negatives are possible).
- *
- * The following rules are applied:
- *  - Names and nullability hints for [[org.apache.spark.sql.types.DataType]]s are stripped.
- *  - Names for [[GetStructField]] are stripped.
- *  - TimeZoneId for [[Cast]] and [[AnsiCast]] are stripped if `needsTimeZone` is false.
- *  - Commutative and associative operations ([[Add]] and [[Multiply]]) have their children ordered
- *    by `hashCode`.
- *  - [[EqualTo]] and [[EqualNullSafe]] are reordered by `hashCode`.
- *  - Other comparisons ([[GreaterThan]], [[LessThan]]) are reversed by `hashCode`.
- *  - Elements in [[In]] are reordered by `hashCode`.
+ * Reorders adjacent commutative operators such as [[And]] in the expression tree, according to
+ * the `hasCode` of leaf nodes, to remove cosmetic variations. Caller side should only call it on
+ * the root node of an expression tree that needs to be canonicalized.
  */
 object Canonicalize {
-  def execute(e: Expression): Expression = {
-    expressionReorder(ignoreTimeZone(ignoreNamesTypes(e)))
-  }
-
-  /** Remove names and nullability from types, and names from `GetStructField`. */
-  private[expressions] def ignoreNamesTypes(e: Expression): Expression = e match {
-    case a: AttributeReference =>
-      AttributeReference("none", a.dataType.asNullable)(exprId = a.exprId)
-    case GetStructField(child, ordinal, Some(_)) => GetStructField(child, ordinal, None)
-    case _ => e
-  }
-
-  /** Remove TimeZoneId for Cast if needsTimeZone return false. */
-  private[expressions] def ignoreTimeZone(e: Expression): Expression = e match {
-    case c: CastBase if c.timeZoneId.nonEmpty && !c.needsTimeZone =>
-      c.withTimeZone(null)
-    case _ => e
-  }
-
   /** Collects adjacent commutative operations. */
   private def gatherCommutative(
       e: Expression,
       f: PartialFunction[Expression, Seq[Expression]]): Seq[Expression] = e match {
     case c if f.isDefinedAt(c) => f(c).flatMap(gatherCommutative(_, f))
-    case other => other :: Nil
+    case other => reorderCommutativeOperators(other) :: Nil

Review comment:
       Since we call `Canonicalize` only once now, we need to make it truly recursive.




-- 
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] SparkQA removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992795352


   **[Test build #146145 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146145/testReport)** for PR 34883 at commit [`b5e1bdd`](https://github.com/apache/spark/commit/b5e1bdd106b02c0b765a732ba6572f05aefc8cc3).


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992697958


   **[Test build #146141 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146141/testReport)** for PR 34883 at commit [`76ff503`](https://github.com/apache/spark/commit/76ff503b723b84443d85a7ace7740f93a8b6b39c).
    * This patch **fails Spark unit tests**.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992795352


   **[Test build #146145 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146145/testReport)** for PR 34883 at commit [`b5e1bdd`](https://github.com/apache/spark/commit/b5e1bdd106b02c0b765a732ba6572f05aefc8cc3).


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993028491


   **[Test build #146145 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/146145/testReport)** for PR 34883 at commit [`b5e1bdd`](https://github.com/apache/spark/commit/b5e1bdd106b02c0b765a732ba6572f05aefc8cc3).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768258120



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -316,6 +316,15 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
   override lazy val resolved: Boolean =
     childrenResolved && checkInputDataTypes().isSuccess && (!needsTimeZone || timeZoneId.isDefined)
 
+  override lazy val roughlyCanonicalized: Expression = {

Review comment:
       Should we maybe consider having a separate trait for this?
   
   It looks to me that there are only specific expressions that can be optimized by roughly canonicalizing .. e.g.) we can have a trait, and call `roughlyCanonicalized` if it inherits the trait at `canonicalized`.




-- 
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] AmplabJenkins commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993898979


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50664/
   


-- 
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] viirya commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768223821



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node
+  // without changing the structure of the expression tree.
+  // This method should only be called in `canonicalized` or subclass's `roughlyCanonicalized`.
+  // Subclasses (especially leaf nodes) should override this method to customize the
+  // canonicalization logic. Some basic canonicalization rules:
+  //  - Names and nullability hints for `DataType`s are stripped. See the override in
+  //    `AttributeReference` and `GetStructField`.
+  //  - TimeZoneId for [[Cast]] and [[AnsiCast]] are stripped if `needsTimeZone` is false.
+  //  - Rearrange the inputs of certain predicate expressions according to the `hashCode` of inputs.
+  lazy val roughlyCanonicalized: Expression = {

Review comment:
       `preCanonicalized`? roughlyCanonicalized` looks a bit vague and weird.




-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993898979


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50664/
   


-- 
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] viirya commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768248198



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Canonicalize.scala
##########
@@ -18,48 +18,17 @@
 package org.apache.spark.sql.catalyst.expressions
 
 /**
- * Rewrites an expression using rules that are guaranteed preserve the result while attempting
- * to remove cosmetic variations. Deterministic expressions that are `equal` after canonicalization
- * will always return the same answer given the same input (i.e. false positives should not be
- * possible). However, it is possible that two canonical expressions that are not equal will in fact
- * return the same answer given any input (i.e. false negatives are possible).
- *
- * The following rules are applied:
- *  - Names and nullability hints for [[org.apache.spark.sql.types.DataType]]s are stripped.
- *  - Names for [[GetStructField]] are stripped.
- *  - TimeZoneId for [[Cast]] and [[AnsiCast]] are stripped if `needsTimeZone` is false.
- *  - Commutative and associative operations ([[Add]] and [[Multiply]]) have their children ordered
- *    by `hashCode`.
- *  - [[EqualTo]] and [[EqualNullSafe]] are reordered by `hashCode`.
- *  - Other comparisons ([[GreaterThan]], [[LessThan]]) are reversed by `hashCode`.
- *  - Elements in [[In]] are reordered by `hashCode`.
+ * Reorders adjacent commutative operators such as [[And]] in the expression tree, according to
+ * the `hasCode` of leaf nodes, to remove cosmetic variations. Caller side should only call it on

Review comment:
       hasCode -> hashCode




-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-993029537


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/146145/
   


-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768251511



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node

Review comment:
       Maybe it's best to keep these as regular Scaladoc `/** ... */ ` instead of comments.




-- 
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 #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992554591


   cc @maropu @viirya @JoshRosen 


-- 
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] AmplabJenkins removed a comment on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992915159


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/50618/
   


-- 
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] SparkQA commented on pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #34883:
URL: https://github.com/apache/spark/pull/34883#issuecomment-992661539


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50613/
   


-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768255219



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node
+  // without changing the structure of the expression tree.

Review comment:
       I meant that
   
   > This method should only be called in `canonicalized` or subclass's `roughlyCanonicalized`.
   
   doesn't explain when and why do we use this.




-- 
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] HyukjinKwon commented on a change in pull request #34883: [SPARK-37629][SQL] Speed up Expression.canonicalized

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #34883:
URL: https://github.com/apache/spark/pull/34883#discussion_r768253475



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -222,6 +222,20 @@ abstract class Expression extends TreeNode[Expression] {
    */
   def childrenResolved: Boolean = children.forall(_.resolved)
 
+  // Return a roughly canonicalized expression, which recursively canonicalizes each expression node
+  // without changing the structure of the expression tree.

Review comment:
       Can we also describe when this can be used? If somebody mistakenly uses `roughlyCanonicalized` instead of `canonicalized`, does it still work?




-- 
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