Search in sources :

Example 1 with Put

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();
}
Also used : PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) Put(software.amazon.awssdk.services.dynamodb.model.Put)

Example 2 with Put

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);
}
Also used : AlreadyExistsException(org.apache.iceberg.exceptions.AlreadyExistsException) CatalogUtil(org.apache.iceberg.CatalogUtil) LoggerFactory(org.slf4j.LoggerFactory) TableMetadata(org.apache.iceberg.TableMetadata) CatalogProperties(org.apache.iceberg.CatalogProperties) TableOperations(org.apache.iceberg.TableOperations) Lists(org.apache.iceberg.relocated.com.google.common.collect.Lists) NoSuchNamespaceException(org.apache.iceberg.exceptions.NoSuchNamespaceException) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) NamespaceNotEmptyException(org.apache.iceberg.exceptions.NamespaceNotEmptyException) GlobalSecondaryIndex(software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex) Configurable(org.apache.hadoop.conf.Configurable) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) ScalarAttributeType(software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) TableStatus(software.amazon.awssdk.services.dynamodb.model.TableStatus) TransactWriteItemsRequest(software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsRequest) ProjectionType(software.amazon.awssdk.services.dynamodb.model.ProjectionType) CloseableGroup(org.apache.iceberg.io.CloseableGroup) KeyType(software.amazon.awssdk.services.dynamodb.model.KeyType) Set(java.util.Set) S3FileIO(org.apache.iceberg.aws.s3.S3FileIO) QueryResponse(software.amazon.awssdk.services.dynamodb.model.QueryResponse) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Put(software.amazon.awssdk.services.dynamodb.model.Put) List(java.util.List) AwsClientFactories(org.apache.iceberg.aws.AwsClientFactories) PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DeleteItemRequest(software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest) QueryRequest(software.amazon.awssdk.services.dynamodb.model.QueryRequest) DescribeTableResponse(software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) ImmutableMap(org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap) GetItemRequest(software.amazon.awssdk.services.dynamodb.model.GetItemRequest) UpdateItemRequest(software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest) BaseMetastoreCatalog(org.apache.iceberg.BaseMetastoreCatalog) CreateTableRequest(software.amazon.awssdk.services.dynamodb.model.CreateTableRequest) Namespace(org.apache.iceberg.catalog.Namespace) SupportsNamespaces(org.apache.iceberg.catalog.SupportsNamespaces) Logger(org.slf4j.Logger) TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Maps(org.apache.iceberg.relocated.com.google.common.collect.Maps) IOException(java.io.IOException) AttributeDefinition(software.amazon.awssdk.services.dynamodb.model.AttributeDefinition) Joiner(org.apache.iceberg.relocated.com.google.common.base.Joiner) ResourceNotFoundException(software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException) ValidationException(org.apache.iceberg.exceptions.ValidationException) Delete(software.amazon.awssdk.services.dynamodb.model.Delete) KeySchemaElement(software.amazon.awssdk.services.dynamodb.model.KeySchemaElement) BillingMode(software.amazon.awssdk.services.dynamodb.model.BillingMode) Tasks(org.apache.iceberg.util.Tasks) Projection(software.amazon.awssdk.services.dynamodb.model.Projection) Closeable(java.io.Closeable) Preconditions(org.apache.iceberg.relocated.com.google.common.base.Preconditions) GetItemResponse(software.amazon.awssdk.services.dynamodb.model.GetItemResponse) AwsProperties(org.apache.iceberg.aws.AwsProperties) DescribeTableRequest(software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest) FileIO(org.apache.iceberg.io.FileIO) VisibleForTesting(org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) AlreadyExistsException(org.apache.iceberg.exceptions.AlreadyExistsException) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) GetItemResponse(software.amazon.awssdk.services.dynamodb.model.GetItemResponse)

Aggregations

Put (software.amazon.awssdk.services.dynamodb.model.Put)2 PutItemRequest (software.amazon.awssdk.services.dynamodb.model.PutItemRequest)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Configurable (org.apache.hadoop.conf.Configurable)1 Configuration (org.apache.hadoop.conf.Configuration)1 BaseMetastoreCatalog (org.apache.iceberg.BaseMetastoreCatalog)1 CatalogProperties (org.apache.iceberg.CatalogProperties)1 CatalogUtil (org.apache.iceberg.CatalogUtil)1 TableMetadata (org.apache.iceberg.TableMetadata)1 TableOperations (org.apache.iceberg.TableOperations)1 AwsClientFactories (org.apache.iceberg.aws.AwsClientFactories)1 AwsProperties (org.apache.iceberg.aws.AwsProperties)1 S3FileIO (org.apache.iceberg.aws.s3.S3FileIO)1 Namespace (org.apache.iceberg.catalog.Namespace)1