aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorWenchen Fan <cloud0fan@outlook.com>2015-07-15 10:31:39 -0700
committerReynold Xin <rxin@databricks.com>2015-07-15 10:31:39 -0700
commitfa4ec3606a965238423f977808163983c9d56e0a (patch)
tree9376179744d72df86fe99dc7e8384c47ffb2b43d /core
parent6f6902597d5d687049c103bc0cf6da30919b92d8 (diff)
downloadspark-fa4ec3606a965238423f977808163983c9d56e0a.tar.gz
spark-fa4ec3606a965238423f977808163983c9d56e0a.tar.bz2
spark-fa4ec3606a965238423f977808163983c9d56e0a.zip
[SPARK-9020][SQL] Support mutable state in code gen expressions
We can keep expressions' mutable states in generated class(like `SpecificProjection`) as member variables, so that we can read and modify them inside codegened expressions. Author: Wenchen Fan <cloud0fan@outlook.com> Closes #7392 from cloud-fan/mutable-state and squashes the following commits: eb3a221 [Wenchen Fan] fix order 73144d8 [Wenchen Fan] naming improvement 318f41d [Wenchen Fan] address more comments d43b65d [Wenchen Fan] address comments fd45c7a [Wenchen Fan] Support mutable state in code gen expressions
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/org/apache/spark/TaskContext.scala15
1 files changed, 14 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/TaskContext.scala b/core/src/main/scala/org/apache/spark/TaskContext.scala
index d09e17dea0..248339148d 100644
--- a/core/src/main/scala/org/apache/spark/TaskContext.scala
+++ b/core/src/main/scala/org/apache/spark/TaskContext.scala
@@ -32,7 +32,20 @@ object TaskContext {
*/
def get(): TaskContext = taskContext.get
- private val taskContext: ThreadLocal[TaskContext] = new ThreadLocal[TaskContext]
+ /**
+ * Returns the partition id of currently active TaskContext. It will return 0
+ * if there is no active TaskContext for cases like local execution.
+ */
+ def getPartitionId(): Int = {
+ val tc = taskContext.get()
+ if (tc == null) {
+ 0
+ } else {
+ tc.partitionId()
+ }
+ }
+
+ private[this] val taskContext: ThreadLocal[TaskContext] = new ThreadLocal[TaskContext]
// Note: protected[spark] instead of private[spark] to prevent the following two from
// showing up in JavaDoc.