diff --git a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthBatchReader.java b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthBatchReader.java index d389211b930..f63eac3b528 100644 --- a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthBatchReader.java +++ b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthBatchReader.java @@ -143,8 +143,6 @@ private boolean parseLine(String line, RowSetLoader writer) throws IOException { for (FixedwidthFieldConfig field : config.getFields()) { value = line.substring(field.getIndex() - 1, field.getIndex() + field.getWidth() - 1); dataType = field.getType(); - dateTimeFormat = field.getDateTimeFormat(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH); try { switch (dataType) { case INT: @@ -154,15 +152,21 @@ private boolean parseLine(String line, RowSetLoader writer) throws IOException { writer.scalar(i).setString(value); break; case DATE: + dateTimeFormat = field.getDateTimeFormat(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH); LocalDate date = LocalDate.parse(value, formatter); writer.scalar(i).setDate(date); break; case TIME: - LocalTime time = LocalTime.parse(value, formatter); + dateTimeFormat = field.getDateTimeFormat(); + DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH); + LocalTime time = LocalTime.parse(value, formatter2); writer.scalar(i).setTime(time); break; case TIMESTAMP: - LocalDateTime ldt = LocalDateTime.parse(value, formatter); + dateTimeFormat = field.getDateTimeFormat(); + DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern(dateTimeFormat, Locale.ENGLISH); + LocalDateTime ldt = LocalDateTime.parse(value, formatter3); ZoneId z = ZoneId.of("America/Toronto"); ZonedDateTime zdt = ldt.atZone(z); Instant timeStamp = zdt.toInstant(); diff --git a/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java b/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java index a24d3498297..f29219e6bd7 100644 --- a/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java +++ b/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java @@ -101,10 +101,10 @@ public void testExplicitQuery() throws Exception { //Test Serialization/Deserialization @Test public void testSerDe() throws Exception { - String sql = "SELECT COUNT(*) FROM dfs.`fwf/test.fwf`"; + String sql = "SELECT COUNT(*) FROM cp.`fwf/test.fwf`"; String plan = queryBuilder().sql(sql).explainJson(); long cnt = queryBuilder().physical(plan).singletonLong(); - assertEquals(5L, cnt); + assertEquals(25L, cnt); } @Test