Skip to content

Commit b703d7e

Browse files
committed
Add unit tests in Cloudera Impala Connector
1 parent bd6506c commit b703d7e

File tree

6 files changed

+711
-149
lines changed

6 files changed

+711
-149
lines changed

athena-cloudera-impala/src/test/java/com/amazonaws/athena/connectors/cloudera/ImpalaEnvironmentPropertiesTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,27 @@
3232
import static com.amazonaws.athena.connector.lambda.connection.EnvironmentConstants.SECRET_NAME;
3333
import static org.junit.Assert.assertEquals;
3434

35-
public class ImpalaEnvironmentPropertiesTest {
35+
public class ImpalaEnvironmentPropertiesTest
36+
{
3637
Map<String, String> connectionProperties;
3738
ImpalaEnvironmentProperties impalaEnvironmentProperties;
3839

3940
@Before
40-
public void setUp() {
41+
public void setUp()
42+
{
4143
connectionProperties = new HashMap<>();
42-
connectionProperties.put(HOST, "50.100.00.10");
44+
connectionProperties.put(HOST, "localhost");
4345
connectionProperties.put(DATABASE, "default");
4446
connectionProperties.put(SECRET_NAME, "testSecret");
4547
connectionProperties.put(PORT, "49172");
4648
impalaEnvironmentProperties = new ImpalaEnvironmentProperties();
4749
}
4850

4951
@Test
50-
public void impalaConnectionPropertiesTest() {
51-
52+
public void testImpalaConnectionProperties()
53+
{
5254
Map<String, String> impalaConnectionProperties = impalaEnvironmentProperties.connectionPropertiesToEnvironment(connectionProperties);
53-
54-
String expectedConnectionString = "impala://jdbc:impala://50.100.00.10:49172/default;${testSecret}";
55+
String expectedConnectionString = "impala://jdbc:impala://localhost:49172/default;${testSecret}";
5556
assertEquals(expectedConnectionString, impalaConnectionProperties.get(DEFAULT));
5657
}
57-
}
58+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*-
2+
* #%L
3+
* athena-cloudera-impala
4+
* %%
5+
* Copyright (C) 2019 - 2025 Amazon Web Services
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.amazonaws.athena.connectors.cloudera;
21+
22+
import org.apache.arrow.vector.types.pojo.ArrowType;
23+
import org.junit.Test;
24+
25+
import java.util.Arrays;
26+
import java.util.Collections;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
public class ImpalaFederationExpressionParserTest
31+
{
32+
private static final String IMPALA_QUOTE_CHARACTER = "`";
33+
private final ImpalaFederationExpressionParser parser = new ImpalaFederationExpressionParser(IMPALA_QUOTE_CHARACTER);
34+
35+
@Test
36+
public void testWriteArrayConstructorClause_withMultipleElements()
37+
{
38+
String result = parser.writeArrayConstructorClause(
39+
new ArrowType.Int(32, true),
40+
Arrays.asList("1", "2", "3")
41+
);
42+
assertEquals("1, 2, 3", result);
43+
}
44+
45+
@Test
46+
public void testWriteArrayConstructorClause_withSingleElement()
47+
{
48+
String result = parser.writeArrayConstructorClause(
49+
new ArrowType.Utf8(),
50+
Collections.singletonList("'test'")
51+
);
52+
assertEquals("'test'", result);
53+
}
54+
55+
@Test
56+
public void testWriteArrayConstructorClause_withEmptyList()
57+
{
58+
String result = parser.writeArrayConstructorClause(
59+
new ArrowType.Bool(),
60+
Collections.emptyList()
61+
);
62+
assertEquals("", result);
63+
}
64+
}
Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.amazonaws.athena.connectors.cloudera;/*-
1+
/*-
22
* #%L
33
* athena-cloudera-impala
44
* %%
@@ -17,13 +17,13 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20-
21-
import com.amazonaws.athena.connector.credentials.DefaultCredentials;
20+
package com.amazonaws.athena.connectors.cloudera;
2221
import com.amazonaws.athena.connector.credentials.CredentialsProvider;
22+
import com.amazonaws.athena.connector.credentials.DefaultCredentials;
2323
import com.amazonaws.athena.connector.credentials.StaticCredentialsProvider;
24-
import com.amazonaws.athena.connectors.jdbc.connection.*;
24+
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig;
25+
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionInfo;
2526
import com.google.common.collect.ImmutableMap;
26-
import org.junit.Assert;
2727
import org.junit.Test;
2828

2929
import java.sql.Connection;
@@ -32,19 +32,66 @@
3232
import java.sql.SQLException;
3333
import java.util.Map;
3434

35-
public class ImpalaJdbcConnectionFactoryTest {
35+
import static org.junit.Assert.assertEquals;
36+
37+
public class ImpalaJdbcConnectionFactoryTest
38+
{
39+
private static final String TEST_CATALOG = "testCatalog";
40+
private static final String TEST_DEFAULT_DATABASE = "default";
41+
private static final Map<String, String> JDBC_PROPERTIES = ImmutableMap.of("databaseTerm", "SCHEMA");
42+
3643
@Test(expected = RuntimeException.class)
37-
public void getConnectionTest() throws ClassNotFoundException, SQLException {
44+
public void testGetConnection() throws SQLException
45+
{
46+
String impalaConnectionString = "impala://jdbc:impala://localhost:10000/athena;AuthMech=3;UID=hive;PWD=''";
47+
3848
DefaultCredentials expectedCredential = new DefaultCredentials("impala", "impala");
3949
CredentialsProvider credentialsProvider = new StaticCredentialsProvider(expectedCredential);
40-
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", ImpalaConstants.IMPALA_NAME,
41-
"impala://jdbc:impala://23.21.178.97:10000/athena;AuthMech=3;UID=hive;PWD=''", "impala");
42-
Map<String, String> JDBC_PROPERTIES = ImmutableMap.of("databaseTerm", "SCHEMA");
43-
DatabaseConnectionInfo DatabaseConnectionInfo = new DatabaseConnectionInfo(ImpalaConstants.IMPALA_DRIVER_CLASS, ImpalaConstants.IMPALA_DEFAULT_PORT);
44-
Connection connection = new ImpalaJdbcConnectionFactory(databaseConnectionConfig, JDBC_PROPERTIES,DatabaseConnectionInfo).getConnection(credentialsProvider);
50+
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig(TEST_CATALOG, ImpalaConstants.IMPALA_NAME,
51+
impalaConnectionString, "impala");
52+
DatabaseConnectionInfo databaseConnectionInfo = new DatabaseConnectionInfo(ImpalaConstants.IMPALA_DRIVER_CLASS, ImpalaConstants.IMPALA_DEFAULT_PORT);
53+
Connection connection = new ImpalaJdbcConnectionFactory(databaseConnectionConfig, JDBC_PROPERTIES, databaseConnectionInfo).getConnection(credentialsProvider);
4554
String originalURL = connection.getMetaData().getURL();
4655
Driver drv = DriverManager.getDriver(originalURL);
4756
String driverClass = drv.getClass().getName();
48-
Assert.assertEquals("com.cloudera.impala.jdbc.Driver", driverClass);
57+
assertEquals("com.cloudera.impala.jdbc.Driver", driverClass);
58+
}
59+
60+
@Test(expected = RuntimeException.class)
61+
public void testGetConnection_withNullCredentials() throws Exception
62+
{
63+
String localJdbcString = String.format("jdbc:impala://localhost:10000/%s", TEST_DEFAULT_DATABASE);
64+
65+
// Setup the connection config with a test JDBC string
66+
DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig(
67+
TEST_CATALOG,
68+
ImpalaConstants.IMPALA_NAME,
69+
localJdbcString,
70+
TEST_DEFAULT_DATABASE
71+
);
72+
73+
// Setup other required parameters
74+
ImpalaJdbcConnectionFactory connectionFactory = getImpalaJdbcConnectionFactory(databaseConnectionConfig);
75+
76+
// Attempt to get connection with null credentials - this should use the original JDBC string
77+
Connection connection = connectionFactory.getConnection(null);
78+
79+
// Verify the connection URL matches the original JDBC string
80+
assertEquals(localJdbcString, connection.getMetaData().getURL());
81+
}
82+
83+
private static ImpalaJdbcConnectionFactory getImpalaJdbcConnectionFactory(DatabaseConnectionConfig databaseConnectionConfig)
84+
{
85+
DatabaseConnectionInfo databaseConnectionInfo = new DatabaseConnectionInfo(
86+
ImpalaConstants.IMPALA_DRIVER_CLASS,
87+
ImpalaConstants.IMPALA_DEFAULT_PORT
88+
);
89+
90+
// Create the connection factory and attempt to get a connection with null credentials
91+
return new ImpalaJdbcConnectionFactory(
92+
databaseConnectionConfig,
93+
JDBC_PROPERTIES,
94+
databaseConnectionInfo
95+
);
4996
}
5097
}

0 commit comments

Comments
 (0)