Uh oh!
There was an error while loading. Please reload this page.
Support for specifying custom date format for date and timestamp types. - #280
Support for specifying custom date format for date and timestamp types.#280HyukjinKwon wants to merge 8 commits into
Conversation
HyukjinKwon
commented
Mar 4, 2016
@falaki Just to let you know, the original functions, |
codecov-io
commented
Mar 4, 2016
Current coverage is |
| val charset = parameters.getOrElse("charset", TextFile.DEFAULT_CHARSET.name()) | ||
| // TODO validate charset? | ||
| val dataFormat = parameters.getOrElse("charset", TextFile.DEFAULT_CHARSET.name()) |
| nullValue: String = ""): DataType = { | ||
| nullValue: String = "", | ||
| dateFormatter: SimpleDateFormat = null): DataType = { | ||
| def tryParseInteger(field: String): DataType = if ((allCatch opt field.toInt).isDefined) { |
There was a problem hiding this comment.
Um.. Do you mean the indentation correction as below?
- from
private[csv] definferField(typeSoFar: DataType,
field: String,
nullValue: String="",
dateFormatter: SimpleDateFormat=null):DataType= {
deftryParseInteger(field: String):DataType=if ((allCatch opt field.toInt).isDefined) {
IntegerType
} else {
tryParseLong(field)
}
...- to
private[csv] definferField(typeSoFar: DataType,
field: String,
nullValue: String="",
dateFormatter: SimpleDateFormat=null):DataType= {
deftryParseInteger(field: String):DataType=if ((allCatch opt field.toInt).isDefined) {
IntegerType
} else {
tryParseLong(field)
}
...There was a problem hiding this comment.
Oh I see. The problem is for lines above:
private[csv] definferField(typeSoFar: DataType,
field: String,
nullValue: String="",
dateFormatter: SimpleDateFormat=null):DataType= {
deftryParseInteger(field: String):DataType=if ((allCatch opt field.toInt).isDefined) {
IntegerType
} else {
tryParseLong(field)
}falaki
commented
Mar 4, 2016
@HyukjinKwon left one more comment. Otherwise looks good. I can merge this before I cut the branch tonight. |
HyukjinKwon
commented
Mar 4, 2016
@falaki (although this is not the right thread to say this), what do you think about This was merged in Spark, apache/spark#11464 and I was working on this for this library as well. However, I just realised that this might not be some kind of what we must do identically for this, like If you think it is good to support |
falaki
commented
Mar 4, 2016
Let's open an issue for it. |
HyukjinKwon
commented
Mar 4, 2016
barrybecker4
commented
Mar 4, 2016
Thank you for adding this! I will pull and build a local snapshot until 1.4.0 officially releases. |
HyukjinKwon
commented
Mar 7, 2016
@barrybecker4 Maybe would you create a PR for that typo (also for other typos if you know)? |
5ean
commented
May 4, 2016
I still face error in python. Maybe i did not use it correctly. Please kindly advise. schema has timestamp type. And the string in csv file '"25/02/2014 00:00:00" exception: Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff] |
The docs are not clear on how to do this so hopefully this can help: https://stackoverflow.com/questions/43259485/how-to-load-csvs-with-timestamps-in-custom-format |
shatestest
commented
May 3, 2019
this is not working as expected. https://stackoverflow.com/questions/55965978/how-to-set-jdbc-partitioncolumn-type-to-date-in-spark-2-4-1/55966481#55966481 |
https://github.com/databricks/spark-csv/issues/279
https://github.com/databricks/spark-csv/issues/262
https://github.com/databricks/spark-csv/issues/266
This PR adds the support to specify custom date format for
DateTypeandTimestampType.For
TimestampType, this uses the given format to infer schema and also to convert the valuesFor
DateType, this uses the given format to convert the values.If the
dateFormatis not given, then it works withTimestamp.valueOf()andDate.valueOf()for backwords compatibility.When it's given, then it uses
SimpleDateFormatfor parsing data.In addition,
IntegerType,DoubleTypeandLongTypehave a higher priority thanTimestampTypein type inference. This means even if the given format isyyyyoryyyy.MM, it will be inferred asIntegerTypeorDoubleType. Since it is type inference, I think it is okay to give such precedences.