software.amazon.awssdk.services.dynamodb.model.ProjectionType Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.ProjectionType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateTableEnhancedRequestTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void builder_maximal() { EnhancedGlobalSecondaryIndex globalSecondaryIndex = EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build(); EnhancedLocalSecondaryIndex localSecondaryIndex = EnhancedLocalSecondaryIndex.create( "lsi", Projection.builder().projectionType(ProjectionType.ALL).build()); CreateTableEnhancedRequest builtObject = CreateTableEnhancedRequest.builder() .globalSecondaryIndices(globalSecondaryIndex) .localSecondaryIndices(localSecondaryIndex) .provisionedThroughput(getDefaultProvisionedThroughput()) .build(); assertThat(builtObject.globalSecondaryIndices(), is(Collections.singletonList(globalSecondaryIndex))); assertThat(builtObject.localSecondaryIndices(), is(Collections.singletonList(localSecondaryIndex))); assertThat(builtObject.provisionedThroughput(), is(getDefaultProvisionedThroughput())); }
Example #2
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test(expected = IllegalArgumentException.class) public void generateRequest_invalidGsi() { ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder() .readCapacityUnits(1L) .writeCapacityUnits(1L) .build(); List<EnhancedGlobalSecondaryIndex> invalidGsiList = Collections.singletonList( EnhancedGlobalSecondaryIndex.builder() .indexName("invalid") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(provisionedThroughput) .build()); CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(invalidGsiList).build()); operation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null); }
Example #3
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void generateRequest_validLsiAsGsiReference() { List<EnhancedGlobalSecondaryIndex> validLsiList = Collections.singletonList( EnhancedGlobalSecondaryIndex.builder() .indexName("lsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(p -> p.readCapacityUnits(1L).writeCapacityUnits(1L)) .build()); CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(validLsiList).build()); CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null); assertThat(request.globalSecondaryIndexes().size(), is(1)); software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex globalSecondaryIndex = request.globalSecondaryIndexes().get(0); assertThat(globalSecondaryIndex.indexName(), is("lsi_1")); }
Example #4
Source File: CreateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void createDynamoDBTable( DynamoDbEnhancedClient enhancedClient) { try { // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Create the table mappedTable.createTable(r -> r.provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .build())); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #5
Source File: IndexScanTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable( r -> r.provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_keys_only") .projection(p -> p.projectionType(ProjectionType.KEYS_ONLY)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build())); }
Example #6
Source File: IndexQueryTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable( CreateTableEnhancedRequest.builder() .provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_keys_only") .projection(p -> p.projectionType(ProjectionType.KEYS_ONLY)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build()) .build()); }
Example #7
Source File: AsyncIndexQueryTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable( CreateTableEnhancedRequest.builder() .provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices(EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_keys_only") .projection(p -> p.projectionType(ProjectionType.KEYS_ONLY)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build()) .build()) .join(); }
Example #8
Source File: BasicCrudTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable(r -> r.provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build())); }
Example #9
Source File: AsyncBasicCrudTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable( r -> r.provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(getDefaultProvisionedThroughput()) .build())) .join(); }
Example #10
Source File: AsyncIndexScanTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Before public void createTable() { mappedTable.createTable( r -> r.provisionedThroughput(getDefaultProvisionedThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_keys_only") .projection(p -> p.projectionType(ProjectionType.KEYS_ONLY)) .provisionedThroughput(getDefaultProvisionedThroughput()).build())) .join(); }
Example #11
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void generateRequest_invalidGsiAsLsiReference() { List<EnhancedLocalSecondaryIndex> invalidGsiList = Collections.singletonList( EnhancedLocalSecondaryIndex.create("gsi_1", Projection.builder().projectionType(ProjectionType.ALL).build())); CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().localSecondaryIndices(invalidGsiList).build()); operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null); }
Example #12
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void generateRequest_invalidLsi() { List<EnhancedLocalSecondaryIndex> invalidLsiList = Collections.singletonList( EnhancedLocalSecondaryIndex.create("invalid", Projection.builder().projectionType(ProjectionType.ALL).build())); CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().localSecondaryIndices(invalidLsiList).build()); operation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null); }
Example #13
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Creates a table in AWS DynamoDB which will be shared between apps. * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createSharedTable(long readCapacity, long writeCapacity) { if (StringUtils.isBlank(SHARED_TABLE) || StringUtils.containsWhitespace(SHARED_TABLE) || existsTable(SHARED_TABLE)) { return false; } String table = getTableNameForAppid(SHARED_TABLE); try { GlobalSecondaryIndex secIndex = GlobalSecondaryIndex.builder(). indexName(getSharedIndexName()). provisionedThroughput(b -> b.readCapacityUnits(1L).writeCapacityUnits(1L)). projection(Projection.builder().projectionType(ProjectionType.ALL).build()). keySchema(KeySchemaElement.builder().attributeName(Config._APPID).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(Config._ID).keyType(KeyType.RANGE).build()).build(); AttributeDefinition[] attributes = new AttributeDefinition[] { AttributeDefinition.builder().attributeName(Config._KEY).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._APPID).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._ID).attributeType(ScalarAttributeType.S).build() }; CreateTableResponse tbl = getClient().createTable(b -> b.tableName(table). keySchema(KeySchemaElement.builder().attributeName(Config._KEY).keyType(KeyType.HASH).build()). sseSpecification(b2 -> b2.enabled(ENCRYPTION_AT_REST_ENABLED)). attributeDefinitions(attributes). globalSecondaryIndexes(secIndex). provisionedThroughput(b6 -> b6.readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity))); logger.info("Waiting for DynamoDB table to become ACTIVE..."); waitForActive(table); logger.info("Created shared table '{}', status {}.", table, tbl.tableDescription().tableStatus()); } catch (Exception e) { logger.error(null, e); return false; } return true; }
Example #14
Source File: SecondaryIndexesIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Assert the tableDescription is as expected */ @Test public void testDescribeTempTableWithIndexes() { TableDescription tableDescription = dynamo.describeTable(DescribeTableRequest.builder().tableName(tableName).build()).table(); assertEquals(tableName, tableDescription.tableName()); assertNotNull(tableDescription.tableStatus()); assertEquals(2, tableDescription.keySchema().size()); assertEquals(HASH_KEY_NAME, tableDescription.keySchema().get(0) .attributeName()); assertEquals(KeyType.HASH, tableDescription .keySchema().get(0).keyType()); assertEquals(RANGE_KEY_NAME, tableDescription.keySchema() .get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .keySchema().get(1).keyType()); assertEquals(1, tableDescription.localSecondaryIndexes().size()); assertEquals(LSI_NAME, tableDescription .localSecondaryIndexes().get(0).indexName()); assertEquals(2, tableDescription .localSecondaryIndexes().get(0).keySchema().size()); assertEquals(HASH_KEY_NAME, tableDescription .localSecondaryIndexes().get(0).keySchema().get(0).attributeName()); assertEquals(KeyType.HASH, tableDescription .localSecondaryIndexes().get(0).keySchema().get(0).keyType()); assertEquals(LSI_RANGE_KEY_NAME, tableDescription .localSecondaryIndexes().get(0).keySchema().get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .localSecondaryIndexes().get(0).keySchema().get(1).keyType()); assertEquals(ProjectionType.KEYS_ONLY, tableDescription.localSecondaryIndexes().get(0) .projection().projectionType()); assertTrue(tableDescription.localSecondaryIndexes().get(0) .projection().nonKeyAttributes() instanceof SdkAutoConstructList); assertEquals(1, tableDescription.globalSecondaryIndexes().size()); assertEquals(GSI_NAME, tableDescription .globalSecondaryIndexes().get(0).indexName()); assertEquals(2, tableDescription .globalSecondaryIndexes().get(0).keySchema().size()); assertEquals(GSI_HASH_KEY_NAME, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(0).attributeName()); assertEquals(KeyType.HASH, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(0).keyType()); assertEquals(GSI_RANGE_KEY_NAME, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(1).attributeName()); assertEquals(KeyType.RANGE, tableDescription .globalSecondaryIndexes().get(0).keySchema().get(1).keyType()); assertEquals(ProjectionType.KEYS_ONLY, tableDescription.globalSecondaryIndexes().get(0) .projection().projectionType()); assertTrue(tableDescription.globalSecondaryIndexes().get(0) .projection().nonKeyAttributes() instanceof SdkAutoConstructList); }
Example #15
Source File: TempTableWithSecondaryIndexes.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Table schema: * Hash Key : HASH_KEY_NAME (S) * Range Key : RANGE_KEY_NAME (N) * LSI schema: * Hash Key : HASH_KEY_NAME (S) * Range Key : LSI_RANGE_KEY_NAME (N) * GSI schema: * Hash Key : GSI_HASH_KEY_NAME (N) * Range Key : GSI_RANGE_KEY_NAME (N) */ @Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(TEMP_TABLE_NAME) .keySchema( KeySchemaElement.builder() .attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(RANGE_KEY_NAME) .keyType(KeyType.RANGE) .build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName( RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build(), AttributeDefinition.builder().attributeName( LSI_RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build(), AttributeDefinition.builder().attributeName( GSI_HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName( GSI_RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build()) .provisionedThroughput(BasicTempTable.DEFAULT_PROVISIONED_THROUGHPUT) .localSecondaryIndexes( LocalSecondaryIndex.builder() .indexName(LSI_NAME) .keySchema( KeySchemaElement.builder() .attributeName( HASH_KEY_NAME) .keyType(KeyType.HASH).build(), KeySchemaElement.builder() .attributeName( LSI_RANGE_KEY_NAME) .keyType(KeyType.RANGE).build()) .projection( Projection.builder() .projectionType(ProjectionType.KEYS_ONLY).build()).build()) .globalSecondaryIndexes( GlobalSecondaryIndex.builder().indexName(GSI_NAME) .keySchema( KeySchemaElement.builder() .attributeName( GSI_HASH_KEY_NAME) .keyType(KeyType.HASH).build(), KeySchemaElement.builder() .attributeName( GSI_RANGE_KEY_NAME) .keyType(KeyType.RANGE).build()) .projection( Projection.builder() .projectionType(ProjectionType.KEYS_ONLY).build()) .provisionedThroughput( GSI_PROVISIONED_THROUGHPUT).build()) .build(); return createTableRequest; }