我正在使用C中的aws-dynamo库执行以下dynamoDB查询参数。
{ "TableName": "table4", "KeyConditionExpression": "#yr = :yyyy and ts between :letter1 and :letter2", "ExpressionAttributeNames": { "#yr": "userid" }, "ExpressionAttributeValues": { ":yyyy": "abc", ":letter1": 1, ":letter2": 2 } }
但我收到了错误
"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value null at 'hashKeyValue' failed to satisfy constraint: Member must not be null"
这是我的表结构
table4
{
"Table": {
"TableSizeBytes": 66,
"KeySchema": [
{
"AttributeName": "userid",
"KeyType": "HASH"
},
{
"AttributeName": "ts",
"KeyType": "RANGE"
}
],
"CreationDateTime": 1464617195.039,
"ItemCount": 3,
"AttributeDefinitions": [
{
"AttributeName": "ts",
"AttributeType": "N"
},
{
"AttributeName": "userid",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1,
"LastDecreaseDateTime": 1464683346.007,
"NumberOfDecreasesToday": 1
},
"TableStatus": "ACTIVE",
"TableName": "table4",
"TableArn": "arn:aws:dynamodb:us-east-1:456456456:table/table4"
}
}
答案 0 :(得分:0)
分区键必须在keyconditionexpression中。请包含分区键并尝试。查询dynamodb时,必须使用分区键。扫描dynamodb时,分区键是可选的。这是dynamodb中查询与扫描之间的主要区别。
答案 1 :(得分:0)
这是工作查询和表格结构。
{ TableName: 'table4',
KeyConditionExpression: '#userid = :userid AND #ts between :ts1 AND :ts2',
ExpressionAttributeNames: { '#userid': 'userid', '#ts': 'ts' },
ExpressionAttributeValues: { ':userid': 'user1', ':ts1': 1, ':ts2': 2 } }
查询输出: -
{"userid":{"S":"user1"},"ts":{"N":"1"}}
表格结构: -
{"Table":{"AttributeDefinitions":
[{"AttributeName":"userid","AttributeType":"S"},
{"AttributeName":"ts","AttributeType":"N"}],
"TableName":"table4","KeySchema":
[{"AttributeName":"userid","KeyType":"HASH"},{"AttributeName":"ts","KeyType":"RANGE"}],
"TableStatus":"ACTIVE",
"CreationDateTime":"2016-05-31T12:46:08.351Z",
"ProvisionedThroughput":{"LastIncreaseDateTime":"1970-01-01T00:00:00.000Z","LastDecreaseDateTime":"1970-01-01T00:00:00.000Z","NumberOfDecreasesToday":0,
"ReadCapacityUnits":10,"WriteCapacityUnits":10},
"TableSizeBytes":15,"ItemCount":1,"TableArn":
"arn:aws:dynamodb:ddblocal:000000000000:table/table4"}}