How to use Databricks Job Spark Configuration spark_conf?

半世苍凉 提交于 2020-06-09 05:49:08

问题


I have a sample Spark Code where I am trying to access the Values for tables from the Spark Configurations provided by spark_conf Option by using the typeSafe application.conf and Spark Conf in the Databricks UI. The code I am using is below,

When I hit the Run Button in the Databricks UI, the job is finishing successfully, but the println function is printing dummyValue instead of ThisIsTableAOne,ThisIsTableBOne...

I can see from the Spark UI that, the Configurations for TableNames are being passed to the Spark job, but these values are not getting reflected in the Code.

    try {

    val inputConfig = AppConfig.getConfig("input")
    val outputConfig = AppConfig.getConfig("output")

    val tableA = inputConfig.getString("tableA")
    val tableB = inputConfig.getString("tableB")
    val tableC = outputConfig.getString("tableC")

    println(
    s"""
    |$tableA
    |$tableB
    |$tableC
    |""".stripMargin)

    val userDataInTable = sparkSession.createDataFrame(Seq(
    (1, "dummy", "dummy", "dummy")

    )).toDF("id", "col2", "col3", "col4")

    userDataInTable.show(false)

    println("Completed Entry ")


    } catch {
    case e: Exception =>
    sparkSession.stop()
    e.printStackTrace
    }
    //application.conf contains below text,

    spark.tableNameA="dummyValue"
    spark.tableNameB="dummyValue"
    spark.tableNameC="dummyValue"
    input{
    tableA=${spark.tableNameA}
    tableB=${spark.tableNameB}
    }
    output{
    tableC=${spark.tableNameC}
    }

    //AppConfig
    val appConfig = ConfigFactory.load("application.conf")
    def getConfig(moduleName: String): Config = {
    val config = appConfig.getConfig(moduleName)
    config
    }

来源:https://stackoverflow.com/questions/62094327/how-to-use-databricks-job-spark-configuration-spark-conf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!