我正在尝试在timestamp/date
路径的末尾附加destination
字符串,但失败。如果删除,则没有错误。我尝试了以下事情:
val formatDate = new SimpleDateFormat("yyyy-mm-dd hh:ss")
val newDate = formatDate.format(Calendar.getInstance().getTime())
val finalPath = jobInfo.jobId + "_" + jobInfo.jobRunId + "_" + newDate
df.write.mode(SaveMode.Overwrite).parquet(destPath + "\\" + cTableName + "\\" + finalPath.trim())
错误:
java.io.IOException: Mkdirs failed to create file:/C:/tmp/sparkIF/employees/1000_12_2020-31-18 08:11/_temporary/0/_temporary/attempt_20200318203112_0002_m_000000_2
正如我所看到的,它正在尝试创建temporary
目录。我不确定为什么会这样做。因为,我正在使用overwrite
模式,所以现有目录应该没有问题
我认为您的示例中的问题是路径中的空格符号。保存数据的更好方法取决于使用目录日期分区的日期。例如:
val cal = Calendar.getInstance()
val datePartitions = Seq(
s"year=${cal.get(Calendar.YEAR)}",
s"month=${"%02d".format(cal.get(Calendar.MONTH))}",
s"day=${"%02d".format(cal.get(Calendar.DAY_OF_MONTH))}",
s"hour=${"%02d".format(cal.get(Calendar.HOUR))}",
s"minute=${"%02d".format(cal.get(Calendar.MINUTE))}"
).mkString(File.separator)
val finalPath = s"${jobId}_$jobRunId${File.separator}$datePartitions"
println(s"$destPath${File.separator}$cTableName${File.separator}$finalPath")
// it prints your prefix and year=2020\month=02\day=19\hour=10\minute=03 suffix
Hadoop在目录路径中不支持分号
下面的代码应该起作用
val finalPath = jobInfo.jobId + "_" + jobInfo.jobRunId + "_" + newDate.replaceAll(":","_")