-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-3965 [Java] JDBC-To-Arrow Configuration #3133
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
da77cbe
Creating a configuration class for the JDBC-to-Arrow converter.
b270044
Updated validaton & documentation, and unit tests for the new JdbcToA…
df632e3
Updating the SQL tests to include JdbcToArrowConfig versions.
4f1260c
Adding documentation for public static VectorSchemaRoot sqlToArrow(Re…
8d6cf00
Documentation for public static VectorSchemaRoot sqlToArrow(Connectio…
68c91e7
Modifying the jdbcToArrowSchema and jdbcToArrowVectors methods to rec…
bb3165b
Updating the function calls to use the JdbcToArrowConfig versions.
881c6c8
Merge pull request #1 from apache/master
mikepigott 5b1b364
Merge branch 'master' into jdbc-to-arrow-config
3b17c29
Merge pull request #2 from apache/master
mikepigott e5b19ee
Merge pull request #3 from apache/master
mikepigott 789c8c8
Merge pull request #4 from apache/master
mikepigott d7ca982
Merge branch 'master' into jdbc-to-arrow-config
d6c64a7
ARROW-3965: JdbcToArrowConfigBuilder
be95426
ARROW-3965: JDBC-To-Arrow Config Builder javadocs.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)