从火花分区配置单元外部表中的列



创建带有来自 Spark 的分区的外部表

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.SaveMode

val spark = SparkSession.builder().master("local[*]").appName("splitInput").enableHiveSupport().getOrCreate()
val sparkDf = spark.read.option("header","true").option("inferSchema","true").csv("input/candidate/event=ABCD/CandidateScheduleData_3007_2018.csv")
var newDf = sparkDf 
for(col <- sparkDf.columns){    newDf = newDf.withColumnRenamed(col,col.replaceAll("\s", "_"))  }
newDf.write.mode(SaveMode.Overwrite).option("path","/output/candidate/event=ABCD/").partitionBy("CenterCode","ExamDate").saveAsTable("abc.candidatelist")

一切正常,除了分区列ExamDate创建格式

ExamDate=30%2F07%2F2018 instead of ExamDate=30-07-2018

如何将%2F替换为考试日期格式的-

%2F是百分比编码/。这意味着数据完全采用30/07/2018格式。您可以:

  • 使用指定的格式to_date解析它。
  • 使用所需格式手动设置列的格式。

最新更新