Skip to content

Commit

Permalink
[CsvIO]: update class for parsing date time. (#31996)
Browse files Browse the repository at this point in the history
  • Loading branch information
francisohara24 authored Jul 26, 2024
1 parent 8eb09bf commit 4479281
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
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;
import java.util.Map;
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit 4479281

Please sign in to comment.