text: Q:
  
  Extracting Column Details & Type from Schema Scala
  
  i am using AWS EMR v5.29.0 Spark v2.4.4 and Scala v2.11.12.
  i am reading a file with infer schema method and creating dataframe with column names and datatype of column name with below code
  val df = spark.read.options(Map("inferSchema"->"true","header"->"true")).csv("s3://bucket-name/File_Name.csv")
  val columnList = df.schema.fields.map(field => (field.name, field.dataType.typeName)).toList.toDF("column_name","datatype")
  
  when i do df.printSchema() the output is as below.
  df.printSchema()
  
  Output:
  
  root
   |-- ABC|EFG|IJK|LMN: string (nullable = true)
  
  When i am doing columnList.show()
  the output is coming as below
  +--------------------+--------+
  |         column_name|datatype|
  +--------------------+--------+
  |ABC|EFG|IJK|LMN     |  string|
  +--------------------+--------+
  
  where as the output required is like below.
  +---------------+--------+
  |column_name    |datatype|
  +---------------+--------+
  |ABC            |string  |
  |EFG            |string  |
  |IJK            |string  |
  |LMN            |string  |
  +---------------+--------+
  
  Regards
  mahi
  
  A:
  
  Try below code.
  scala> df.select(split($"column_name","\\|").as("column_name"),$"datatype").select(explode($"column_name"),$"datatype").show(false)
  +---+--------+
  |col|datatype|
  +---+--------+
  |ABC|string  |
  |EFG|string  |
  |IJK|string  |
  |LMN|string  |
  +---+--------+
  
  