You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by rajeshbalamohan <gi...@git.apache.org> on 2016/06/06 13:01:04 UTC

[GitHub] spark pull request #13522: [SPARK-14321][SQL] Reduce date format cost and st...

GitHub user rajeshbalamohan opened a pull request:

    https://github.com/apache/spark/pull/13522

    [SPARK-14321][SQL] Reduce date format cost and string-to-date cost in…

    ## What changes were proposed in this pull request?
    Here is the generated code snippet when executing date functions. SimpleDateFormat is fairly expensive and can show up bottleneck when processing millions of records. It would be better to instantiate it once.
    
    ```
    /* 066 */     UTF8String primitive5 = null;
    /* 067 */     if (!isNull4) {
    /* 068 */       try {
    /* 069 */         primitive5 = UTF8String.fromString(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
    /* 070 */             new java.util.Date(primitive7 * 1000L)));
    /* 071 */       } catch (java.lang.Throwable e) {
    /* 072 */         isNull4 = true;
    /* 073 */       }
    /* 074 */     }
    ```
    
    With modified code, here is the generated code
    ```
    /* 010 */   private java.text.SimpleDateFormat sdf2;
    /* 011 */   private UnsafeRow result13;
    /* 012 */   private org.apache.spark.sql.catalyst.expressions.codegen.BufferHolder bufferHolder14;
    /* 013 */   private org.apache.spark.sql.catalyst.expressions.codegen.UnsafeRowWriter rowWriter15;
    /* 014 */
    ...
    ...
    /* 065 */     boolean isNull0 = isNull3;
    /* 066 */     UTF8String primitive1 = null;
    /* 067 */     if (!isNull0) {
    /* 068 */       try {
    /* 069 */         if (sdf2 == null) {
    /* 070 */           sdf2 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /* 071 */         }
    /* 072 */         primitive1 = UTF8String.fromString(sdf2.format(
    /* 073 */             new java.util.Date(primitive4 * 1000L)));
    /* 074 */       } catch (java.lang.Throwable e) {
    /* 075 */         isNull0 = true;
    /* 076 */       }
    /* 077 */     }
    ```
    
    Similarly Calendar.getInstance was used in DateTimeUtils which can be lazily inited.
    
    
    ## How was this patch tested?
    
    org.apache.spark.sql.catalyst.expressions.DateExpressionsSuite,org.apache.spark.sql.catalyst.util.DateTimeUtilsSuite

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/rajeshbalamohan/spark SPARK-14321-1

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/13522.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 #13522
    
----
commit 602d4a70ba845df3160a07c2c9afe2d5c3c574c4
Author: Rajesh Balamohan <rb...@apache.org>
Date:   2016-06-06T12:54:02Z

    [SPARK-14321][SQL] Reduce date format cost and string-to-date cost in date functions

----


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/60042/
    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 #13522: [SPARK-14321][SQL] Reduce date format cost and st...

Posted by wangyang1992 <gi...@git.apache.org>.
Github user wangyang1992 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13522#discussion_r65899067
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala ---
    @@ -435,20 +437,23 @@ abstract class UnixTime extends BinaryExpression with ExpectsInputTypes {
           case StringType if right.foldable =>
             val sdf = classOf[SimpleDateFormat].getName
             val fString = if (constFormat == null) null else constFormat.toString
    -        val formatter = ctx.freshName("formatter")
             if (fString == null) {
               ev.copy(code = s"""
                 boolean ${ev.isNull} = true;
                 ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};""")
             } else {
    +          val formatter = ctx.freshName("formatter")
    +          ctx.addMutableState(sdf, formatter, s"""$formatter = null;""")
    --- End diff --
    
    Not very familiar with codegen, but I wonder if we can add the instantiation here and avoid the null checking below.
    ctx.addMutableState(sdf, formatter, s"""$formatter = new $sdf("$fString");""")


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/60118/
    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 #13522: [SPARK-14321][SQL] Reduce date format cost and st...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/13522


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    **[Test build #60118 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60118/consoleFull)** for PR 13522 at commit [`425aa7e`](https://github.com/apache/spark/commit/425aa7ea30f1f92143fc9f539c7b928255dee1c9).
     * 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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by rajeshbalamohan <gi...@git.apache.org>.
Github user rajeshbalamohan commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    @cloud-fan  - Sorry about the delay. Rebased SPARK-14321 for master. https://github.com/apache/spark/pull/12105 had become stale and got little messy in my system. Ended up creating this PR. I will close the earlier one after review. 


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    **[Test build #60118 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60118/consoleFull)** for PR 13522 at commit [`425aa7e`](https://github.com/apache/spark/commit/425aa7ea30f1f92143fc9f539c7b928255dee1c9).


---
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 #13522: [SPARK-14321][SQL] Reduce date format cost and st...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13522#discussion_r65925160
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala ---
    @@ -435,20 +437,23 @@ abstract class UnixTime extends BinaryExpression with ExpectsInputTypes {
           case StringType if right.foldable =>
             val sdf = classOf[SimpleDateFormat].getName
             val fString = if (constFormat == null) null else constFormat.toString
    -        val formatter = ctx.freshName("formatter")
             if (fString == null) {
               ev.copy(code = s"""
                 boolean ${ev.isNull} = true;
                 ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};""")
             } else {
    +          val formatter = ctx.freshName("formatter")
    +          ctx.addMutableState(sdf, formatter, s"""$formatter = null;""")
    --- End diff --
    
    creating formatter may fail and be null, so we still need to do null checking below 


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    LGTM except one naming comments, thanks for working on it!


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Merged build finished. 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 #13522: [SPARK-14321][SQL] Reduce date format cost and st...

Posted by wangyang1992 <gi...@git.apache.org>.
Github user wangyang1992 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13522#discussion_r65898385
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala ---
    @@ -554,14 +561,19 @@ case class FromUnixTime(sec: Expression, format: Expression)
               boolean ${ev.isNull} = true;
               ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};""")
           } else {
    +        val sdfTerm = ctx.freshName("formatter")
    --- End diff --
    
    This is trivial but why use a different variable name here from the above one? (which is called "formatter")


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Merged build finished. 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 #13522: [SPARK-14321][SQL] Reduce date format cost and st...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13522#discussion_r65925313
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala ---
    @@ -554,14 +561,19 @@ case class FromUnixTime(sec: Expression, format: Expression)
               boolean ${ev.isNull} = true;
               ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};""")
           } else {
    +        val sdfTerm = ctx.freshName("formatter")
    --- End diff --
    
    `formatter` looks better


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    **[Test build #60042 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60042/consoleFull)** for PR 13522 at commit [`602d4a7`](https://github.com/apache/spark/commit/602d4a70ba845df3160a07c2c9afe2d5c3c574c4).
     * 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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    **[Test build #60042 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/60042/consoleFull)** for PR 13522 at commit [`602d4a7`](https://github.com/apache/spark/commit/602d4a70ba845df3160a07c2c9afe2d5c3c574c4).


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Some more ideas: I think we should create a subclass of `UnixTime` to handle the `left.dataType == StringType && right.foldable` case. In optimizer, we can replace it with null literal if the `formatter` is null, then we don't need to do null check for every record, like this PR did.


---
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 issue #13522: [SPARK-14321][SQL] Reduce date format cost and string-to...

Posted by rajeshbalamohan <gi...@git.apache.org>.
Github user rajeshbalamohan commented on the issue:

    https://github.com/apache/spark/pull/13522
  
    Thank you. I have pushed the fixes in the recent commit. 


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