I have a file which I am converting into Dataframe. For the schema, I want it to be read from a config fle
I don't want to give the schema hardcoded in the code as it might change with time , so we are putting the schema in a separate file.
val searchPath = "/hdfs/cbt/dfgdfgdf_fsdfg/data/noheaderfile"
val columns = "Name,ID,Address,City"
val fields = columns.split(",").map(fieldName => StructField(fieldName, StringType,
nullable = true))
val customSchema = StructType(fields)
var dfPivot =spark.read.format("com.databricks.spark.csv").option("header","false").option("inferSchema", "false").schema(customSchema).load(searchPath)
Here I want the following line of the code to be changed.
val columns = "Name,ID,Address,City"
Instead there should be a file instead which contains the schema.
Please advise.