Skip to content

Commit 05ae3f1

Browse files
Megan Fossestherbuchwalter
Megan Foss
authored andcommitted
Fixed Serialization/Deserialization test
1 parent 18bc812 commit 05ae3f1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthBatchReader.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ private boolean parseLine(String line, RowSetLoader writer) throws IOException {
143143
for (FixedwidthFieldConfig field : config.getFields()) {
144144
value = line.substring(field.getIndex() - 1, field.getIndex() + field.getWidth() - 1);
145145
dataType = field.getType();
146-
dateTimeFormat = field.getDateTimeFormat();
147-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH);
148146
try {
149147
switch (dataType) {
150148
case INT:
@@ -154,15 +152,21 @@ private boolean parseLine(String line, RowSetLoader writer) throws IOException {
154152
writer.scalar(i).setString(value);
155153
break;
156154
case DATE:
155+
dateTimeFormat = field.getDateTimeFormat();
156+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH);
157157
LocalDate date = LocalDate.parse(value, formatter);
158158
writer.scalar(i).setDate(date);
159159
break;
160160
case TIME:
161-
LocalTime time = LocalTime.parse(value, formatter);
161+
dateTimeFormat = field.getDateTimeFormat();
162+
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH);
163+
LocalTime time = LocalTime.parse(value, formatter2);
162164
writer.scalar(i).setTime(time);
163165
break;
164166
case TIMESTAMP:
165-
LocalDateTime ldt = LocalDateTime.parse(value, formatter);
167+
dateTimeFormat = field.getDateTimeFormat();
168+
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH);
169+
LocalDateTime ldt = LocalDateTime.parse(value, formatter3);
166170
ZoneId z = ZoneId.of("America/Toronto");
167171
ZonedDateTime zdt = ldt.atZone(z);
168172
Instant timeStamp = zdt.toInstant();

contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public void testExplicitQuery() throws Exception {
101101
//Test Serialization/Deserialization
102102
@Test
103103
public void testSerDe() throws Exception {
104-
String sql = "SELECT COUNT(*) FROM dfs.`fwf/test.fwf`";
104+
String sql = "SELECT COUNT(*) FROM cp.`fwf/test.fwf`";
105105
String plan = queryBuilder().sql(sql).explainJson();
106106
long cnt = queryBuilder().physical(plan).singletonLong();
107-
assertEquals(5L, cnt);
107+
assertEquals(25L, cnt);
108108
}
109109

110110
@Test

0 commit comments

Comments
 (0)