Skip to content

Commit

Permalink
Merge branch 'master' into sqlserver_phase2_tablelist_issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ritiktrianz authored Jan 17, 2025
2 parents 2401575 + 66736ea commit ae4e095
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
public class Db2As400MetadataHandler extends JdbcMetadataHandler
{
private static final Logger LOGGER = LoggerFactory.getLogger(Db2As400MetadataHandler.class);
static final String PARTITION_NUMBER = "PARTITION_NUMBER";
static final String PARTITION_NUMBER = "partition_number";
static final String PARTITIONING_COLUMN = "PARTITIONING_COLUMN";
/**
* DB2 has max number of partition 32,000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.amazonaws.athena.connectors.db2as400.Db2As400MetadataHandler.PARTITION_NUMBER;
import static org.mockito.ArgumentMatchers.nullable;

public class Db2As400MetadataHandlerTest extends TestBase {
private static final Logger logger = LoggerFactory.getLogger(Db2As400MetadataHandlerTest.class);
private static final Schema PARTITION_SCHEMA = SchemaBuilder.newBuilder().addField("PARTITION_NUMBER", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build();
private static final Schema PARTITION_SCHEMA = SchemaBuilder.newBuilder().addField(PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build();
private DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", Db2As400Constants.NAME,
"db2as400://jdbc:as400://testhost;user=dummy;password=dummy;");
private Db2As400MetadataHandler db2As400MetadataHandler;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void setup() throws Exception {
public void getPartitionSchema()
{
Assert.assertEquals(SchemaBuilder.newBuilder()
.addField(Db2As400MetadataHandler.PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build(),
.addField(PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build(),
this.db2As400MetadataHandler.getPartitionSchema("testCatalogName"));
}

Expand All @@ -130,7 +131,7 @@ public void doGetSplitsWithNoPartition()
GetSplitsResponse getSplitsResponse = this.db2As400MetadataHandler.doGetSplits(splitBlockAllocator, getSplitsRequest);

Set<Map<String, String>> expectedSplits = new HashSet<>();
expectedSplits.add(Collections.singletonMap(db2As400MetadataHandler.PARTITION_NUMBER, "0"));
expectedSplits.add(Collections.singletonMap(PARTITION_NUMBER, "0"));
Assert.assertEquals(expectedSplits.size(), getSplitsResponse.getSplits().size());
Set<Map<String, String>> actualSplits = getSplitsResponse.getSplits().stream().map(Split::getProperties).collect(Collectors.toSet());
Assert.assertEquals(expectedSplits, actualSplits);
Expand Down Expand Up @@ -167,13 +168,13 @@ public void doGetSplits()

Set<Map<String, String>> expectedSplits = com.google.common.collect.ImmutableSet.of(
com.google.common.collect.ImmutableMap.of(
db2As400MetadataHandler.PARTITION_NUMBER, "0",
PARTITION_NUMBER, "0",
db2As400MetadataHandler.PARTITIONING_COLUMN, "PC"),
com.google.common.collect.ImmutableMap.of(
db2As400MetadataHandler.PARTITION_NUMBER, "1",
PARTITION_NUMBER, "1",
db2As400MetadataHandler.PARTITIONING_COLUMN, "PC"),
com.google.common.collect.ImmutableMap.of(
db2As400MetadataHandler.PARTITION_NUMBER, "2",
PARTITION_NUMBER, "2",
db2As400MetadataHandler.PARTITIONING_COLUMN, "PC"));

Assert.assertEquals(expectedSplits.size(), getSplitsResponse.getSplits().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testGetPartitionWhereClauses()
{
Db2As400QueryStringBuilder builder = new Db2As400QueryStringBuilder("'");
Split split = Mockito.mock(Split.class);
Mockito.when(split.getProperty(Mockito.eq("PARTITION_NUMBER"))).thenReturn("0");
Mockito.when(split.getProperty(Mockito.eq("partition_number"))).thenReturn("0");
Mockito.when(split.getProperty(Mockito.eq("PARTITIONING_COLUMN"))).thenReturn("PC");
Assert.assertEquals(Arrays.asList(" DATAPARTITIONNUM(PC) = 0"), builder.getPartitionWhereClauses(split));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Db2Constants
public static final String DRIVER_CLASS = "com.ibm.db2.jcc.DB2Driver";
public static final int DEFAULT_PORT = 50001;
public static final String QUOTE_CHARACTER = "\"";

static final String PARTITION_NUMBER = "partition_number";
public static final String QRY_TO_LIST_SCHEMAS = "select schemaname as name " +
"from syscat.schemata " +
"where schemaname not like 'SYS%' " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
import java.util.stream.Collectors;

import static com.amazonaws.athena.connector.lambda.domain.predicate.functions.StandardFunctions.NULLIF_FUNCTION_NAME;
import static com.amazonaws.athena.connectors.db2.Db2Constants.PARTITION_NUMBER;

public class Db2MetadataHandler extends JdbcMetadataHandler
{
private static final Logger LOGGER = LoggerFactory.getLogger(Db2MetadataHandler.class);
static final String PARTITION_NUMBER = "PARTITION_NUMBER";
static final String PARTITIONING_COLUMN = "PARTITIONING_COLUMN";
/**
* DB2 has max number of partition 32,000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Collections;
import java.util.List;

import static com.amazonaws.athena.connectors.db2.Db2Constants.PARTITION_NUMBER;

public class Db2QueryStringBuilder extends JdbcSplitQueryBuilder
{
private static final Logger LOGGER = LoggerFactory.getLogger(Db2QueryStringBuilder.class);
Expand Down Expand Up @@ -74,7 +76,7 @@ protected List<String> getPartitionWhereClauses(Split split)
if (column != null) {
LOGGER.debug("Fetching data using Partition");
//example query: select * from EMP_TABLE WHERE DATAPARTITIONNUM(EMP_NO) = 0
return Collections.singletonList(" DATAPARTITIONNUM(" + column + ") = " + split.getProperty(Db2MetadataHandler.PARTITION_NUMBER));
return Collections.singletonList(" DATAPARTITIONNUM(" + column + ") = " + split.getProperty(PARTITION_NUMBER));
}
else {
LOGGER.debug("Fetching data without Partition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.amazonaws.athena.connectors.db2.Db2Constants.PARTITION_NUMBER;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;

public class Db2MetadataHandlerTest extends TestBase {
private static final Logger logger = LoggerFactory.getLogger(Db2MetadataHandlerTest.class);
private static final Schema PARTITION_SCHEMA = SchemaBuilder.newBuilder().addField("PARTITION_NUMBER", org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build();
private static final Schema PARTITION_SCHEMA = SchemaBuilder.newBuilder().addField(PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build();
private DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", Db2Constants.NAME,
"dbtwo://jdbc:db2://hostname:50001/dummydatabase:user=dummyuser;password=dummypwd");
private Db2MetadataHandler db2MetadataHandler;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void setup() throws Exception {
public void getPartitionSchema()
{
Assert.assertEquals(SchemaBuilder.newBuilder()
.addField(Db2MetadataHandler.PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build(),
.addField(PARTITION_NUMBER, org.apache.arrow.vector.types.Types.MinorType.VARCHAR.getType()).build(),
this.db2MetadataHandler.getPartitionSchema("testCatalogName"));
}

Expand All @@ -131,7 +132,7 @@ public void doGetSplitsWithNoPartition()
GetSplitsResponse getSplitsResponse = this.db2MetadataHandler.doGetSplits(splitBlockAllocator, getSplitsRequest);

Set<Map<String, String>> expectedSplits = new HashSet<>();
expectedSplits.add(Collections.singletonMap(db2MetadataHandler.PARTITION_NUMBER, "0"));
expectedSplits.add(Collections.singletonMap(PARTITION_NUMBER, "0"));
Assert.assertEquals(expectedSplits.size(), getSplitsResponse.getSplits().size());
Set<Map<String, String>> actualSplits = getSplitsResponse.getSplits().stream().map(Split::getProperties).collect(Collectors.toSet());
Assert.assertEquals(expectedSplits, actualSplits);
Expand Down Expand Up @@ -168,13 +169,13 @@ public void doGetSplits()

Set<Map<String, String>> expectedSplits = com.google.common.collect.ImmutableSet.of(
com.google.common.collect.ImmutableMap.of(
db2MetadataHandler.PARTITION_NUMBER, "0",
PARTITION_NUMBER, "0",
db2MetadataHandler.PARTITIONING_COLUMN, "PC"),
com.google.common.collect.ImmutableMap.of(
db2MetadataHandler.PARTITION_NUMBER, "1",
PARTITION_NUMBER, "1",
db2MetadataHandler.PARTITIONING_COLUMN, "PC"),
com.google.common.collect.ImmutableMap.of(
db2MetadataHandler.PARTITION_NUMBER, "2",
PARTITION_NUMBER, "2",
db2MetadataHandler.PARTITIONING_COLUMN, "PC"));

Assert.assertEquals(expectedSplits.size(), getSplitsResponse.getSplits().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testGetPartitionWhereClauses()
{
Db2QueryStringBuilder builder = new Db2QueryStringBuilder(QUOTE_CHARACTER, new Db2FederationExpressionParser(QUOTE_CHARACTER));
Split split = Mockito.mock(Split.class);
Mockito.when(split.getProperty(Mockito.eq("PARTITION_NUMBER"))).thenReturn("0");
Mockito.when(split.getProperty(Mockito.eq("partition_number"))).thenReturn("0");
Mockito.when(split.getProperty(Mockito.eq("PARTITIONING_COLUMN"))).thenReturn("PC");
Assert.assertEquals(Arrays.asList(" DATAPARTITIONNUM(PC) = 0"), builder.getPartitionWhereClauses(split));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.sql.SQLException;
import java.util.Collections;

import static com.amazonaws.athena.connectors.db2.Db2Constants.PARTITION_NUMBER;
import static com.amazonaws.athena.connectors.db2.Db2Constants.QUOTE_CHARACTER;
import static org.mockito.ArgumentMatchers.nullable;

Expand Down Expand Up @@ -97,7 +98,7 @@ public void buildSplitSqlNew()
Schema schema = schemaBuilder.build();

Split split = Mockito.mock(Split.class);
Mockito.when(split.getProperty(Db2MetadataHandler.PARTITION_NUMBER)).thenReturn("0");
Mockito.when(split.getProperty(PARTITION_NUMBER)).thenReturn("0");

ValueSet valueSet = getSingleValueSet("varcharTest");
Constraints constraints = Mockito.mock(Constraints.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
import com.amazonaws.athena.connector.lambda.metadata.optimizations.querypassthrough.QueryPassthroughSignature;
import com.google.common.collect.ImmutableSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.ErrorDetails;
Expand All @@ -31,7 +30,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

public class DDBQueryPassthrough implements QueryPassthroughSignature
{
Expand Down Expand Up @@ -82,15 +80,5 @@ public void customConnectorVerifications(Map<String, String> engineQptArguments)
if (!upperCaseStatement.startsWith("SELECT")) {
throw new AthenaConnectorException("Statement does not start with SELECT.", ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
}

// List of disallowed keywords
Set<String> disallowedKeywords = ImmutableSet.of("INSERT", "UPDATE", "DELETE", "CREATE", "DROP", "ALTER");

// Check if the statement contains any disallowed keywords
for (String keyword : disallowedKeywords) {
if (upperCaseStatement.contains(keyword)) {
throw new AthenaConnectorException("Unaccepted operation; only SELECT statements are allowed. Found: " + keyword, ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
}
}
}
}
2 changes: 1 addition & 1 deletion athena-gcs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.15.0</version>
<version>5.16.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion athena-google-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.15.0</version>
<version>5.16.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awscdk/rds -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public Connection getConnection(final JdbcCredentialProvider jdbcCredentialProvi
properties.put("javax.net.ssl.trustStore", "rds-truststore.jks");
properties.put("javax.net.ssl.trustStorePassword", "federationStorePass");
properties.put("oracle.net.ssl_server_dn_match", "true");
// By default; Oracle RDS uses SSL_RSA_WITH_AES_256_CBC_SHA
// Adding the following cipher suits to support others listed in Doc
// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.Oracle.Options.SSL.html#Appendix.Oracle.Options.SSL.CipherSuites
if (System.getenv().getOrDefault(IS_FIPS_ENABLED, "false").equalsIgnoreCase("true") || System.getenv().getOrDefault(IS_FIPS_ENABLED_LEGACY, "false").equalsIgnoreCase("true")) {
properties.put("oracle.net.ssl_cipher_suites", "(TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public final class SaphanaConstants
public static final int SAPHANA_DEFAULT_PORT = 1025;
static final Map<String, String> JDBC_PROPERTIES = ImmutableMap.of("databaseTerm", "SCHEMA");
static final String ALL_PARTITIONS = "0";
static final String BLOCK_PARTITION_COLUMN_NAME = "PART_ID";
static final String BLOCK_PARTITION_COLUMN_NAME = "part_id";
static final String COLUMN_NAME = "COLUMN_NAME";
static final String CASE_UPPER = "upper";
static final String CASE_LOWER = "lower";
public static final String SAPHANA_QUOTE_CHARACTER = "\"";
/**
* partition query for saphana
*/
static final String GET_PARTITIONS_QUERY = "SELECT DISTINCT PART_ID FROM SYS.TABLE_PARTITIONS " +
static final String GET_PARTITIONS_QUERY = "SELECT DISTINCT PART_ID as \"part_id\" FROM SYS.TABLE_PARTITIONS " +
"WHERE TABLE_NAME = ? AND SCHEMA_NAME = ? AND PART_ID IS NOT NULL";

/**
Expand Down
Loading

0 comments on commit ae4e095

Please sign in to comment.