-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Simplify transactions in JdbcPageSink #7875
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
5 commits
Select commit
Hold shift + click to select a range
0602a9e
Document why disable auto-commit in read-only transaction
findepi 7332cb9
Use Phoenix driver explicitly
findepi 6d0122c
Workaround implicit transactions when using Phoenix JDBC
findepi 8076017
Workaround broken auto-commit reporting in ClickHouse JDBC
findepi 2011c8d
Simplify transactions in JdbcPageSink
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
64 changes: 64 additions & 0 deletions
64
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/ConfiguringConnectionFactory.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,64 @@ | ||
| /* | ||
| * 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.trino.plugin.jdbc; | ||
|
|
||
| import io.trino.spi.connector.ConnectorSession; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public final class ConfiguringConnectionFactory | ||
| implements ConnectionFactory | ||
| { | ||
| private final ConnectionFactory delegate; | ||
| private final Configurator configurator; | ||
|
|
||
| public ConfiguringConnectionFactory(ConnectionFactory delegate, Configurator configurator) | ||
| { | ||
| this.delegate = requireNonNull(delegate, "delegate is null"); | ||
| this.configurator = requireNonNull(configurator, "configurator is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public Connection openConnection(ConnectorSession session) | ||
| throws SQLException | ||
| { | ||
| Connection connection = delegate.openConnection(session); | ||
| try { | ||
| configurator.configure(connection); | ||
| } | ||
| catch (SQLException | RuntimeException e) { | ||
| try (connection) { | ||
| throw e; | ||
| } | ||
| } | ||
| return connection; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() | ||
| throws SQLException | ||
| { | ||
| delegate.close(); | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| public interface Configurator | ||
| { | ||
| void configure(Connection connection) | ||
| 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
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
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
72 changes: 72 additions & 0 deletions
72
...rino-clickhouse/src/main/java/io/trino/plugin/clickhouse/ClickHouseConnectionFactory.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,72 @@ | ||
| /* | ||
| * 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.trino.plugin.clickhouse; | ||
|
|
||
| import io.trino.plugin.jdbc.ConnectionFactory; | ||
| import io.trino.plugin.jdbc.ForwardingConnection; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
|
|
||
| import javax.annotation.PreDestroy; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| import static com.google.common.base.Verify.verify; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class ClickHouseConnectionFactory | ||
| implements ConnectionFactory | ||
| { | ||
| private final ConnectionFactory delegate; | ||
|
|
||
| public ClickHouseConnectionFactory(ConnectionFactory delegate) | ||
| { | ||
| this.delegate = requireNonNull(delegate, "delegate is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public Connection openConnection(ConnectorSession session) | ||
| throws SQLException | ||
| { | ||
| return new ForwardingConnection() | ||
| { | ||
| private final Connection delegate = ClickHouseConnectionFactory.this.delegate.openConnection(session); | ||
|
|
||
| @Override | ||
| protected Connection getDelegate() | ||
| { | ||
| return delegate; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean getAutoCommit() | ||
| throws SQLException | ||
| { | ||
| // ClickHouse's Connection (ru.yandex.clickhouse.ClickHouseConnectionImpl) ignores setAutoCommit, commit and rollback, | ||
| // but still returns false from getAutoCommit(). | ||
| // TODO once https://github.com/ClickHouse/clickhouse-jdbc/issues/657 is solved, remove the workaround. | ||
| verify(!delegate.getAutoCommit(), "ClickHouse connection declared auto-commit mode, the code needs update"); | ||
| return true; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| @PreDestroy | ||
| public void close() | ||
| throws SQLException | ||
| { | ||
| delegate.close(); | ||
| } | ||
| } |
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
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
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
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
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.