You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2015/03/08 10:46:22 UTC
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
GitHub user viirya opened a pull request:
https://github.com/apache/spark/pull/4940
[SPARK-6215][SQL] Shorten apply and update funcs in GenerateProjection
Some codes in `GenerateProjection` look redundant and can be shortened.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/viirya/spark-1 fix_genprojection2
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/4940.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 #4940
----
commit b207614bdbc054d1a192f0e44e9ecc3489523630
Author: Liang-Chi Hsieh <vi...@gmail.com>
Date: 2015-03-08T09:42:28Z
Shorten apply and update funcs.
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by chenghao-intel <gi...@git.apache.org>.
Github user chenghao-intel commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-81089066
See https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/rows.scala#L67
Usually we don't the the validity of `ordinal` within the callee, the caller should take care of that.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by marmbrus <gi...@git.apache.org>.
Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/4940#discussion_r26633794
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateProjection.scala ---
@@ -84,9 +84,15 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
val elementName = newTermName(s"c$i")
val iLit = ru.Literal(Constant(i))
- q"if(i == $ordinal) { if(isNullAt($i)) return null else return $elementName }"
+ q"if(i == $ordinal) { return $elementName }"
}
- q"override def apply(i: Int): Any = { ..$cases; $accessorFailure }"
+ q"""
+ override def apply(i: Int): Any = {
+ if (i < 0 || i >= this.length) $accessorFailure
--- End diff --
Yes, but you are adding an if check that will never actually be used when the optimizer is doing its job correctly. Why optimize for user error?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by chenghao-intel <gi...@git.apache.org>.
Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/4940#discussion_r26011394
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateProjection.scala ---
@@ -84,9 +84,15 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
val elementName = newTermName(s"c$i")
val iLit = ru.Literal(Constant(i))
- q"if(i == $ordinal) { if(isNullAt($i)) return null else return $elementName }"
+ q"if(i == $ordinal) { return $elementName }"
}
- q"override def apply(i: Int): Any = { ..$cases; $accessorFailure }"
+ q"""
+ override def apply(i: Int): Any = {
+ if (i < 0 || i >= this.length) $accessorFailure
--- End diff --
Will that be the same checking with `if(i == $ordinal)`? and in `..$cases`, it will run the checking again, which seems not necessary to me.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-77743415
[Test build #28371 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/28371/consoleFull) for PR 4940 at commit [`b207614`](https://github.com/apache/spark/commit/b207614bdbc054d1a192f0e44e9ecc3489523630).
* This patch **passes all tests**.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-81366888
I think it is not a bug, it is reasonable behavior.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by chenghao-intel <gi...@git.apache.org>.
Github user chenghao-intel commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-77785497
@viirya I am not sure if we really need this change, seems the checking `if (i < 0 || i >= this.length)` is not necessary to me, because the `ordinal` should have been resolved during the `analysis` or attribute `bounding` (`BoundReferences.bindReference`), bring the complication checking to runtime will cause extra overhead.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-77743416
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/28371/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by marmbrus <gi...@git.apache.org>.
Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/4940#discussion_r26633778
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateProjection.scala ---
@@ -84,9 +84,15 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
val elementName = newTermName(s"c$i")
val iLit = ru.Literal(Constant(i))
- q"if(i == $ordinal) { if(isNullAt($i)) return null else return $elementName }"
+ q"if(i == $ordinal) { return $elementName }"
--- End diff --
Why remove the null check?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-77793875
@chenghao-intel These are the random accessors for the row (`SpecificRow`) objects produced by the projection `GenerateProjection`. So I think they are not resolved during the analysis nor attribute bounding. The `i` given to `def apply(i: Int): Any` is just a parameter used to access the `i`-th element in the row.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya closed the pull request at:
https://github.com/apache/spark/pull/4940
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/4940#discussion_r26013756
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateProjection.scala ---
@@ -84,9 +84,15 @@ object GenerateProjection extends CodeGenerator[Seq[Expression], Projection] {
val elementName = newTermName(s"c$i")
val iLit = ru.Literal(Constant(i))
- q"if(i == $ordinal) { if(isNullAt($i)) return null else return $elementName }"
+ q"if(i == $ordinal) { return $elementName }"
}
- q"override def apply(i: Int): Any = { ..$cases; $accessorFailure }"
+ q"""
+ override def apply(i: Int): Any = {
+ if (i < 0 || i >= this.length) $accessorFailure
--- End diff --
It is used to check if the parameter `i` fails in legal range. `if(i == $ordinal)` is used to choose the corresponding element to return. Checking the legal range and giving `accessorFailure` in advance can avoid further running of `$cases`. (when row size grows, that will be many `if` checks.)
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by marmbrus <gi...@git.apache.org>.
Github user marmbrus commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-82686838
I tend to agree with @chenghao-intel, unless you have a benchmark that shows a significant improvement i propose we close this issue.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-82687260
ok.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by chenghao-intel <gi...@git.apache.org>.
Github user chenghao-intel commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-81307940
If in that case,does it mean bugs in codegen?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-77741269
[Test build #28371 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/28371/consoleFull) for PR 4940 at commit [`b207614`](https://github.com/apache/spark/commit/b207614bdbc054d1a192f0e44e9ecc3489523630).
* This patch merges cleanly.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request: [SPARK-6215][SQL] Shorten apply and update fun...
Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the pull request:
https://github.com/apache/spark/pull/4940#issuecomment-81130668
I think it is because the codes you refer to access the element directly with array index. If the ordinsl is not valid, runtime exception will be thrown. But for the generated codes, it uses many `if` condition to determine the element to access. So if the ordinal is not valide, it needs to throw an exception. That is why it originally calls `accessorFailure` after all cases are not met.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org