Skip to content

Commit

Permalink
ARROW-3966: Moving the metadata flag assignment into the builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Pigott committed Feb 3, 2019
1 parent 69022c2 commit 2928513
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,4 @@ public BaseAllocator getAllocator() {
public boolean getIncludeMetadata() {
return includeMetadata;
}

/**
* Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
*
* @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata.
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
*/
public JdbcToArrowConfig setIncludeMetadata(boolean includeMetadata) {
this.includeMetadata = includeMetadata;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class JdbcToArrowConfigBuilder {
private Calendar calendar;
private BaseAllocator allocator;
private boolean includeMetadata;

/**
* Default constructor for the <code>JdbcToArrowConfigBuilder}</code>.
Expand All @@ -38,6 +39,7 @@ public class JdbcToArrowConfigBuilder {
public JdbcToArrowConfigBuilder() {
this.allocator = null;
this.calendar = null;
this.includeMetadata = false;
}

/**
Expand All @@ -63,6 +65,32 @@ public JdbcToArrowConfigBuilder(BaseAllocator allocator, Calendar calendar) {

this.allocator = allocator;
this.calendar = calendar;
this.includeMetadata = false;
}

/**
* Constructor for the <code>JdbcToArrowConfigBuilder</code>. Both the
* allocator and calendar are required. A {@link NullPointerException}
* will be thrown if either of those arguments 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}
* fields and convert {@link java.sql.Date}, {@link java.sql.Time}, and
* {@link java.sql.Timestamp} fields to a single, common time zone when reading
* from the result set.
* </p>
* <p>
* The <code>includeMetadata</code> argument, if <code>true</code> will cause
* various information about each database field to be added to the Vector
* Schema's field metadata.
* </p>
*
* @param allocator The Arrow Vector memory allocator.
* @param calendar The calendar to use when constructing timestamp fields.
*/
public JdbcToArrowConfigBuilder(BaseAllocator allocator, Calendar calendar, boolean includeMetadata) {
this(allocator, calendar);
this.includeMetadata = includeMetadata;
}

/**
Expand Down Expand Up @@ -90,6 +118,17 @@ public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) {
return this;
}

/**
* Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
*
* @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata.
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
*/
public JdbcToArrowConfigBuilder setIncludeMetadata(boolean includeMetadata) {
this.includeMetadata = includeMetadata;
return this;
}

/**
* This builds the {@link JdbcToArrowConfig} from the provided
* {@link BaseAllocator} and {@link Calendar}.
Expand All @@ -98,6 +137,6 @@ public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) {
* @throws NullPointerException if either the allocator or calendar was not set.
*/
public JdbcToArrowConfig build() {
return new JdbcToArrowConfig(allocator, calendar, false);
return new JdbcToArrowConfig(allocator, calendar, includeMetadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ public void testConfig() {
}

@Test public void testIncludeMetadata() {
JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, calendar, false);
JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar, false);

JdbcToArrowConfig config = builder.build();
assertFalse(config.getIncludeMetadata());

config.setIncludeMetadata(true);
builder.setIncludeMetadata(true);
config = builder.build();
assertTrue(config.getIncludeMetadata());

config.setIncludeMetadata(false);
assertFalse(config.getIncludeMetadata());
config = new JdbcToArrowConfigBuilder(allocator, calendar, true).build();
assertTrue(config.getIncludeMetadata());

config = new JdbcToArrowConfig(allocator, calendar, true);
assertTrue(config.getIncludeMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {

@Test
public void testJdbcSchemaMetadata() throws SQLException {
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
config.setIncludeMetadata(true);
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {

@Test
public void testJdbcSchemaMetadata() throws SQLException {
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
config.setIncludeMetadata(true);
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {

@Test
public void testJdbcSchemaMetadata() throws SQLException {
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
config.setIncludeMetadata(true);
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {

@Test
public void testJdbcSchemaMetadata() throws SQLException {
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
config.setIncludeMetadata(true);
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
@Test
public void testJdbcSchemaMetadata() throws SQLException {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()));
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar).build();
config.setIncludeMetadata(true);
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true).build();
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);
Expand Down

0 comments on commit 2928513

Please sign in to comment.