使用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
如何用ExamDate格式的%2F
替换-
。
答案 0 :(得分:0)
%2F
是百分比编码的/
。这意味着数据完全为30/07/2018
格式。您可以:
to_date
对其进行解析。