You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/01/30 14:01:49 UTC
[arrow] branch master updated: ARROW-3965 [Java] JDBC-To-Arrow
Configuration
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 8e19532 ARROW-3965 [Java] JDBC-To-Arrow Configuration
8e19532 is described below
commit 8e195327149b670de2cd7a8cfe75bbd6f71c6b49
Author: Mike Pigott <mp...@gmail.com>
AuthorDate: Wed Jan 30 08:01:42 2019 -0600
ARROW-3965 [Java] JDBC-To-Arrow Configuration
https://issues.apache.org/jira/browse/ARROW-3965
This creates an object which configures the BaseAllocator and Calendar used during to configure the translation from a JDBC ResultSet to an Arrow vector.
Author: Mike Pigott <mp...@gmail.com>
Author: Michael Pigott <mi...@users.noreply.github.com>
Closes #3133 from mikepigott/jdbc-to-arrow-config and squashes the following commits:
be9542686 <Mike Pigott> ARROW-3965: JDBC-To-Arrow Config Builder javadocs.
d6c64a775 <Mike Pigott> ARROW-3965: JdbcToArrowConfigBuilder
d7ca982f9 <Mike Pigott> Merge branch 'master' into jdbc-to-arrow-config
789c8c84d <Michael Pigott> Merge pull request #4 from apache/master
e5b19eeeb <Michael Pigott> Merge pull request #3 from apache/master
3b17c2976 <Michael Pigott> Merge pull request #2 from apache/master
5b1b364dd <Mike Pigott> Merge branch 'master' into jdbc-to-arrow-config
881c6c83e <Michael Pigott> Merge pull request #1 from apache/master
bb3165b93 <Mike Pigott> Updating the function calls to use the JdbcToArrowConfig versions.
68c91e7a7 <Mike Pigott> Modifying the jdbcToArrowSchema and jdbcToArrowVectors methods to receive JdbcToArrowConfig objects.
8d6cf0089 <Mike Pigott> Documentation for public static VectorSchemaRoot sqlToArrow(Connection connection, String query, JdbcToArrowConfig config)
4f1260ce9 <Mike Pigott> Adding documentation for public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, JdbcToArrowConfig config)
df632e36d <Mike Pigott> Updating the SQL tests to include JdbcToArrowConfig versions.
b2700448d <Mike Pigott> Updated validaton & documentation, and unit tests for the new JdbcToArrowConfig.
da77cbe8c <Mike Pigott> Creating a configuration class for the JDBC-to-Arrow converter.
---
.../org/apache/arrow/adapter/jdbc/JdbcToArrow.java | 56 +++++++++--
.../arrow/adapter/jdbc/JdbcToArrowConfig.java | 73 +++++++++++++++
.../adapter/jdbc/JdbcToArrowConfigBuilder.java | 103 +++++++++++++++++++++
.../arrow/adapter/jdbc/JdbcToArrowUtils.java | 58 +++++++++---
.../adapter/jdbc/AbstractJdbcToArrowTest.java | 4 +-
.../arrow/adapter/jdbc/JdbcToArrowConfigTest.java | 94 +++++++++++++++++++
.../adapter/jdbc/h2/JdbcToArrowCharSetTest.java | 8 ++
.../adapter/jdbc/h2/JdbcToArrowDataTypesTest.java | 8 ++
.../arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java | 8 ++
.../arrow/adapter/jdbc/h2/JdbcToArrowTest.java | 8 ++
.../adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java | 12 +++
11 files changed, 410 insertions(+), 22 deletions(-)
diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java
index 14e4368..fd32036 100644
--- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java
+++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrow.java
@@ -89,7 +89,9 @@ public class JdbcToArrow {
Preconditions.checkArgument(query != null && query.length() > 0, "SQL query can not be null or empty");
Preconditions.checkNotNull(allocator, "Memory allocator object can not be null");
- return sqlToArrow(connection, query, allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT));
+ JdbcToArrowConfig config =
+ new JdbcToArrowConfig(allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT));
+ return sqlToArrow(connection, query, config);
}
/**
@@ -115,8 +117,29 @@ public class JdbcToArrow {
Preconditions.checkNotNull(allocator, "Memory allocator object can not be null");
Preconditions.checkNotNull(calendar, "Calendar object can not be null");
+ return sqlToArrow(connection, query, new JdbcToArrowConfig(allocator, calendar));
+ }
+
+ /**
+ * For the given SQL query, execute and fetch the data from Relational DB and convert it to Arrow objects.
+ *
+ * @param connection Database connection to be used. This method will not close the passed connection object.
+ * Since the caller has passed the connection object it's the responsibility of the caller
+ * to close or return the connection to the pool.
+ * @param query The DB Query to fetch the data.
+ * @param config Configuration
+ * @return Arrow Data Objects {@link VectorSchemaRoot}
+ * @throws SQLException Propagate any SQL Exceptions to the caller after closing any resources opened such as
+ * ResultSet and Statement objects.
+ */
+ public static VectorSchemaRoot sqlToArrow(Connection connection, String query, JdbcToArrowConfig config)
+ throws SQLException, IOException {
+ Preconditions.checkNotNull(connection, "JDBC connection object can not be null");
+ Preconditions.checkArgument(query != null && query.length() > 0, "SQL query can not be null or empty");
+ Preconditions.checkNotNull(config, "The configuration cannot be null");
+
try (Statement stmt = connection.createStatement()) {
- return sqlToArrow(stmt.executeQuery(query), allocator, calendar);
+ return sqlToArrow(stmt.executeQuery(query), config);
}
}
@@ -147,7 +170,9 @@ public class JdbcToArrow {
Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not be null");
Preconditions.checkNotNull(allocator, "Memory Allocator object can not be null");
- return sqlToArrow(resultSet, allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT));
+ JdbcToArrowConfig config =
+ new JdbcToArrowConfig(allocator, Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT));
+ return sqlToArrow(resultSet, config);
}
/**
@@ -162,10 +187,7 @@ public class JdbcToArrow {
Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not be null");
Preconditions.checkNotNull(calendar, "Calendar object can not be null");
- RootAllocator rootAllocator = new RootAllocator(Integer.MAX_VALUE);
- VectorSchemaRoot root = sqlToArrow(resultSet, rootAllocator, calendar);
-
- return root;
+ return sqlToArrow(resultSet, new JdbcToArrowConfig(new RootAllocator(Integer.MAX_VALUE), calendar));
}
/**
@@ -183,9 +205,25 @@ public class JdbcToArrow {
Preconditions.checkNotNull(allocator, "Memory Allocator object can not be null");
Preconditions.checkNotNull(calendar, "Calendar object can not be null");
+ return sqlToArrow(resultSet, new JdbcToArrowConfig(allocator, calendar));
+ }
+
+ /**
+ * For the given JDBC {@link ResultSet}, fetch the data from Relational DB and convert it to Arrow objects.
+ *
+ * @param resultSet ResultSet to use to fetch the data from underlying database
+ * @param config Configuration of the conversion from JDBC to Arrow.
+ * @return Arrow Data Objects {@link VectorSchemaRoot}
+ * @throws SQLException on error
+ */
+ public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, JdbcToArrowConfig config)
+ throws SQLException, IOException {
+ Preconditions.checkNotNull(resultSet, "JDBC ResultSet object can not be null");
+ Preconditions.checkNotNull(config, "The configuration cannot be null");
+
VectorSchemaRoot root = VectorSchemaRoot.create(
- JdbcToArrowUtils.jdbcToArrowSchema(resultSet.getMetaData(), calendar), allocator);
- JdbcToArrowUtils.jdbcToArrowVectors(resultSet, root, calendar);
+ JdbcToArrowUtils.jdbcToArrowSchema(resultSet.getMetaData(), config), config.getAllocator());
+ JdbcToArrowUtils.jdbcToArrowVectors(resultSet, root, config);
return root;
}
}
diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java
new file mode 100644
index 0000000..59813a8
--- /dev/null
+++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.adapter.jdbc;
+
+import java.util.Calendar;
+
+import org.apache.arrow.memory.BaseAllocator;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * This class configures the JDBC-to-Arrow conversion process.
+ * <p>
+ * The allocator is used to construct the {@link org.apache.arrow.vector.VectorSchemaRoot},
+ * and the calendar is used to define the time zone of any {@link org.apahe.arrow.vector.pojo.ArrowType.Timestamp}
+ * fields that are created during the conversion.
+ * </p>
+ * <p>
+ * Neither field may be <code>null</code>.
+ * </p>
+ */
+public final class JdbcToArrowConfig {
+ private Calendar calendar;
+ private BaseAllocator allocator;
+
+ /**
+ * 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.
+ */
+ 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.
+ * @return the calendar.
+ */
+ public Calendar getCalendar() {
+ return calendar;
+ }
+
+ /**
+ * The Arrow memory allocator.
+ * @return the allocator.
+ */
+ public BaseAllocator getAllocator() {
+ return allocator;
+ }
+}
diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java
new file mode 100644
index 0000000..df97c3a
--- /dev/null
+++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.adapter.jdbc;
+
+import java.util.Calendar;
+
+import org.apache.arrow.memory.BaseAllocator;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * This class builds {@link JdbcToArrowConfig}s.
+ */
+public class JdbcToArrowConfigBuilder {
+ private Calendar calendar;
+ private BaseAllocator allocator;
+
+ /**
+ * Default constructor for the <code>JdbcToArrowConfigBuilder}</code>.
+ * Use the setter methods for the allocator and calendar; both must be
+ * set. Otherwise, {@link #build()} will throw a {@link NullPointerException}.
+ */
+ public JdbcToArrowConfigBuilder() {
+ this.allocator = null;
+ this.calendar = null;
+ }
+
+ /**
+ * 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>.
+ * <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>
+ *
+ * @param allocator The Arrow Vector memory allocator.
+ * @param calendar The calendar to use when constructing timestamp fields.
+ */
+ 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;
+ }
+
+ /**
+ * Sets the memory allocator to use when constructing the Arrow vectors from the ResultSet.
+ *
+ * @param allocator the allocator to set.
+ * @exception NullPointerException if <code>allocator</code> is null.
+ */
+ public JdbcToArrowConfigBuilder setAllocator(BaseAllocator allocator) {
+ Preconditions.checkNotNull(allocator, "Memory allocator cannot be null");
+ this.allocator = allocator;
+ return this;
+ }
+
+ /**
+ * Sets the {@link Calendar} to use when constructing timestamp fields in the
+ * 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;
+ }
+
+ /**
+ * This builds the {@link JdbcToArrowConfig} from the provided
+ * {@link BaseAllocator} and {@link Calendar}.
+ *
+ * @return The built {@link JdbcToArrowConfig}
+ * @throws NullPointerException if either the allocator or calendar was not set.
+ */
+ public JdbcToArrowConfig build() {
+ return new JdbcToArrowConfig(allocator, calendar);
+ }
+}
diff --git a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java
index 3425fa6..d48cfe2 100644
--- a/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java
+++ b/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowUtils.java
@@ -38,6 +38,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BaseFixedWidthVector;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.BitVector;
@@ -93,6 +94,21 @@ public class JdbcToArrowUtils {
/**
* Create Arrow {@link Schema} object for the given JDBC {@link ResultSetMetaData}.
*
+ * @param rsmd The ResultSetMetaData containing the results, to read the JDBC metadata from.
+ * @param calendar The calendar to use the time zone field of, to construct Timestamp fields from.
+ * @return {@link Schema}
+ * @throws SQLException on error
+ */
+ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) throws SQLException {
+ Preconditions.checkNotNull(rsmd, "JDBC ResultSetMetaData object can't be null");
+ Preconditions.checkNotNull(calendar, "Calendar object can't be null");
+
+ return jdbcToArrowSchema(rsmd, new JdbcToArrowConfig(new RootAllocator(0), calendar));
+ }
+
+ /**
+ * Create Arrow {@link Schema} object for the given JDBC {@link ResultSetMetaData}.
+ *
* <p>This method currently performs following type mapping for JDBC SQL data types to corresponding Arrow data types.
*
* <p>CHAR --> ArrowType.Utf8
@@ -120,14 +136,14 @@ public class JdbcToArrowUtils {
* CLOB --> ArrowType.Utf8
* BLOB --> ArrowType.Binary
*
- * @param rsmd ResultSetMetaData
+ * @param rsmd The ResultSetMetaData containing the results, to read the JDBC metadata from.
+ * @param config The configuration to use when constructing the schema.
* @return {@link Schema}
* @throws SQLException on error
*/
- public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, Calendar calendar) throws SQLException {
-
+ public static Schema jdbcToArrowSchema(ResultSetMetaData rsmd, JdbcToArrowConfig config) throws SQLException {
Preconditions.checkNotNull(rsmd, "JDBC ResultSetMetaData object can't be null");
- Preconditions.checkNotNull(calendar, "Calendar object can't be null");
+ Preconditions.checkNotNull(config, "The configuration object must not be null");
List<Field> fields = new ArrayList<>();
int columnCount = rsmd.getColumnCount();
@@ -179,7 +195,7 @@ public class JdbcToArrowUtils {
break;
case Types.TIMESTAMP:
fields.add(new Field(columnName, FieldType.nullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND,
- calendar.getTimeZone().getID())), null));
+ config.getCalendar().getTimeZone().getID())), null));
break;
case Types.BINARY:
case Types.VARBINARY:
@@ -222,17 +238,37 @@ public class JdbcToArrowUtils {
* Iterate the given JDBC {@link ResultSet} object to fetch the data and transpose it to populate
* the given Arrow Vector objects.
*
- * @param rs ResultSet to use to fetch the data from underlying database
- * @param root Arrow {@link VectorSchemaRoot} object to populate
+ * @param rs ResultSet to use to fetch the data from underlying database
+ * @param root Arrow {@link VectorSchemaRoot} object to populate
+ * @param calendar The calendar to use when reading time-based data.
* @throws SQLException on error
*/
public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, Calendar calendar)
throws SQLException, IOException {
Preconditions.checkNotNull(rs, "JDBC ResultSet object can't be null");
- Preconditions.checkNotNull(root, "JDBC ResultSet object can't be null");
+ Preconditions.checkNotNull(root, "Vector Schema cannot be null");
Preconditions.checkNotNull(calendar, "Calendar object can't be null");
+ jdbcToArrowVectors(rs, root, new JdbcToArrowConfig(new RootAllocator(0), calendar));
+ }
+
+ /**
+ * Iterate the given JDBC {@link ResultSet} object to fetch the data and transpose it to populate
+ * the given Arrow Vector objects.
+ *
+ * @param rs ResultSet to use to fetch the data from underlying database
+ * @param root Arrow {@link VectorSchemaRoot} object to populate
+ * @param config The configuration to use when reading the data.
+ * @throws SQLException on error
+ */
+ public static void jdbcToArrowVectors(ResultSet rs, VectorSchemaRoot root, JdbcToArrowConfig config)
+ throws SQLException, IOException {
+
+ Preconditions.checkNotNull(rs, "JDBC ResultSet object can't be null");
+ Preconditions.checkNotNull(root, "JDBC ResultSet object can't be null");
+ Preconditions.checkNotNull(config, "JDBC-to-Arrow configuration cannot be null");
+
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
@@ -289,16 +325,16 @@ public class JdbcToArrowUtils {
break;
case Types.DATE:
updateVector((DateMilliVector) root.getVector(columnName),
- rs.getDate(i, calendar), !rs.wasNull(), rowCount);
+ rs.getDate(i, config.getCalendar()), !rs.wasNull(), rowCount);
break;
case Types.TIME:
updateVector((TimeMilliVector) root.getVector(columnName),
- rs.getTime(i, calendar), !rs.wasNull(), rowCount);
+ rs.getTime(i, config.getCalendar()), !rs.wasNull(), rowCount);
break;
case Types.TIMESTAMP:
// TODO: Need to handle precision such as milli, micro, nano
updateVector((TimeStampVector) root.getVector(columnName),
- rs.getTimestamp(i, calendar), !rs.wasNull(), rowCount);
+ rs.getTimestamp(i, config.getCalendar()), !rs.wasNull(), rowCount);
break;
case Types.BINARY:
case Types.VARBINARY:
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java
index a147bab..b1a9329 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/AbstractJdbcToArrowTest.java
@@ -45,7 +45,7 @@ public abstract class AbstractJdbcToArrowTest {
* @return Table object
* @throws IOException on error
*/
- protected static Table getTable(String ymlFilePath, Class clss) throws IOException {
+ protected static Table getTable(String ymlFilePath, @SuppressWarnings("rawtypes") Class clss) throws IOException {
return new ObjectMapper(new YAMLFactory()).readValue(
clss.getClassLoader().getResourceAsStream(ymlFilePath), Table.class);
}
@@ -94,7 +94,7 @@ public abstract class AbstractJdbcToArrowTest {
* @throws ClassNotFoundException on error
* @throws IOException on error
*/
- public static Object[][] prepareTestData(String[] testFiles, Class clss)
+ public static Object[][] prepareTestData(String[] testFiles, @SuppressWarnings("rawtypes") Class clss)
throws SQLException, ClassNotFoundException, IOException {
Object[][] tableArr = new Object[testFiles.length][];
int i = 0;
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java
new file mode 100644
index 0000000..b4f92fa
--- /dev/null
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.adapter.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.arrow.memory.BaseAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.junit.Test;
+
+public class JdbcToArrowConfigTest {
+
+ private static final RootAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
+ private static final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
+
+ @Test(expected = NullPointerException.class)
+ public void testConfigNullArguments() {
+ new JdbcToArrowConfig(null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBuilderNullArguments() {
+ new JdbcToArrowConfigBuilder(null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConfigNullCalendar() {
+ new JdbcToArrowConfig(allocator, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBuilderNullCalendar() {
+ new JdbcToArrowConfigBuilder(allocator, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConfigNullAllocator() {
+ new JdbcToArrowConfig(null, calendar);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testBuilderNullAllocator() {
+ new JdbcToArrowConfigBuilder(null, calendar);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSetNullAllocator() {
+ JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar);
+ builder.setAllocator(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSetNullCalendar() {
+ JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar);
+ builder.setCalendar(null);
+ }
+
+ @Test
+ public void testConfig() {
+ JdbcToArrowConfigBuilder builder = new JdbcToArrowConfigBuilder(allocator, calendar);
+ JdbcToArrowConfig config = builder.build();
+
+ assertTrue(allocator == config.getAllocator());
+ assertTrue(calendar == config.getCalendar());
+
+ Calendar newCalendar = Calendar.getInstance();
+ BaseAllocator newAllocator = new RootAllocator(Integer.SIZE);
+
+ builder.setAllocator(newAllocator).setCalendar(newCalendar);
+ config = builder.build();
+
+ assertTrue(newAllocator == config.getAllocator());
+ assertTrue(newCalendar == config.getCalendar());
+ }
+}
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java
index c7dff43..d33c07a 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowCharSetTest.java
@@ -31,6 +31,7 @@ import java.util.Collection;
import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.VarCharVector;
@@ -116,6 +117,13 @@ public class JdbcToArrowCharSetTest extends AbstractJdbcToArrowTest {
new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()),
Calendar.getInstance()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn.createStatement().executeQuery(table.getQuery()),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn,
+ table.getQuery(),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
}
/**
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java
index f6cd764..5bdb38f 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowDataTypesTest.java
@@ -40,6 +40,7 @@ import java.util.Collection;
import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BigIntVector;
@@ -142,6 +143,13 @@ public class JdbcToArrowDataTypesTest extends AbstractJdbcToArrowTest {
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()),
new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn.createStatement().executeQuery(table.getQuery()),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn,
+ table.getQuery(),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
}
/**
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java
index 7933732..629bcfe 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowNullTest.java
@@ -27,6 +27,7 @@ import java.util.Collection;
import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BigIntVector;
@@ -99,6 +100,13 @@ public class JdbcToArrowNullTest extends AbstractJdbcToArrowTest {
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()),
new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()), Calendar.getInstance()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn.createStatement().executeQuery(table.getQuery()),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn,
+ table.getQuery(),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
}
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java
index 4cbfeaf..f74e683 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTest.java
@@ -48,6 +48,7 @@ import java.util.Collection;
import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BigIntVector;
@@ -133,6 +134,13 @@ public class JdbcToArrowTest extends AbstractJdbcToArrowTest {
new RootAllocator(Integer.MAX_VALUE)));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()),
Calendar.getInstance()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn.createStatement().executeQuery(table.getQuery()),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn,
+ table.getQuery(),
+ new JdbcToArrowConfigBuilder(new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance()).build()));
}
/**
diff --git a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java
index 93dc104..fee56c7 100644
--- a/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java
+++ b/java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/h2/JdbcToArrowTimeZoneTest.java
@@ -30,6 +30,7 @@ import java.util.TimeZone;
import org.apache.arrow.adapter.jdbc.AbstractJdbcToArrowTest;
import org.apache.arrow.adapter.jdbc.JdbcToArrow;
+import org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder;
import org.apache.arrow.adapter.jdbc.Table;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.DateMilliVector;
@@ -105,6 +106,17 @@ public class JdbcToArrowTimeZoneTest extends AbstractJdbcToArrowTest {
new RootAllocator(Integer.MAX_VALUE), Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))));
testDataSets(JdbcToArrow.sqlToArrow(conn.createStatement().executeQuery(table.getQuery()),
Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn.createStatement().executeQuery(table.getQuery()),
+ new JdbcToArrowConfigBuilder(
+ new RootAllocator(Integer.MAX_VALUE),
+ Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))).build()));
+ testDataSets(JdbcToArrow.sqlToArrow(
+ conn,
+ table.getQuery(),
+ new JdbcToArrowConfigBuilder(
+ new RootAllocator(Integer.MAX_VALUE),
+ Calendar.getInstance(TimeZone.getTimeZone(table.getTimezone()))).build()));
}
/**