From 51beb781735720a5c57b69368e7981791609b012 Mon Sep 17 00:00:00 2001 From: Jithendar12 Date: Mon, 2 Dec 2024 15:54:11 +0530 Subject: [PATCH 1/2] Add port number as a DBS_PORT parameter in Teradata JDBC Connection String --- .../TeradataEnvironmentProperties.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java b/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java index 0b41bbcb0f..bbc2bfee02 100644 --- a/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java +++ b/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java @@ -21,12 +21,31 @@ import com.amazonaws.athena.connectors.jdbc.JdbcEnvironmentProperties; +import java.util.HashMap; import java.util.Map; import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DATABASE; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DEFAULT; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.HOST; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.PORT; public class TeradataEnvironmentProperties extends JdbcEnvironmentProperties { + @Override + public Map connectionPropertiesToEnvironment(Map connectionProperties) + { + HashMap environment = new HashMap<>(); + // Default port for teradata is 1025 + String port = connectionProperties.getOrDefault(PORT, "1025"); + + // Construct the JDBC connection string and include the port as a DBS_PORT parameter + String connectionString = getConnectionStringPrefix(connectionProperties) + connectionProperties.get(HOST) + + getDatabase(connectionProperties) + ",DBS_PORT=" + port + getJdbcParameters(connectionProperties); + + environment.put(DEFAULT, connectionString); + return environment; + } + @Override protected String getConnectionStringPrefix(Map connectionProperties) { From 7500fddddeb10aa655b402713c1f7fce7b8e236c Mon Sep 17 00:00:00 2001 From: Jithendar12 Date: Mon, 13 Jan 2025 12:04:17 +0530 Subject: [PATCH 2/2] Address review comments --- .../TeradataEnvironmentProperties.java | 4 +- .../TeradataEnvironmentPropertiesTest.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 athena-teradata/src/test/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentPropertiesTest.java diff --git a/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java b/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java index bbc2bfee02..d5ddbee34f 100644 --- a/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java +++ b/athena-teradata/src/main/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentProperties.java @@ -35,12 +35,10 @@ public class TeradataEnvironmentProperties extends JdbcEnvironmentProperties public Map connectionPropertiesToEnvironment(Map connectionProperties) { HashMap environment = new HashMap<>(); - // Default port for teradata is 1025 - String port = connectionProperties.getOrDefault(PORT, "1025"); // Construct the JDBC connection string and include the port as a DBS_PORT parameter String connectionString = getConnectionStringPrefix(connectionProperties) + connectionProperties.get(HOST) - + getDatabase(connectionProperties) + ",DBS_PORT=" + port + getJdbcParameters(connectionProperties); + + getDatabase(connectionProperties) + ",DBS_PORT=" + connectionProperties.getOrDefault(PORT, String.valueOf(TeradataConstants.TERADATA_DEFAULT_PORT)) + getJdbcParameters(connectionProperties); environment.put(DEFAULT, connectionString); return environment; diff --git a/athena-teradata/src/test/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentPropertiesTest.java b/athena-teradata/src/test/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentPropertiesTest.java new file mode 100644 index 0000000000..64f2ecb252 --- /dev/null +++ b/athena-teradata/src/test/java/com/amazonaws/athena/connectors/teradata/TeradataEnvironmentPropertiesTest.java @@ -0,0 +1,70 @@ +/*- + * #%L + * athena-teradata + * %% + * Copyright (C) 2019 Amazon Web Services + * %% + * 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. + * #L% + */ +package com.amazonaws.athena.connectors.teradata; + +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DATABASE; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.DEFAULT; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.HOST; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.PORT; +import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME; +import static org.junit.Assert.assertEquals; + +public class TeradataEnvironmentPropertiesTest +{ + Map connectionProperties; + TeradataEnvironmentProperties teradataEnvironmentProperties; + + @Before + public void setUp() + { + connectionProperties = new HashMap<>(); + connectionProperties.put(HOST, "test.teradata.com"); + connectionProperties.put(DATABASE, "testdb"); + connectionProperties.put(SECRET_NAME, "testSecret"); + teradataEnvironmentProperties = new TeradataEnvironmentProperties(); + } + + @Test + public void connectionPropertiesWithCustomPort() + { + // adding custom port + connectionProperties.put(PORT, "1234"); + + Map teradataConnectionProperties = teradataEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties); + + String expectedConnectionString = "teradata://jdbc:teradata://test.teradata.com/TMODE=ANSI,CHARSET=UTF8,DATABASE=testdb,DBS_PORT=1234,${testSecret}"; + assertEquals(expectedConnectionString, teradataConnectionProperties.get(DEFAULT)); + } + + @Test + public void connectionPropertiesWithDefaultPort() + { + Map teradataConnectionProperties = teradataEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties); + + String expectedConnectionString = "teradata://jdbc:teradata://test.teradata.com/TMODE=ANSI,CHARSET=UTF8,DATABASE=testdb,DBS_PORT=1025,${testSecret}"; + assertEquals(expectedConnectionString, teradataConnectionProperties.get(DEFAULT)); + } +}