From 44792814ff303cd561a1fb3d0ff6cb1b4b4c3135 Mon Sep 17 00:00:00 2001 From: Francis O'Hara Date: Fri, 26 Jul 2024 14:09:35 +0000 Subject: [PATCH] [CsvIO]: update class for parsing date time. (#31996) --- .../org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java | 2 +- .../apache/beam/sdk/io/csv/CsvIOParseHelpersTest.java | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java index 4e4102f0efb7..15a398d3c557 100644 --- a/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java +++ b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpers.java @@ -21,7 +21,6 @@ import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; import java.math.BigDecimal; -import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -29,6 +28,7 @@ import org.apache.beam.sdk.schemas.Schema; import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings; import org.apache.commons.csv.CSVFormat; +import org.joda.time.Instant; /** A utility class containing shared methods for parsing CSV records. */ final class CsvIOParseHelpers { diff --git a/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpersTest.java b/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpersTest.java index 97374cf52fe6..5276fa008c7c 100644 --- a/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpersTest.java +++ b/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseHelpersTest.java @@ -21,13 +21,12 @@ import static org.junit.Assert.assertThrows; import java.math.BigDecimal; -import java.time.DateTimeException; -import java.time.Instant; import java.util.Map; import org.apache.beam.sdk.schemas.Schema; import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; import org.apache.commons.collections.keyvalue.DefaultMapEntry; import org.apache.commons.csv.CSVFormat; +import org.joda.time.Instant; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -382,20 +381,20 @@ public void givenFloatWithSurroundingSpaces_parses() { } @Test - public void givenDatetimeWithSurroundingSpaces() throws DateTimeException { + public void givenDatetimeWithSurroundingSpaces() { Instant datetime = Instant.parse("1234-01-23T10:00:05.000Z"); DefaultMapEntry cellToExpectedValue = new DefaultMapEntry(" 1234-01-23T10:00:05.000Z ", datetime); Schema schema = Schema.builder().addDateTimeField("a_datetime").addStringField("a_string").build(); - DateTimeException e = + IllegalArgumentException e = assertThrows( - DateTimeException.class, + IllegalArgumentException.class, () -> CsvIOParseHelpers.parseCell( cellToExpectedValue.getKey().toString(), schema.getField("a_datetime"))); assertEquals( - "Text " + "' 1234-01-23T10:00:05.000Z '" + " could not be parsed at index 0", + "Invalid format: \" 1234-01-23T10:00:05.000Z \" field a_datetime was received -- type mismatch", e.getMessage()); }