use of com.amazonaws.athena.connector.lambda.ThrottlingInvoker in project aws-athena-query-federation by awslabs.
the class TestBase method setupOnce.
@BeforeClass
public static void setupOnce() throws Exception {
ddbClient = setupDatabase();
ThrottlingInvoker invoker = ThrottlingInvoker.newDefaultBuilder(EXCEPTION_FILTER).build();
schema = DDBTableUtils.peekTableForSchema(TEST_TABLE, invoker, ddbClient);
}
use of com.amazonaws.athena.connector.lambda.ThrottlingInvoker in project aws-athena-query-federation by awslabs.
the class DDBTableUtils method getTable.
/**
* Fetches metadata for a DynamoDB table
*
* @param tableName the (case sensitive) table name
* @param invoker the ThrottlingInvoker to call DDB with
* @param ddbClient the DDB client to use
* @return the table metadata
*/
public static DynamoDBTable getTable(String tableName, ThrottlingInvoker invoker, AmazonDynamoDB ddbClient) throws TimeoutException {
DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
TableDescription table = invoker.invoke(() -> ddbClient.describeTable(request).getTable());
KeyNames keys = getKeys(table.getKeySchema());
// get data statistics
long approxTableSizeInBytes = table.getTableSizeBytes();
long approxItemCount = table.getItemCount();
final long provisionedReadCapacity = table.getProvisionedThroughput() != null ? table.getProvisionedThroughput().getReadCapacityUnits() : PSUEDO_CAPACITY_FOR_ON_DEMAND;
// get secondary indexes
List<LocalSecondaryIndexDescription> localSecondaryIndexes = table.getLocalSecondaryIndexes() != null ? table.getLocalSecondaryIndexes() : ImmutableList.of();
List<GlobalSecondaryIndexDescription> globalSecondaryIndexes = table.getGlobalSecondaryIndexes() != null ? table.getGlobalSecondaryIndexes() : ImmutableList.of();
ImmutableList.Builder<DynamoDBIndex> indices = ImmutableList.builder();
localSecondaryIndexes.forEach(i -> {
KeyNames indexKeys = getKeys(i.getKeySchema());
// DynamoDB automatically fetches all attributes from the table for local secondary index, so ignore projected attributes
indices.add(new DynamoDBIndex(i.getIndexName(), indexKeys.getHashKey(), indexKeys.getRangeKey(), ProjectionType.ALL, ImmutableList.of()));
});
globalSecondaryIndexes.stream().filter(i -> IndexStatus.fromValue(i.getIndexStatus()).equals(IndexStatus.ACTIVE)).forEach(i -> {
KeyNames indexKeys = getKeys(i.getKeySchema());
indices.add(new DynamoDBIndex(i.getIndexName(), indexKeys.getHashKey(), indexKeys.getRangeKey(), ProjectionType.fromValue(i.getProjection().getProjectionType()), i.getProjection().getNonKeyAttributes() == null ? ImmutableList.of() : i.getProjection().getNonKeyAttributes()));
});
return new DynamoDBTable(tableName, keys.getHashKey(), keys.getRangeKey(), table.getAttributeDefinitions(), indices.build(), approxTableSizeInBytes, approxItemCount, provisionedReadCapacity);
}
Aggregations