Getting app run id for a Spark job

后端 未结 4 1251
忘掉有多难
忘掉有多难 2020-12-03 21:05

I\'d like, from where I run a Spark job, to get the unique id of that job.

Via the Spark master node website, I can see that id. It\'s something like:



        
相关标签:
4条回答
  • 2020-12-03 21:32

    It depends on which language you are using.

    Scala

    https://spark.apache.org/docs/1.6.1/api/scala/index.html#org.apache.spark.SparkContext

    sc.applicationId
    

    Java

    https://spark.apache.org/docs/1.6.2/api/java/org/apache/spark/api/java/JavaSparkContext.html

    sparkContext.sc().applicationId();
    

    Python

    http://spark.apache.org/docs/1.6.2/api/python/pyspark.html#pyspark.SparkContext

    sc.applicationId
    

    It can also depend on Spark version.

    0 讨论(0)
  • 2020-12-03 21:33

    With the introduction of the spark: org.apache.spark.sql.SparkSession from Spark 2.0+ on use

    scala> spark.sparkContext.applicationId
    res1: String = app-20170228091742-0025
    
    0 讨论(0)
  • 2020-12-03 21:40

    For those using pyspark, see this nearly identical question: How to extract application ID from the PySpark context

    The answer from @vvladymyrov worked for me running pyspark in yarn-client mode.

    >>> sc._jsc.sc().applicationId()
    u'application_1433865536131_34483'
    
    0 讨论(0)
  • 2020-12-03 21:45

    yes, exactly as you said:

    sc.applicationId
    res0: String = app-20150224184813-11531
    

    (This is spark 1.2)

    See API doc at

    • https://spark.apache.org/docs/1.6.1/api/scala/index.html#org.apache.spark.SparkContext
    0 讨论(0)
提交回复
热议问题