You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2015/07/20 18:41:29 UTC
spark git commit: [SPARK-9177][SQL] Reuse of calendar object in
WeekOfYear
Repository: spark
Updated Branches:
refs/heads/master 5112b7f58 -> a15ecd057
[SPARK-9177][SQL] Reuse of calendar object in WeekOfYear
https://issues.apache.org/jira/browse/SPARK-9177
rxin Are we sure that this is thread safe? chenghao-intel explained in another PR that every partition (if I remember correctly) uses one expression instance. This instance isn't used by multiple threads, is it? If not, we are fine.
Author: Tarek Auel <ta...@googlemail.com>
Closes #7516 from tarekauel/SPARK-9177 and squashes the following commits:
0c1313a [Tarek Auel] [SPARK-9177] utilize more powerful addMutableState
6e2f03f [Tarek Auel] Merge branch 'master' into SPARK-9177
a69ec92 [Tarek Auel] [SPARK-9177] address comment
6cfb180 [Tarek Auel] [SPARK-9177] calendar as lazy transient val
ff97b09 [Tarek Auel] [SPARK-9177] Reuse calendar object in interpreted code and codegen
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/a15ecd05
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/a15ecd05
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/a15ecd05
Branch: refs/heads/master
Commit: a15ecd057a6226e5cf83ca05c46748624a1cfc8c
Parents: 5112b7f
Author: Tarek Auel <ta...@googlemail.com>
Authored: Mon Jul 20 09:41:25 2015 -0700
Committer: Reynold Xin <rx...@databricks.com>
Committed: Mon Jul 20 09:41:25 2015 -0700
----------------------------------------------------------------------
.../sql/catalyst/expressions/datetimeFunctions.scala | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/a15ecd05/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala
index 8024455..9e55f05 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala
@@ -213,10 +213,14 @@ case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCa
override def dataType: DataType = IntegerType
- override protected def nullSafeEval(date: Any): Any = {
+ @transient private lazy val c = {
val c = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
c.setFirstDayOfWeek(Calendar.MONDAY)
c.setMinimalDaysInFirstWeek(4)
+ c
+ }
+
+ override protected def nullSafeEval(date: Any): Any = {
c.setTimeInMillis(date.asInstanceOf[Int] * 1000L * 3600L * 24L)
c.get(Calendar.WEEK_OF_YEAR)
}
@@ -225,10 +229,13 @@ case class WeekOfYear(child: Expression) extends UnaryExpression with ImplicitCa
nullSafeCodeGen(ctx, ev, (time) => {
val cal = classOf[Calendar].getName
val c = ctx.freshName("cal")
+ ctx.addMutableState(cal, c,
+ s"""
+ $c = $cal.getInstance(java.util.TimeZone.getTimeZone("UTC"));
+ $c.setFirstDayOfWeek($cal.MONDAY);
+ $c.setMinimalDaysInFirstWeek(4);
+ """)
s"""
- $cal $c = $cal.getInstance(java.util.TimeZone.getTimeZone("UTC"));
- $c.setFirstDayOfWeek($cal.MONDAY);
- $c.setMinimalDaysInFirstWeek(4);
$c.setTimeInMillis($time * 1000L * 3600L * 24L);
${ev.primitive} = $c.get($cal.WEEK_OF_YEAR);
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org