-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Feature][Connector-V2][Teradata] Add Teradata Source And Sink Connector #3362
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
47 changes: 47 additions & 0 deletions
47
...apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/teradata/TeradataDialect.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,47 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.internal.dialect.teradata; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper; | ||
|
||
import java.util.Optional; | ||
|
||
public class TeradataDialect implements JdbcDialect { | ||
|
||
@Override | ||
public String dialectName() { | ||
return "Teradata"; | ||
} | ||
|
||
@Override | ||
public JdbcRowConverter getRowConverter() { | ||
return new TeradataJdbcRowConverter(); | ||
} | ||
|
||
@Override | ||
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() { | ||
return new TeradataTypeMapper(); | ||
} | ||
|
||
@Override | ||
public Optional<String> getUpsertStatement(String tableName, String[] fieldNames, String[] uniqueKeyFields) { | ||
return Optional.empty(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...seatunnel/connectors/seatunnel/jdbc/internal/dialect/teradata/TeradataDialectFactory.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,37 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.internal.dialect.teradata; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
@AutoService(JdbcDialectFactory.class) | ||
public class TeradataDialectFactory implements JdbcDialectFactory { | ||
|
||
@Override | ||
public boolean acceptsURL(String url) { | ||
return url.startsWith("jdbc:teradata:"); | ||
} | ||
|
||
@Override | ||
public JdbcDialect create() { | ||
return new TeradataDialect(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...atunnel/connectors/seatunnel/jdbc/internal/dialect/teradata/TeradataJdbcRowConverter.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,29 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.internal.dialect.teradata; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; | ||
|
||
public class TeradataJdbcRowConverter extends AbstractJdbcRowConverter { | ||
|
||
@Override | ||
public String converterName() { | ||
return "Teradata"; | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...che/seatunnel/connectors/seatunnel/jdbc/internal/dialect/teradata/TeradataTypeMapper.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,98 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc.internal.dialect.teradata; | ||
|
||
import org.apache.seatunnel.api.table.type.BasicType; | ||
import org.apache.seatunnel.api.table.type.DecimalType; | ||
import org.apache.seatunnel.api.table.type.LocalTimeType; | ||
import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelDataType; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper; | ||
|
||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
|
||
public class TeradataTypeMapper implements JdbcDialectTypeMapper { | ||
|
||
// ============================data types===================== | ||
|
||
// -------------------------number---------------------------- | ||
private static final String TERADATA_BYTEINT = "BYTEINT"; | ||
private static final String TERADATA_SMALLINT = "SMALLINT"; | ||
private static final String TERADATA_INTEGER = "INTEGER"; | ||
private static final String TERADATA_BIGINT = "BIGINT"; | ||
private static final String TERADATA_FLOAT = "FLOAT"; | ||
private static final String TERADATA_DECIMAL = "DECIMAL"; | ||
|
||
// -------------------------string---------------------------- | ||
private static final String TERADATA_CHAR = "CHAR"; | ||
private static final String TERADATA_VARCHAR = "VARCHAR"; | ||
private static final String TERADATA_CLOB = "CLOB"; | ||
|
||
|
||
// ---------------------------binary--------------------------- | ||
private static final String TERADATA_BYTE = "BYTE"; | ||
private static final String TERADATA_VARBYTE = "VARBYTE"; | ||
|
||
// ------------------------------time------------------------- | ||
private static final String TERADATA_DATE = "DATE"; | ||
private static final String TERADATA_TIME = "TIME"; | ||
private static final String TERADATA_TIMESTAMP = "TIMESTAMP"; | ||
|
||
// ------------------------------blob------------------------- | ||
private static final String TERADATA_BLOB = "BLOB"; | ||
|
||
@Override | ||
public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex) throws SQLException { | ||
String teradataType = metadata.getColumnTypeName(colIndex).toUpperCase(); | ||
switch (teradataType) { | ||
case TERADATA_BYTEINT: | ||
return BasicType.BYTE_TYPE; | ||
case TERADATA_SMALLINT: | ||
return BasicType.SHORT_TYPE; | ||
case TERADATA_INTEGER: | ||
return BasicType.INT_TYPE; | ||
case TERADATA_BIGINT: | ||
return BasicType.LONG_TYPE; | ||
case TERADATA_FLOAT: | ||
return BasicType.FLOAT_TYPE; | ||
case TERADATA_DECIMAL: | ||
return new DecimalType(metadata.getPrecision(colIndex), metadata.getScale(colIndex)); | ||
case TERADATA_CHAR: | ||
case TERADATA_VARCHAR: | ||
case TERADATA_CLOB: | ||
return BasicType.STRING_TYPE; | ||
case TERADATA_BYTE: | ||
case TERADATA_VARBYTE: | ||
case TERADATA_BLOB: | ||
return PrimitiveByteArrayType.INSTANCE; | ||
case TERADATA_DATE: | ||
return LocalTimeType.LOCAL_DATE_TYPE; | ||
case TERADATA_TIME: | ||
return LocalTimeType.LOCAL_TIME_TYPE; | ||
case TERADATA_TIMESTAMP: | ||
return LocalTimeType.LOCAL_DATE_TIME_TYPE; | ||
default: | ||
final String jdbcColumnName = metadata.getColumnName(colIndex); | ||
throw new UnsupportedOperationException( | ||
String.format( | ||
"Doesn't support TERADATA type '%s' on column '%s' yet.", | ||
teradataType, jdbcColumnName)); | ||
} | ||
} | ||
} |
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
86 changes: 86 additions & 0 deletions
86
...jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcTeradataIT.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,86 @@ | ||
/* | ||
* 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.seatunnel.connectors.seatunnel.jdbc; | ||
|
||
import org.apache.seatunnel.e2e.common.TestResource; | ||
import org.apache.seatunnel.e2e.common.TestSuiteBase; | ||
import org.apache.seatunnel.e2e.common.container.ContainerExtendedFactory; | ||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
|
||
import com.teradata.jdbc.TeraDataSource; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.testcontainers.containers.Container; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Statement; | ||
|
||
@Disabled("Disabled because it needs user's personal teradata account to run this test!") | ||
public class JdbcTeradataIT extends TestSuiteBase implements TestResource { | ||
private static final String HOST = "1.2.3.4"; | ||
private static final String PORT = "1025"; | ||
private static final String USERNAME = "dbc"; | ||
private static final String PASSWORD = "dbc"; | ||
private static final String DATABASE = "test"; | ||
private static final String SINK_TABLE = "sink_table"; | ||
private static final String TERADATA_DRIVER_JAR = "https://repo1.maven.org/maven2/com/teradata/jdbc/terajdbc4/17.20.00.12/terajdbc4-17.20.00.12.jar"; | ||
private final ContainerExtendedFactory extendedFactory = container -> { | ||
container.execInContainer("bash", "-c", "mkdir -p /tmp/seatunnel/plugins/Jdbc/lib && cd /tmp/seatunnel/plugins/Jdbc/lib && curl -O " + TERADATA_DRIVER_JAR); | ||
}; | ||
|
||
private Connection connection; | ||
|
||
@TestTemplate | ||
public void testTeradata(TestContainer container) throws Exception { | ||
container.executeExtraCommands(extendedFactory); | ||
Container.ExecResult execResult = container.executeJob("/jdbc_teradata_source_and_sink.conf"); | ||
Assertions.assertEquals(0, execResult.getExitCode()); | ||
clearSinkTable(); | ||
} | ||
|
||
private void clearSinkTable() { | ||
try (Statement statement = connection.createStatement()) { | ||
statement.execute(String.format("delete from %s", SINK_TABLE)); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Test teradata server failed!", e); | ||
} | ||
} | ||
|
||
@BeforeAll | ||
@Override | ||
public void startUp() throws Exception { | ||
TeraDataSource teraDataSource = new TeraDataSource(); | ||
teraDataSource.setDSName(HOST); | ||
teraDataSource.setDbsPort(PORT); | ||
teraDataSource.setUser(USERNAME); | ||
teraDataSource.setPassword(PASSWORD); | ||
teraDataSource.setDATABASE(DATABASE); | ||
this.connection = teraDataSource.getConnection(); | ||
} | ||
|
||
@AfterAll | ||
@Override | ||
public void tearDown() throws Exception { | ||
if (connection != null) { | ||
this.connection.close(); | ||
} | ||
} | ||
} |
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.
@FWLamb
Please reference to
JdbcOracledbIT
validation data input and outputhttps://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcOracledbIT.java
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.
Teradata does not have a Docker image, and it seems that it cannot be made by itself.