Skip to content

Commit

Permalink
ARROW-3923: Supporting a null Calendar in the config, and reverting t…
Browse files Browse the repository at this point in the history
…he breaking change.
  • Loading branch information
Mike Pigott committed Feb 3, 2019
1 parent cd9a230 commit 4d95da0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, J
public static VectorSchemaRoot sqlToArrow(ResultSet resultSet) throws SQLException, IOException {
Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not be null");

return sqlToArrow(resultSet, (Calendar) null);
return sqlToArrow(resultSet, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public final class JdbcToArrowConfig {
*/
JdbcToArrowConfig(BaseAllocator allocator, Calendar calendar) {
Preconditions.checkNotNull(allocator, "Memory allocator cannot be null");
Preconditions.checkNotNull(calendar, "Calendar object can not be null");

this.allocator = allocator;
this.calendar = calendar;
}

/**
* The calendar to use when defining Arrow Timestamp fields
* and retrieving time-based fields from the database.
* and retrieving {@link Date}, {@link Time}, or {@link Timestamp}
* data types from the {@link ResultSet}, or <code>null</code> if not converting.
* @return the calendar.
*/
public Calendar getCalendar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class JdbcToArrowConfigBuilder {

/**
* Default constructor for the <code>JdbcToArrowConfigBuilder}</code>.
* Use the setter methods for the allocator and calendar; both must be
* Use the setter methods for the allocator and calendar; the allocator must be
* set. Otherwise, {@link #build()} will throw a {@link NullPointerException}.
*/
public JdbcToArrowConfigBuilder() {
Expand All @@ -41,9 +41,9 @@ public JdbcToArrowConfigBuilder() {
}

/**
* Constructor for the <code>JdbcToArrowConfigBuilder</code>. Both the
* allocator and calendar are required. A {@link NullPointerException}
* will be thrown if one of the arguments is <code>null</code>.
* Constructor for the <code>JdbcToArrowConfigBuilder</code>. The
* allocator is required, and a {@link NullPointerException}
* will be thrown if it is <code>null</code>.
* <p>
* The allocator is used to construct Arrow vectors from the JDBC ResultSet.
* The calendar is used to determine the time zone of {@link java.sql.Timestamp}
Expand All @@ -59,7 +59,6 @@ public JdbcToArrowConfigBuilder(BaseAllocator allocator, Calendar calendar) {
this();

Preconditions.checkNotNull(allocator, "Memory allocator cannot be null");
Preconditions.checkNotNull(calendar, "Calendar object can not be null");

this.allocator = allocator;
this.calendar = calendar;
Expand All @@ -82,10 +81,8 @@ public JdbcToArrowConfigBuilder setAllocator(BaseAllocator allocator) {
* Arrow schema, and reading time-based fields from the JDBC <code>ResultSet</code>.
*
* @param calendar the calendar to set.
* @exception NullPointerExeption if <code>calendar</code> is <code>null</code>.
*/
public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) {
Preconditions.checkNotNull(calendar, "Calendar object can not be null");
this.calendar = calendar;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ public void testBuilderNullArguments() {
new JdbcToArrowConfigBuilder(null, null);
}

@Test(expected = NullPointerException.class)
public void testConfigNullCalendar() {
new JdbcToArrowConfig(allocator, null);
JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, null);
assertNull(config.getCalendar());
}

@Test(expected = NullPointerException.class)
@Test
public void testBuilderNullCalendar() {
new JdbcToArrowConfigBuilder(allocator, null);
JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, null);
JdbcToArrowConfig config = builder.build();
assertNull(config.getCalendar());
}

@Test(expected = NullPointerException.class)
Expand All @@ -68,10 +70,11 @@ public void testSetNullAllocator() {
builder.setAllocator(null);
}

@Test(expected = NullPointerException.class)
@Test
public void testSetNullCalendar() {
JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar);
builder.setCalendar(null);
JdbcToArrowConfig config = builder.setCalendar(null).build();
assertNull(config.getCalendar());
}

@Test
Expand Down

0 comments on commit 4d95da0

Please sign in to comment.