Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed May 26, 2020
1 parent b44acee commit 791bc2f
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package test.org.apache.spark.sql;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.util.*;
Expand Down Expand Up @@ -210,6 +212,17 @@ private static Row createRecordSpark22000Row(Long index) {
return new GenericRow(values);
}

private static String timestampToString(Timestamp ts) {
String timestampString = String.valueOf(ts);
String formatted = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ts);

if (timestampString.length() > 19 && timestampString.substring(19) != ".0") {
return formatted + timestampString.substring(19);
} else {
return formatted;
}
}

private static RecordSpark22000 createRecordSpark22000(Row recordRow) {
RecordSpark22000 record = new RecordSpark22000();
record.setShortField(String.valueOf(recordRow.getShort(0)));
Expand All @@ -219,7 +232,7 @@ private static RecordSpark22000 createRecordSpark22000(Row recordRow) {
record.setDoubleField(String.valueOf(recordRow.getDouble(4)));
record.setStringField(recordRow.getString(5));
record.setBooleanField(String.valueOf(recordRow.getBoolean(6)));
record.setTimestampField(String.valueOf(recordRow.getTimestamp(7)));
record.setTimestampField(timestampToString(recordRow.getTimestamp(7)));
// This would figure out that null value will not become "null".
record.setNullIntField(null);
return record;
Expand Down

0 comments on commit 791bc2f

Please sign in to comment.