use of software.amazon.awssdk.services.dynamodb.model.Put in project aws-sdk-java-v2 by aws.
the class PutItemOperation method generateTransactWriteItem.
@Override
public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) {
PutItemRequest putItemRequest = generateRequest(tableSchema, operationContext, dynamoDbEnhancedClientExtension);
Put.Builder builder = Put.builder().item(putItemRequest.item()).tableName(putItemRequest.tableName()).conditionExpression(putItemRequest.conditionExpression()).expressionAttributeValues(putItemRequest.expressionAttributeValues()).expressionAttributeNames(putItemRequest.expressionAttributeNames());
request.right().map(TransactPutItemEnhancedRequest::returnValuesOnConditionCheckFailureAsString).ifPresent(builder::returnValuesOnConditionCheckFailure);
return TransactWriteItem.builder().put(builder.build()).build();
}
use of software.amazon.awssdk.services.dynamodb.model.Put in project iceberg by apache.
the class DynamoDbCatalog method renameTable.
@Override
public void renameTable(TableIdentifier from, TableIdentifier to) {
Map<String, AttributeValue> fromKey = tablePrimaryKey(from);
Map<String, AttributeValue> toKey = tablePrimaryKey(to);
GetItemResponse fromResponse = dynamo.getItem(GetItemRequest.builder().tableName(awsProperties.dynamoDbTableName()).consistentRead(true).key(fromKey).build());
if (!fromResponse.hasItem()) {
throw new NoSuchTableException("Cannot rename table %s to %s: %s does not exist", from, to, from);
}
GetItemResponse toResponse = dynamo.getItem(GetItemRequest.builder().tableName(awsProperties.dynamoDbTableName()).consistentRead(true).key(toKey).build());
if (toResponse.hasItem()) {
throw new AlreadyExistsException("Cannot rename table %s to %s: %s already exists", from, to, to);
}
fromResponse.item().entrySet().stream().filter(e -> isProperty(e.getKey())).forEach(e -> toKey.put(e.getKey(), e.getValue()));
setNewCatalogEntryMetadata(toKey);
dynamo.transactWriteItems(TransactWriteItemsRequest.builder().transactItems(TransactWriteItem.builder().delete(Delete.builder().tableName(awsProperties.dynamoDbTableName()).key(fromKey).conditionExpression(COL_VERSION + " = :v").expressionAttributeValues(ImmutableMap.of(":v", fromResponse.item().get(COL_VERSION))).build()).build(), TransactWriteItem.builder().put(Put.builder().tableName(awsProperties.dynamoDbTableName()).item(toKey).conditionExpression("attribute_not_exists(" + COL_VERSION + ")").build()).build()).build());
LOG.info("Successfully renamed table from {} to {}", from, to);
}
Aggregations