3737import com .amazonaws .athena .connector .lambda .metadata .GetTableLayoutRequest ;
3838import com .amazonaws .athena .connector .lambda .metadata .ListSchemasRequest ;
3939import com .amazonaws .athena .connector .lambda .metadata .ListSchemasResponse ;
40- import com .amazonaws .athena .connector .lambda .metadata .ListTablesRequest ;
41- import com .amazonaws .athena .connector .lambda .metadata .ListTablesResponse ;
4240import com .amazonaws .athena .connector .lambda .metadata .optimizations .DataSourceOptimizations ;
4341import com .amazonaws .athena .connector .lambda .metadata .optimizations .OptimizationSubType ;
4442import com .amazonaws .athena .connector .lambda .metadata .optimizations .pushdown .ComplexExpressionPushdownSubType ;
4543import com .amazonaws .athena .connector .lambda .metadata .optimizations .pushdown .FilterPushdownSubType ;
4644import com .amazonaws .athena .connector .lambda .metadata .optimizations .pushdown .LimitPushdownSubType ;
4745import com .amazonaws .athena .connector .lambda .metadata .optimizations .pushdown .TopNPushdownSubType ;
46+ import com .amazonaws .athena .connectors .db2 .resolver .Db2JDBCCaseResolver ;
4847import com .amazonaws .athena .connectors .jdbc .connection .DatabaseConnectionConfig ;
4948import com .amazonaws .athena .connectors .jdbc .connection .DatabaseConnectionInfo ;
5049import com .amazonaws .athena .connectors .jdbc .connection .GenericJdbcConnectionFactory ;
5352import com .amazonaws .athena .connectors .jdbc .manager .JdbcArrowTypeConverter ;
5453import com .amazonaws .athena .connectors .jdbc .manager .JdbcMetadataHandler ;
5554import com .amazonaws .athena .connectors .jdbc .manager .PreparedStatementBuilder ;
55+ import com .amazonaws .athena .connectors .jdbc .resolver .JDBCCaseResolver ;
5656import com .google .common .annotations .VisibleForTesting ;
5757import com .google .common .collect .ImmutableMap ;
5858import com .google .common .collect .ImmutableSet ;
6868import java .sql .Connection ;
6969import java .sql .PreparedStatement ;
7070import java .sql .ResultSet ;
71+ import java .sql .SQLException ;
7172import java .sql .Statement ;
7273import java .util .ArrayList ;
7374import java .util .Arrays ;
@@ -121,18 +122,19 @@ public Db2MetadataHandler(
121122 JdbcConnectionFactory jdbcConnectionFactory ,
122123 java .util .Map <String , String > configOptions )
123124 {
124- super (databaseConnectionConfig , jdbcConnectionFactory , configOptions );
125+ super (databaseConnectionConfig , jdbcConnectionFactory , configOptions , new Db2JDBCCaseResolver ( Db2Constants . NAME ) );
125126 }
126127
127128 @ VisibleForTesting
128129 protected Db2MetadataHandler (
129- DatabaseConnectionConfig databaseConnectionConfig ,
130- SecretsManagerClient secretsManager ,
131- AthenaClient athena ,
132- JdbcConnectionFactory jdbcConnectionFactory ,
133- java .util .Map <String , String > configOptions )
130+ DatabaseConnectionConfig databaseConnectionConfig ,
131+ SecretsManagerClient secretsManager ,
132+ AthenaClient athena ,
133+ JdbcConnectionFactory jdbcConnectionFactory ,
134+ java .util .Map <String , String > configOptions ,
135+ JDBCCaseResolver caseResolver )
134136 {
135- super (databaseConnectionConfig , secretsManager , athena , jdbcConnectionFactory , configOptions );
137+ super (databaseConnectionConfig , secretsManager , athena , jdbcConnectionFactory , configOptions , caseResolver );
136138 }
137139
138140 /**
@@ -152,21 +154,20 @@ public ListSchemasResponse doListSchemaNames(final BlockAllocator blockAllocator
152154 }
153155
154156 /**
155- * Overridden this method to fetch table(s) for selected schema in Athena Data window .
157+ * Overridden the base class method to provide DB2-specific table listing functionality .
156158 *
157- * @param blockAllocator
158- * @param listTablesRequest
159- * @return
159+ * @param connection The JDBC connection to use for querying DB2
160+ * @param schemaName The name of the schema to list tables from
161+ * @return A list of {@link TableName} objects representing the tables and views in the specified schema
162+ * @throws SQLException if there is an error executing the query or processing the results
160163 */
161164 @ Override
162- public ListTablesResponse doListTables ( final BlockAllocator blockAllocator , final ListTablesRequest listTablesRequest ) throws Exception
165+ protected List < TableName > listTables ( Connection connection , String schemaName ) throws SQLException
163166 {
164- try (Connection connection = getJdbcConnectionFactory ().getConnection (getCredentialProvider ())) {
165- LOGGER .info ("{}: List table names for Catalog {}, Schema {}" , listTablesRequest .getQueryId (), listTablesRequest .getCatalogName (), listTablesRequest .getSchemaName ());
166- List <String > tableNames = getTableList (connection , Db2Constants .QRY_TO_LIST_TABLES_AND_VIEWS , listTablesRequest .getSchemaName ());
167- List <TableName > tables = tableNames .stream ().map (tableName -> new TableName (listTablesRequest .getSchemaName (), tableName )).collect (Collectors .toList ());
168- return new ListTablesResponse (listTablesRequest .getCatalogName (), tables , null );
169- }
167+ List <String > tableNames = getTableList (connection , schemaName );
168+ return tableNames .stream ()
169+ .map (tableName -> new TableName (schemaName , tableName ))
170+ .collect (Collectors .toList ());
170171 }
171172
172173 /**
@@ -395,18 +396,17 @@ private List<String> getSchemaList(final Connection connection, String query) th
395396 * Logic to fetch table name(s) for given schema. Through jdbc call and executing sql query pulling
396397 * all the table names from Db2 for a given schema.
397398 *
398- * @param connection
399- * @param query
400- * @param schemaName
401- * @return List<String>
402- * @throws Exception
399+ * @param connection The JDBC connection to use for querying DB2
400+ * @param schemaName The name of the schema to list tables from
401+ * @return List of table names in the specified schema
402+ * @throws SQLException if any error occurs while executing the query or processing results
403403 */
404- private List <String > getTableList (final Connection connection , String query , String schemaName ) throws Exception
404+ private List <String > getTableList (final Connection connection , String schemaName ) throws SQLException
405405 {
406406 List <String > list = new ArrayList <>();
407- try (PreparedStatement ps = connection .prepareStatement (query )) {
407+ try (PreparedStatement ps = connection .prepareStatement (Db2Constants . QRY_TO_LIST_TABLES_AND_VIEWS )) {
408408 ps .setString (1 , schemaName );
409- try (ResultSet rs = ps .executeQuery (); ) {
409+ try (ResultSet rs = ps .executeQuery ()) {
410410 while (rs .next ()) {
411411 list .add (rs .getString ("NAME" ));
412412 }
0 commit comments