Skip to content
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

Add port number as a DBS_PORT parameter in Teradata JDBC Connection String #2452

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
AbdulR3hman marked this conversation as resolved.
Show resolved Hide resolved
{
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));
}
}
Loading