-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Added trino-sybase connector #8488
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c2e5b7c
Added trino-sybase connector
academy-codex 55ff4de
Removing aggregation pushdown impl;
academy-codex 45ba3c7
review comments fixes;
academy-codex 618cce6
removed license
academy-codex 3170f9a
Merge pull request #6 from academy-codex/mr_trino_sybase_connector_fixes
academy-codex aff265a
Update pom.xml
academy-codex 9bfc73a
remove unused method;
academy-codex 49ebdb0
removed unneeded comment;
academy-codex b242817
Merge pull request #7 from academy-codex/mr_trino_sybase_connector_fixes
academy-codex 1ce0844
fix CI; fix query runner;
academy-codex e17e2a3
fix unused varuable TPCH_SCHEMA;
academy-codex 112abf3
Merge pull request #8 from academy-codex/mr_trino_sybase_connector_fixes
academy-codex 38bc78a
dependency fix;
academy-codex 60ef301
Merge pull request #9 from academy-codex/mr_trino_sybase_connector_fixes
academy-codex 785ca7e
dependency fix;
academy-codex 43b10af
Merge pull request #10 from academy-codex/mr_trino_sybase_connector_f…
academy-codex 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-root</artifactId> | ||
<version>360-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>trino-sybase</artifactId> | ||
<description>Trino - Sybase Connector</description> | ||
<packaging>trino-plugin</packaging> | ||
|
||
<properties> | ||
<air.main.basedir>${project.parent.basedir}</air.main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-base-jdbc</artifactId> | ||
</dependency> | ||
|
||
<!-- <dependency>--> | ||
<!-- <groupId>io.trino</groupId>--> | ||
<!-- <artifactId>trino-matching</artifactId>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>configuration</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>log</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>log-manager</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>units</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.sourceforge.jtds</groupId> | ||
<artifactId>jtds</artifactId> | ||
<version>1.3.1</version> | ||
</dependency> | ||
|
||
<!-- <dependency>--> | ||
<!-- <groupId>org.jdbi</groupId>--> | ||
<!-- <artifactId>jdbi3-core</artifactId>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<!-- transitive compile, but used in tests --> | ||
<groupId>net.jodah</groupId> | ||
<artifactId>failsafe</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-spi</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>slice</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openjdk.jol</groupId> | ||
<artifactId>jol-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- for testing --> | ||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-base-jdbc</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-main</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-main</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino</groupId> | ||
<artifactId>trino-tpch</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.trino.tpch</groupId> | ||
<artifactId>tpch</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.airlift</groupId> | ||
<artifactId>testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>jdbc</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>mssqlserver</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
206 changes: 206 additions & 0 deletions
206
plugin/trino-sybase/src/main/java/io/trino/plugin/sybase/SybaseClient.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,206 @@ | ||
/* | ||
* 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.sybase; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.collect.ImmutableSet; | ||
import io.trino.plugin.jdbc.BaseJdbcClient; | ||
import io.trino.plugin.jdbc.BaseJdbcConfig; | ||
import io.trino.plugin.jdbc.ColumnMapping; | ||
import io.trino.plugin.jdbc.ConnectionFactory; | ||
import io.trino.plugin.jdbc.JdbcColumnHandle; | ||
import io.trino.plugin.jdbc.JdbcTableHandle; | ||
import io.trino.plugin.jdbc.JdbcTypeHandle; | ||
import io.trino.plugin.jdbc.WriteMapping; | ||
import io.trino.plugin.jdbc.mapping.IdentifierMapping; | ||
import io.trino.spi.TrinoException; | ||
import io.trino.spi.connector.ConnectorSession; | ||
import io.trino.spi.connector.SchemaTableName; | ||
import io.trino.spi.type.CharType; | ||
import io.trino.spi.type.DecimalType; | ||
import io.trino.spi.type.Type; | ||
import io.trino.spi.type.VarcharType; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.BiFunction; | ||
|
||
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR; | ||
import static io.trino.plugin.jdbc.StandardColumnMappings.booleanWriteFunction; | ||
import static io.trino.plugin.jdbc.StandardColumnMappings.charWriteFunction; | ||
import static io.trino.plugin.jdbc.StandardColumnMappings.varcharWriteFunction; | ||
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED; | ||
import static io.trino.spi.type.BooleanType.BOOLEAN; | ||
import static java.lang.String.format; | ||
import static java.util.Objects.requireNonNull; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
public class SybaseClient | ||
extends BaseJdbcClient | ||
{ | ||
public static final int SYBASE_MAX_LIST_EXPRESSIONS = 500; | ||
|
||
private static final Joiner DOT_JOINER = Joiner.on("."); | ||
|
||
@Inject | ||
public SybaseClient(BaseJdbcConfig config, ConnectionFactory connectionFactory, IdentifierMapping identifierMapping) | ||
{ | ||
super(config, "\"", connectionFactory, identifierMapping); | ||
|
||
requireNonNull(config, "sybaseConfig is null"); | ||
} | ||
|
||
@Override | ||
protected void renameTable(ConnectorSession session, String catalogName, String schemaName, String tableName, SchemaTableName newTable) | ||
{ | ||
if (!schemaName.equals(newTable.getSchemaName())) { | ||
throw new TrinoException(NOT_SUPPORTED, "This connector does not support renaming tables across schemas"); | ||
} | ||
|
||
String sql = format( | ||
"sp_rename %s, %s", | ||
singleQuote(catalogName, schemaName, tableName), | ||
singleQuote(newTable.getTableName())); | ||
execute(session, sql); | ||
} | ||
|
||
@Override | ||
public Collection<String> listSchemas(Connection connection) | ||
{ | ||
try (ResultSet resultSet = connection.getMetaData().getSchemas()) { | ||
ImmutableSet.Builder<String> schemaNames = ImmutableSet.builder(); | ||
while (resultSet.next()) { | ||
String schemaName = resultSet.getString("TABLE_SCHEM"); | ||
// skip internal schemas | ||
if (filterSchema(schemaName)) { | ||
schemaNames.add(schemaName); | ||
} | ||
} | ||
return schemaNames.build(); | ||
} | ||
catch (SQLException e) { | ||
throw new TrinoException(JDBC_ERROR, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void renameColumn(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle jdbcColumn, String newColumnName) | ||
{ | ||
String sql = format( | ||
"sp_rename %s, %s, 'COLUMN'", | ||
singleQuote(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName(), jdbcColumn.getColumnName()), | ||
singleQuote(newColumnName)); | ||
execute(session, sql); | ||
} | ||
|
||
@Override | ||
protected void copyTableSchema(Connection connection, String catalogName, String schemaName, String tableName, String newTableName, List<String> columnNames) | ||
{ | ||
String sql = format( | ||
"SELECT %s INTO %s FROM %s WHERE 0 = 1", | ||
columnNames.stream() | ||
.map(this::quoted) | ||
.collect(joining(", ")), | ||
quoted(catalogName, schemaName, newTableName), | ||
quoted(catalogName, schemaName, tableName)); | ||
execute(connection, sql); | ||
} | ||
|
||
@Override | ||
public boolean schemaExists(ConnectorSession session, String schema) | ||
{ | ||
return super.schemaExists(session, schema); | ||
} | ||
|
||
@Override | ||
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) | ||
{ | ||
return legacyColumnMapping(session, connection, typeHandle); | ||
} | ||
|
||
@Override | ||
public WriteMapping toWriteMapping(ConnectorSession session, Type type) | ||
{ | ||
if (type == BOOLEAN) { | ||
return WriteMapping.booleanMapping("bit", booleanWriteFunction()); | ||
} | ||
|
||
if (type instanceof VarcharType) { | ||
VarcharType varcharType = (VarcharType) type; | ||
String dataType; | ||
if (varcharType.isUnbounded() || varcharType.getBoundedLength() > 4000) { | ||
dataType = "nvarchar(max)"; | ||
} | ||
else { | ||
dataType = "nvarchar(" + varcharType.getBoundedLength() + ")"; | ||
} | ||
return WriteMapping.sliceMapping(dataType, varcharWriteFunction()); | ||
} | ||
|
||
if (type instanceof CharType) { | ||
CharType charType = (CharType) type; | ||
String dataType; | ||
if (charType.getLength() > 4000) { | ||
dataType = "nvarchar(max)"; | ||
} | ||
else { | ||
dataType = "nchar(" + charType.getLength() + ")"; | ||
} | ||
return WriteMapping.sliceMapping(dataType, charWriteFunction()); | ||
} | ||
|
||
return legacyToWriteMapping(session, type); | ||
} | ||
|
||
private static Optional<JdbcTypeHandle> toTypeHandle(DecimalType decimalType) | ||
{ | ||
return Optional.of(new JdbcTypeHandle(Types.NUMERIC, Optional.of("decimal"), Optional.of(decimalType.getPrecision()), Optional.of(decimalType.getScale()), Optional.empty(), Optional.empty())); | ||
} | ||
|
||
@Override | ||
protected Optional<BiFunction<String, Long, String>> limitFunction() | ||
{ | ||
return Optional.of((sql, limit) -> format("SELECT TOP %s * FROM (%s) o", limit, sql)); | ||
} | ||
|
||
@Override | ||
public boolean isLimitGuaranteed(ConnectorSession session) | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public void abortReadConnection(Connection connection) | ||
throws SQLException | ||
{ | ||
connection.close(); | ||
} | ||
|
||
private static String singleQuote(String... objects) | ||
{ | ||
return singleQuote(DOT_JOINER.join(objects)); | ||
} | ||
|
||
private static String singleQuote(String literal) | ||
{ | ||
return "\'" + literal + "\'"; | ||
} | ||
} |
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.
As far as I checked this rename logic locally, this method throws an error. Perhaps, Sybase doesn't allow passing catalog nor schema names in this procedure?
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36273.1572/html/sprocs/X37949.htm
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.
let me check on this..