-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Let jdbc-based connectors control how data should be written and predicates pushed down #109
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05b9d83
Rename ReadMapping to ColumnMapping
findepi c3c1738
Add WriteFunction to ColumnMapping
findepi e0e96e5
Add WriteMapping
findepi 8cda0e4
Use WriteFunction to bind data in JdbcPageSink
findepi 58bbfdf
Use WriteFunction to bind parameters in QueryBuilder
findepi 9652894
Allow JDBC connector to control predicate pushdown
findepi b5fa79a
Enable predicate pushdown for decimals
findepi 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BooleanWriteFunction.java
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * Licensed 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 io.prestosql.plugin.jdbc; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
|
|
||
| public interface BooleanWriteFunction | ||
findepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| extends WriteFunction | ||
| { | ||
| @Override | ||
| default Class<?> getJavaType() | ||
| { | ||
| return boolean.class; | ||
| } | ||
|
|
||
| void set(PreparedStatement statement, int index, boolean value) | ||
| throws SQLException; | ||
| } | ||
119 changes: 119 additions & 0 deletions
119
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/ColumnMapping.java
This file contains hidden or 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,119 @@ | ||
| /* | ||
| * Licensed 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 io.prestosql.plugin.jdbc; | ||
|
|
||
| import io.prestosql.spi.predicate.Domain; | ||
| import io.prestosql.spi.type.Type; | ||
|
|
||
| import java.util.function.UnaryOperator; | ||
|
|
||
| import static com.google.common.base.MoreObjects.toStringHelper; | ||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public final class ColumnMapping | ||
| { | ||
| public static ColumnMapping booleanMapping(Type prestoType, BooleanReadFunction readFunction, BooleanWriteFunction writeFunction) | ||
| { | ||
| return booleanMapping(prestoType, readFunction, writeFunction, UnaryOperator.identity()); | ||
| } | ||
|
|
||
| public static ColumnMapping booleanMapping(Type prestoType, BooleanReadFunction readFunction, BooleanWriteFunction writeFunction, UnaryOperator<Domain> pushdownConverter) | ||
| { | ||
| return new ColumnMapping(prestoType, readFunction, writeFunction, pushdownConverter); | ||
| } | ||
|
|
||
| public static ColumnMapping longMapping(Type prestoType, LongReadFunction readFunction, LongWriteFunction writeFunction) | ||
| { | ||
| return longMapping(prestoType, readFunction, writeFunction, UnaryOperator.identity()); | ||
| } | ||
|
|
||
| public static ColumnMapping longMapping(Type prestoType, LongReadFunction readFunction, LongWriteFunction writeFunction, UnaryOperator<Domain> pushdownConverter) | ||
| { | ||
| return new ColumnMapping(prestoType, readFunction, writeFunction, pushdownConverter); | ||
| } | ||
|
|
||
| public static ColumnMapping doubleMapping(Type prestoType, DoubleReadFunction readFunction, DoubleWriteFunction writeFunction) | ||
| { | ||
| return doubleMapping(prestoType, readFunction, writeFunction, UnaryOperator.identity()); | ||
| } | ||
|
|
||
| public static ColumnMapping doubleMapping(Type prestoType, DoubleReadFunction readFunction, DoubleWriteFunction writeFunction, UnaryOperator<Domain> pushdownConverter) | ||
| { | ||
| return new ColumnMapping(prestoType, readFunction, writeFunction, pushdownConverter); | ||
| } | ||
|
|
||
| public static ColumnMapping sliceMapping(Type prestoType, SliceReadFunction readFunction, SliceWriteFunction writeFunction) | ||
| { | ||
| return sliceMapping(prestoType, readFunction, writeFunction, UnaryOperator.identity()); | ||
| } | ||
|
|
||
| public static ColumnMapping sliceMapping(Type prestoType, SliceReadFunction readFunction, SliceWriteFunction writeFunction, UnaryOperator<Domain> pushdownConverter) | ||
| { | ||
| return new ColumnMapping(prestoType, readFunction, writeFunction, pushdownConverter); | ||
| } | ||
|
|
||
| private final Type type; | ||
| private final ReadFunction readFunction; | ||
| private final WriteFunction writeFunction; | ||
| private final UnaryOperator<Domain> pushdownConverter; | ||
|
|
||
| private ColumnMapping(Type type, ReadFunction readFunction, WriteFunction writeFunction, UnaryOperator<Domain> pushdownConverter) | ||
| { | ||
| this.type = requireNonNull(type, "type is null"); | ||
| this.readFunction = requireNonNull(readFunction, "readFunction is null"); | ||
| this.writeFunction = requireNonNull(writeFunction, "writeFunction is null"); | ||
| checkArgument( | ||
| type.getJavaType() == readFunction.getJavaType(), | ||
| "Presto type %s is not compatible with read function %s returning %s", | ||
| type, | ||
| readFunction, | ||
| readFunction.getJavaType()); | ||
| checkArgument( | ||
| type.getJavaType() == writeFunction.getJavaType(), | ||
| "Presto type %s is not compatible with write function %s accepting %s", | ||
| type, | ||
| writeFunction, | ||
| writeFunction.getJavaType()); | ||
| this.pushdownConverter = requireNonNull(pushdownConverter, "pushdownConverter is null"); | ||
| } | ||
|
|
||
| public Type getType() | ||
| { | ||
| return type; | ||
| } | ||
|
|
||
| public ReadFunction getReadFunction() | ||
| { | ||
| return readFunction; | ||
| } | ||
|
|
||
| public WriteFunction getWriteFunction() | ||
| { | ||
| return writeFunction; | ||
| } | ||
|
|
||
| public UnaryOperator<Domain> getPushdownConverter() | ||
| { | ||
| return pushdownConverter; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return toStringHelper(this) | ||
| .add("type", type) | ||
| .toString(); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/DoubleWriteFunction.java
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * Licensed 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 io.prestosql.plugin.jdbc; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
|
|
||
| public interface DoubleWriteFunction | ||
| extends WriteFunction | ||
| { | ||
| @Override | ||
| default Class<?> getJavaType() | ||
| { | ||
| return double.class; | ||
| } | ||
|
|
||
| void set(PreparedStatement statement, int index, double value) | ||
| throws SQLException; | ||
| } |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.