Get dataframe schema load to metadata table

后端 未结 2 1101
醉话见心
醉话见心 2021-01-23 09:41

Use case is to read a file and create a dataframe on top of it.After that get the schema of that file and store into a DB table.

For example purpose I am just creating a

2条回答
  •  清歌不尽
    2021-01-23 10:02

    Try this -

    //-- For local file
    val rdd = spark.read.option("wholeFile", true).option("delimiter",",").csv(s"file:///file/path/file.csv").rdd
    
    val schema = StructType(Seq(StructField("Name", StringType, true),
                                StructField("Age", IntegerType, true),
                                StructField("Designation", StringType, true),
                                StructField("Salary", IntegerType, true),
                                StructField("ZipCode", IntegerType, true)))
    
    val df = spark.createDataFrame(rdd,schema)
    

提交回复
热议问题