Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CsvIO]: update class for representing date-time in CsvIOParseHelpers::parseCell(String, Schema.Field) #31996

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading