|
71 | 71 | import java.util.stream.Collectors; |
72 | 72 |
|
73 | 73 | import static com.amazonaws.athena.connector.lambda.metadata.ListTablesRequest.UNLIMITED_PAGE_SIZE_VALUE; |
| 74 | +import static com.amazonaws.athena.connector.lambda.domain.predicate.Constraints.DEFAULT_NO_LIMIT; |
74 | 75 | import static com.amazonaws.athena.connectors.db2.Db2Constants.PARTITION_NUMBER; |
75 | 76 | import static org.mockito.ArgumentMatchers.nullable; |
76 | 77 |
|
@@ -374,6 +375,52 @@ public void doListPaginatedTables() |
374 | 375 | // With unlimited page size, there should be no next token (null) since all results are returned |
375 | 376 | executePaginatedTableTest(values, expected, "0", UNLIMITED_PAGE_SIZE_VALUE, null); |
376 | 377 | } |
| 378 | + |
| 379 | + @Test |
| 380 | + public void doGetSplits_withSinglePartition_returnsSplit() |
| 381 | + throws Exception { |
| 382 | + Constraints constraints = new Constraints( |
| 383 | + Collections.emptyMap(), |
| 384 | + Collections.emptyList(), |
| 385 | + Collections.emptyList(), |
| 386 | + DEFAULT_NO_LIMIT, |
| 387 | + Collections.emptyMap(), |
| 388 | + null |
| 389 | + ); |
| 390 | + TableName tableName = new TableName("testSchema", "testTable"); |
| 391 | + |
| 392 | + PreparedStatement partitionPreparedStatement = Mockito.mock(PreparedStatement.class); |
| 393 | + Mockito.when(this.connection.prepareStatement(Db2Constants.PARTITION_QUERY)).thenReturn(partitionPreparedStatement); |
| 394 | + ResultSet partitionResultSet = mockResultSet(new String[]{"DATAPARTITIONID"}, new int[]{Types.INTEGER}, new Object[][]{{0}}, new AtomicInteger(-1)); |
| 395 | + Mockito.when(partitionPreparedStatement.executeQuery()).thenReturn(partitionResultSet); |
| 396 | + |
| 397 | + PreparedStatement colNamePreparedStatement = Mockito.mock(PreparedStatement.class); |
| 398 | + Mockito.when(this.connection.prepareStatement(Db2Constants.COLUMN_INFO_QUERY)).thenReturn(colNamePreparedStatement); |
| 399 | + ResultSet colNameResultSet = mockResultSet(new String[]{"COLNAME"}, new int[]{Types.VARCHAR}, new Object[][]{{"PC"}}, new AtomicInteger(-1)); |
| 400 | + Mockito.when(colNamePreparedStatement.executeQuery()).thenReturn(colNameResultSet); |
| 401 | + Mockito.when(colNameResultSet.next()).thenReturn(true); |
| 402 | + |
| 403 | + Mockito.when(this.connection.getMetaData().getSearchStringEscape()).thenReturn(null); |
| 404 | + |
| 405 | + Schema partitionSchema = this.db2MetadataHandler.getPartitionSchema("testCatalogName"); |
| 406 | + Set<String> partitionCols = partitionSchema.getFields().stream().map(Field::getName).collect(Collectors.toSet()); |
| 407 | + GetTableLayoutRequest getTableLayoutRequest = new GetTableLayoutRequest(this.federatedIdentity, "testQueryId", "testCatalogName", tableName, constraints, partitionSchema, partitionCols); |
| 408 | + |
| 409 | + GetTableLayoutResponse getTableLayoutResponse = this.db2MetadataHandler.doGetTableLayout(this.blockAllocator, getTableLayoutRequest); |
| 410 | + |
| 411 | + BlockAllocator splitBlockAllocator = new BlockAllocatorImpl(); |
| 412 | + GetSplitsRequest getSplitsRequest = new GetSplitsRequest(this.federatedIdentity, "testQueryId", "testCatalogName", tableName, getTableLayoutResponse.getPartitions(), new ArrayList<>(partitionCols), constraints, null); |
| 413 | + GetSplitsResponse getSplitsResponse = this.db2MetadataHandler.doGetSplits(splitBlockAllocator, getSplitsRequest); |
| 414 | + |
| 415 | + Set<Map<String, String>> expectedSplits = com.google.common.collect.ImmutableSet.of( |
| 416 | + com.google.common.collect.ImmutableMap.of( |
| 417 | + PARTITION_NUMBER, "0", |
| 418 | + Db2MetadataHandler.PARTITIONING_COLUMN, "PC")); |
| 419 | + |
| 420 | + Assert.assertEquals(expectedSplits.size(), getSplitsResponse.getSplits().size()); |
| 421 | + Set<Map<String, String>> actualSplits = getSplitsResponse.getSplits().stream().map(Split::getProperties).collect(Collectors.toSet()); |
| 422 | + Assert.assertEquals(expectedSplits, actualSplits); |
| 423 | + } |
377 | 424 |
|
378 | 425 | /** |
379 | 426 | * Helper method to execute paginated table test and verify results |
|
0 commit comments