Skip to content

Commit 2928513

Browse files
author
Mike Pigott
committed
ARROW-3966: Moving the metadata flag assignment into the builder.
1 parent 69022c2 commit 2928513

File tree

8 files changed

+52
-26
lines changed

8 files changed

+52
-26
lines changed

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

-11
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,4 @@ public BaseAllocator getAllocator() {
8282
public boolean getIncludeMetadata() {
8383
return includeMetadata;
8484
}
85-
86-
/**
87-
* Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
88-
*
89-
* @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata.
90-
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
91-
*/
92-
public JdbcToArrowConfig setIncludeMetadata(boolean includeMetadata) {
93-
this.includeMetadata = includeMetadata;
94-
return this;
95-
}
9685
}

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

+40-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
public class JdbcToArrowConfigBuilder {
3030
private Calendar calendar;
3131
private BaseAllocator allocator;
32+
private boolean includeMetadata;
3233

3334
/**
3435
* Default constructor for the <code>JdbcToArrowConfigBuilder}</code>.
@@ -38,6 +39,7 @@ public class JdbcToArrowConfigBuilder {
3839
public JdbcToArrowConfigBuilder() {
3940
this.allocator = null;
4041
this.calendar = null;
42+
this.includeMetadata = false;
4143
}
4244

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

6466
this.allocator = allocator;
6567
this.calendar = calendar;
68+
this.includeMetadata = false;
69+
}
70+
71+
/**
72+
* Constructor for the <code>JdbcToArrowConfigBuilder</code>. Both the
73+
* allocator and calendar are required. A {@link NullPointerException}
74+
* will be thrown if either of those arguments is <code>null</code>.
75+
* <p>
76+
* The allocator is used to construct Arrow vectors from the JDBC ResultSet.
77+
* The calendar is used to determine the time zone of {@link java.sql.Timestamp}
78+
* fields and convert {@link java.sql.Date}, {@link java.sql.Time}, and
79+
* {@link java.sql.Timestamp} fields to a single, common time zone when reading
80+
* from the result set.
81+
* </p>
82+
* <p>
83+
* The <code>includeMetadata</code> argument, if <code>true</code> will cause
84+
* various information about each database field to be added to the Vector
85+
* Schema's field metadata.
86+
* </p>
87+
*
88+
* @param allocator The Arrow Vector memory allocator.
89+
* @param calendar The calendar to use when constructing timestamp fields.
90+
*/
91+
public JdbcToArrowConfigBuilder(BaseAllocator allocator, Calendar calendar, boolean includeMetadata) {
92+
this(allocator, calendar);
93+
this.includeMetadata = includeMetadata;
6694
}
6795

6896
/**
@@ -90,6 +118,17 @@ public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) {
90118
return this;
91119
}
92120

121+
/**
122+
* Sets whether to include JDBC ResultSet field metadata in the Arrow Schema field metadata.
123+
*
124+
* @param includeMetadata Whether to include or exclude JDBC metadata in the Arrow Schema field metadata.
125+
* @return This instance of the <code>JdbcToArrowConfig</code>, for chaining.
126+
*/
127+
public JdbcToArrowConfigBuilder setIncludeMetadata(boolean includeMetadata) {
128+
this.includeMetadata = includeMetadata;
129+
return this;
130+
}
131+
93132
/**
94133
* This builds the {@link JdbcToArrowConfig} from the provided
95134
* {@link BaseAllocator} and {@link Calendar}.
@@ -98,6 +137,6 @@ public JdbcToArrowConfigBuilder setCalendar(Calendar calendar) {
98137
* @throws NullPointerException if either the allocator or calendar was not set.
99138
*/
100139
public JdbcToArrowConfig build() {
101-
return new JdbcToArrowConfig(allocator, calendar, false);
140+
return new JdbcToArrowConfig(allocator, calendar, includeMetadata);
102141
}
103142
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ public void testConfig() {
9393
}
9494

9595
@Test public void testIncludeMetadata() {
96-
JdbcToArrowConfig config = new JdbcToArrowConfig(allocator, calendar, false);
96+
JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar, false);
97+
98+
JdbcToArrowConfig config = builder.build();
9799
assertFalse(config.getIncludeMetadata());
98100

99-
config.setIncludeMetadata(true);
101+
builder.setIncludeMetadata(true);
102+
config = builder.build();
100103
assertTrue(config.getIncludeMetadata());
101104

102-
config.setIncludeMetadata(false);
103-
assertFalse(config.getIncludeMetadata());
105+
config = new JdbcToArrowConfigBuilder(allocator, calendar, true).build();
106+
assertTrue(config.getIncludeMetadata());
104107

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

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
133133

134134
@Test
135135
public void testJdbcSchemaMetadata() throws SQLException {
136-
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
137-
config.setIncludeMetadata(true);
136+
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
138137
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
139138
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
140139
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
159159

160160
@Test
161161
public void testJdbcSchemaMetadata() throws SQLException {
162-
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
163-
config.setIncludeMetadata(true);
162+
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
164163
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
165164
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
166165
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
116116

117117
@Test
118118
public void testJdbcSchemaMetadata() throws SQLException {
119-
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
120-
config.setIncludeMetadata(true);
119+
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
121120
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
122121
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
123122
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
150150

151151
@Test
152152
public void testJdbcSchemaMetadata() throws SQLException {
153-
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance()).build();
154-
config.setIncludeMetadata(true);
153+
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), Calendar.getInstance(), true).build();
155154
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
156155
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
157156
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);

java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ public void testJdbcToArroValues() throws SQLException, IOException {
127127
@Test
128128
public void testJdbcSchemaMetadata() throws SQLException {
129129
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()));
130-
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar).build();
131-
config.setIncludeMetadata(true);
130+
JdbcToArrowConfig config = new JdbcToArrowConfigBuilder(new RootAllocator(0), calendar, true).build();
132131
ResultSetMetaData rsmd = conn.createStatement().executeQuery(table.getQuery()).getMetaData();
133132
Schema schema = JdbcToArrowUtils.jdbcToArrowSchema(rsmd, config);
134133
JdbcToArrowTestHelper.assertFieldMetadataMatchesResultSetMetadata(rsmd, schema);

0 commit comments

Comments
 (0)