Skip to content

Commit

Permalink
Test for the include-metadata flag in the configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Pigott committed Dec 8, 2018
1 parent 7e9ce37 commit 7b4527c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public JdbcToArrowConfig(BaseAllocator allocator, Calendar calendar) {
this.includeMetadata = false;
}

/**
* Constructs a new configuration from the provided allocator and calendar. The <code>allocator</code>
* is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define
* Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
*
* @param allocator The memory allocator to construct the Arrow vectors with.
* @param calendar The calendar to use when constructing Timestamp fields and reading time-based results.
* @param includeMetadata Whether to include JDBC field metadata in the Arrow Schema Field metadata.
*/
public JdbcToArrowConfig(BaseAllocator allocator, Calendar calendar, boolean includeMetadata) {
this(allocator, calendar);
this.includeMetadata = includeMetadata;
Expand All @@ -75,6 +84,7 @@ public Calendar getCalendar() {
* Arrow schema, and reading time-based fields from the JDBC <code>ResultSet</code>.
*
* @param calendar the calendar to set.
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
* @exception NullPointerExeption if <code>calendar</code> is <code>null</code>.
*/
public JdbcToArrowConfig setCalendar(Calendar calendar) {
Expand All @@ -95,6 +105,7 @@ public BaseAllocator getAllocator() {
* Sets the memory allocator to use when construting the Arrow vectors from the ResultSet.
*
* @param allocator the allocator to set.
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
* @exception NullPointerException if <code>allocator</code> is null.
*/
public JdbcToArrowConfig setAllocator(BaseAllocator allocator) {
Expand All @@ -103,10 +114,26 @@ public JdbcToArrowConfig setAllocator(BaseAllocator allocator) {
return this;
}

public boolean includeMetadata() {
/**
* Whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
*
* @return <code>true</code> to include field metadata, <code>false</code> to exclude it.
*/
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;
}

/**
* Whether this configuration is valid. The configuration is valid when:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig
final FieldType fieldType;

final Map<String, String> metadata;
if (config.includeMetadata()) {
if (config.getIncludeMetadata()) {
metadata = new HashMap<String, String>();
metadata.put(JdbcToArrow.SQL_CATALOG_NAME_KEY, rsmd.getCatalogName(i));
metadata.put(JdbcToArrow.SQL_TABLE_NAME_KEY, rsmd.getTableName(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ public void testConfig() {
assertTrue(newAllocator == config.getAllocator());
assertTrue(newCalendar == config.getCalendar());
}

@Test public void testIncludeMetadata() {
JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, calendar);
assertTrue(config.isValid());
assertFalse(config.getIncludeMetadata());

config.setIncludeMetadata(true);
assertTrue(config.getIncludeMetadata());

config.setIncludeMetadata(false);
assertFalse(config.getIncludeMetadata());

config = new JdbcToArrowConfig(allocator, calendar, true);
assertTrue(config.isValid());
assertTrue(config.getIncludeMetadata());

config = new JdbcToArrowConfig(allocator, calendar, false);
assertTrue(config.isValid());
assertFalse(config.getIncludeMetadata());
}
}

0 comments on commit 7b4527c

Please sign in to comment.