forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Author: Michael Pigott <[email protected]> Closes apache#3133 from mikepigott/jdbc-to-arrow-config and squashes the following commits: be95426 <Mike Pigott> ARROW-3965: JDBC-To-Arrow Config Builder javadocs. d6c64a7 <Mike Pigott> ARROW-3965: JdbcToArrowConfigBuilder d7ca982 <Mike Pigott> Merge branch 'master' into jdbc-to-arrow-config 789c8c8 <Michael Pigott> Merge pull request #4 from apache/master e5b19ee <Michael Pigott> Merge pull request #3 from apache/master 3b17c29 <Michael Pigott> Merge pull request #2 from apache/master 5b1b364 <Mike Pigott> Merge branch 'master' into jdbc-to-arrow-config 881c6c8 <Michael Pigott> Merge pull request #1 from apache/master bb3165b <Mike Pigott> Updating the function calls to use the JdbcToArrowConfig versions. 68c91e7 <Mike Pigott> Modifying the jdbcToArrowSchema and jdbcToArrowVectors methods to receive JdbcToArrowConfig objects. 8d6cf00 <Mike Pigott> Documentation for public static VectorSchemaRoot sqlToArrow(Connection connection, String query, JdbcToArrowConfig config) 4f1260c <Mike Pigott> Adding documentation for public static VectorSchemaRoot sqlToArrow(ResultSet resultSet, JdbcToArrowConfig config) df632e3 <Mike Pigott> Updating the SQL tests to include JdbcToArrowConfig versions. b270044 <Mike Pigott> Updated validaton & documentation, and unit tests for the new JdbcToArrowConfig. da77cbe <Mike Pigott> Creating a configuration class for the JDBC-to-Arrow converter.
- Loading branch information
Showing
11 changed files
with
410 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/JdbcToArrowConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.