Creating hive table using parquet file metadata

后端 未结 6 1457
面向向阳花
面向向阳花 2021-02-01 11:01

I wrote a DataFrame as parquet file. And, I would like to read the file using Hive using the metadata from parquet.

Output from writing parquet write

_co         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 11:40

    I would like to expand James answer,

    The following code will work for all datatypes including ARRAY, MAP and STRUCT.

    Have tested in SPARK 2.2

    val df=sqlContext.parquetFile("parquetFilePath")
    val schema = df.schema
    var columns = schema.fields
    var ddl1 = "CREATE EXTERNAL TABLE " tableName + " ("
    val cols=(for(column <- columns) yield column.name+" "+column.dataType.sql).mkString(",")
    ddl1=ddl1+cols+" ) STORED AS PARQUET LOCATION '/tmp/hive_test1/'"
    spark.sql(ddl1)
    

提交回复
热议问题