pyscala commented on a change in pull request #13834:
URL: https://github.com/apache/flink/pull/13834#discussion_r514885227
##########
File path:
flink-formats/flink-csv/src/main/java/org/apache/flink/formats/csv/CsvToRowDataConverters.java
##########
@@ -221,12 +221,22 @@ private int convertToDate(JsonNode jsonNode) {
return (int)
Date.valueOf(jsonNode.asText()).toLocalDate().toEpochDay();
}
- private int convertToTime(JsonNode jsonNode) {
+ private CsvToRowDataConverter convertToTime(TimeType timeType) {
+ final int precision = timeType.getPrecision();
// csv currently is using Time.valueOf() to parse time string
- LocalTime localTime =
Time.valueOf(jsonNode.asText()).toLocalTime();
// TODO: FLINK-17525 support millisecond and nanosecond
// get number of milliseconds of the day
- return localTime.toSecondOfDay() * 1000;
+ return jsonNode -> {
+ LocalTime localTime =
LocalTime.parse(jsonNode.asText());
+ if (precision == 3) {
+ return localTime.toNanoOfDay() / 1000_000L;
+ } else if (precision == 0) {
+ return localTime.toSecondOfDay() * 1000L;
+ } else {
+ throw new IllegalArgumentException("Csv does
not support TIME type " +
+ "with precision: " + precision + ", it
only supports precision 0 or 3.");
+ }
+ };
Review comment:
I will optimize.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]