Skip to content

Commit 7b4527c

Browse files
author
Mike Pigott
committed
Test for the include-metadata flag in the configuration.
1 parent 7e9ce37 commit 7b4527c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public JdbcToArrowConfig(BaseAllocator allocator, Calendar calendar) {
5656
this.includeMetadata = false;
5757
}
5858

59+
/**
60+
* Constructs a new configuration from the provided allocator and calendar. The <code>allocator</code>
61+
* is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define
62+
* Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
63+
*
64+
* @param allocator The memory allocator to construct the Arrow vectors with.
65+
* @param calendar The calendar to use when constructing Timestamp fields and reading time-based results.
66+
* @param includeMetadata Whether to include JDBC field metadata in the Arrow Schema Field metadata.
67+
*/
5968
public JdbcToArrowConfig(BaseAllocator allocator, Calendar calendar, boolean includeMetadata) {
6069
this(allocator, calendar);
6170
this.includeMetadata = includeMetadata;
@@ -75,6 +84,7 @@ public Calendar getCalendar() {
7584
* Arrow schema, and reading time-based fields from the JDBC <code>ResultSet</code>.
7685
*
7786
* @param calendar the calendar to set.
87+
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
7888
* @exception NullPointerExeption if <code>calendar</code> is <code>null</code>.
7989
*/
8090
public JdbcToArrowConfig setCalendar(Calendar calendar) {
@@ -95,6 +105,7 @@ public BaseAllocator getAllocator() {
95105
* Sets the memory allocator to use when construting the Arrow vectors from the ResultSet.
96106
*
97107
* @param allocator the allocator to set.
108+
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
98109
* @exception NullPointerException if <code>allocator</code> is null.
99110
*/
100111
public JdbcToArrowConfig setAllocator(BaseAllocator allocator) {
@@ -103,10 +114,26 @@ public JdbcToArrowConfig setAllocator(BaseAllocator allocator) {
103114
return this;
104115
}
105116

106-
public boolean includeMetadata() {
117+
/**
118+
* Whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
119+
*
120+
* @return <code>true</code> to include field metadata, <code>false</code> to exclude it.
121+
*/
122+
public boolean getIncludeMetadata() {
107123
return includeMetadata;
108124
}
109125

126+
/**
127+
* Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
128+
*
129+
* @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata.
130+
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
131+
*/
132+
public JdbcToArrowConfig setIncludeMetadata(boolean includeMetadata) {
133+
this.includeMetadata = includeMetadata;
134+
return this;
135+
}
136+
110137
/**
111138
* Whether this configuration is valid. The configuration is valid when:
112139
* <ul>

java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig
155155
final FieldType fieldType;
156156

157157
final Map<String, String> metadata;
158-
if (config.includeMetadata()) {
158+
if (config.getIncludeMetadata()) {
159159
metadata = new HashMap<String, String>();
160160
metadata.put(JdbcToArrow.SQL_CATALOG_NAME_KEY, rsmd.getCatalogName(i));
161161
metadata.put(JdbcToArrow.SQL_TABLE_NAME_KEY, rsmd.getTableName(i));

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,24 @@ public void testConfig() {
7575
assertTrue(newAllocator == config.getAllocator());
7676
assertTrue(newCalendar == config.getCalendar());
7777
}
78+
79+
@Test public void testIncludeMetadata() {
80+
JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, calendar);
81+
assertTrue(config.isValid());
82+
assertFalse(config.getIncludeMetadata());
83+
84+
config.setIncludeMetadata(true);
85+
assertTrue(config.getIncludeMetadata());
86+
87+
config.setIncludeMetadata(false);
88+
assertFalse(config.getIncludeMetadata());
89+
90+
config = new JdbcToArrowConfig(allocator, calendar, true);
91+
assertTrue(config.isValid());
92+
assertTrue(config.getIncludeMetadata());
93+
94+
config = new JdbcToArrowConfig(allocator, calendar, false);
95+
assertTrue(config.isValid());
96+
assertFalse(config.getIncludeMetadata());
97+
}
7898
}

0 commit comments

Comments
 (0)