Skip to content

Commit

Permalink
Add port number as a DBS_PORT parameter in Teradata JDBC Connection S…
Browse files Browse the repository at this point in the history
…tring (#2452)
  • Loading branch information
Jithendar12 authored Jan 15, 2025
1 parent 01bd504 commit 2d1bea3
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@

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<String, String> connectionPropertiesToEnvironment(Map<String, String> connectionProperties)
{
HashMap<String, String> environment = new HashMap<>();

// 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=" + connectionProperties.getOrDefault(PORT, String.valueOf(TeradataConstants.TERADATA_DEFAULT_PORT)) + getJdbcParameters(connectionProperties);

environment.put(DEFAULT, connectionString);
return environment;
}

@Override
protected String getConnectionStringPrefix(Map<String, String> connectionProperties)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> 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<String, String> 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));
}
}

0 comments on commit 2d1bea3

Please sign in to comment.