Skip to content

Commit 492dca3

Browse files
Vladimir VladimirovJoshRosen
authored andcommitted
[SPARK-8528] Expose SparkContext.applicationId in PySpark
Use case - we want to log applicationId (YARN in hour case) to request help with troubleshooting from the DevOps Author: Vladimir Vladimirov <[email protected]> Closes #6936 from smartkiwi/master and squashes the following commits: 870338b [Vladimir Vladimirov] this would make doctest to run in python3 0eae619 [Vladimir Vladimirov] Scala doesn't use u'...' for unicode literals 14d77a8 [Vladimir Vladimirov] stop using ELLIPSIS b4ebfc5 [Vladimir Vladimirov] addressed PR feedback - updated docstring 223a32f [Vladimir Vladimirov] fixed test - applicationId is property that returns the string 3221f5a [Vladimir Vladimirov] [SPARK-8528] added documentation for Scala 2cff090 [Vladimir Vladimirov] [SPARK-8528] add applicationId property for SparkContext object in pyspark
1 parent a5c2961 commit 492dca3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ class SparkContext(config: SparkConf) extends Logging with ExecutorAllocationCli
315315
_dagScheduler = ds
316316
}
317317

318+
/**
319+
* A unique identifier for the Spark application.
320+
* Its format depends on the scheduler implementation.
321+
* (i.e.
322+
* in case of local spark app something like 'local-1433865536131'
323+
* in case of YARN something like 'application_1433865536131_34483'
324+
* )
325+
*/
318326
def applicationId: String = _applicationId
319327
def applicationAttemptId: Option[String] = _applicationAttemptId
320328

python/pyspark/context.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ def version(self):
291291
"""
292292
return self._jsc.version()
293293

294+
@property
295+
@ignore_unicode_prefix
296+
def applicationId(self):
297+
"""
298+
A unique identifier for the Spark application.
299+
Its format depends on the scheduler implementation.
300+
(i.e.
301+
in case of local spark app something like 'local-1433865536131'
302+
in case of YARN something like 'application_1433865536131_34483'
303+
)
304+
>>> sc.applicationId # doctest: +ELLIPSIS
305+
u'local-...'
306+
"""
307+
return self._jsc.sc().applicationId()
308+
294309
@property
295310
def startTime(self):
296311
"""Return the epoch time when the Spark Context was started."""

0 commit comments

Comments
 (0)