我有一个不包含任何唯一键(主键)的数据集。只有当所有行组合在一起时才是唯一的。但是,我在键中给出了第一个属性(类类型),以便在dynamoDB中创建表,如下所示:
CreateTableRequest createTableRequest = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(newKeySchemaElement()
.withAttributeName("Class type")
.withKeyType(KeyType.HASH))
.withAttributeDefinitions(newAttributeDefinition().withAttributeName("Class type").withAttributeType(ScalarAttributeType.S))
...
...;
使用此数据集,PutItem不起作用,因为它将一个属性替换为其他属性,因为“类类型”不是唯一的。我希望将所有行上传到dynamoDB。我的putItem如下所示:
Map<String, AttributeValue> item = newItem(col[0], col[1], col[2], col[3], titanic_col[4]);
PutItemRequest putItemRequest = new PutItemRequest(tableName, item).withConditionExpression("Class type = NULL");
// No error in the above line. But getting exception.
PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
关于条件表达式行的例外情况:
Caught an AmazonServiceException, which means your request made it to AWS, but was rejected with an error response for some reason.
Error Message: Invalid ConditionExpression: Syntax error; token: "type", near: "Class type =" (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: J51GM61PM4AE2HPD0DVMQ6TNU7VV4KQNSO5AEMVJF66Q9ASUAAJG)
HTTP Status Code: 400
AWS Error Code: ValidationException
Error Type: Client
我想知道语法是否正确。如果没有,请提供正确的语法来解决问题(避免替换属性)。
答案 0 :(得分:0)