DynamoDB查询全局二级索引的BETWEEN不起作用(目标C)

时间:2013-12-29 15:00:31

标签: ios amazon-dynamodb

我的DynamoDB查询返回“不支持查询密钥条件”。

NSMutableDictionary * conditions = [[NSMutableDictionary alloc] init];

DynamoDBCondition * googleConditionLat = [[DynamoDBCondition alloc] init];
googleConditionLat.comparisonOperator = @"BETWEEN";
DynamoDBAttributeValue * googleIDAttributeLat1 = [[DynamoDBAttributeValue alloc] initWithN:[NSString stringWithFormat:@"%f", location.coordinate.latitude - 0.0005]];
[googleConditionLat addAttributeValueList:googleIDAttributeLat1];
DynamoDBAttributeValue * googleIDAttributeLat2 = [[DynamoDBAttributeValue alloc] initWithN:[NSString stringWithFormat:@"%f", location.coordinate.latitude + 0.0005]];
[googleConditionLat addAttributeValueList:googleIDAttributeLat2];
[conditions setObject:googleConditionLat forKey:kLatitudeKey];

#if 1
DynamoDBCondition * googleConditionLong = [[DynamoDBCondition alloc] init];
googleConditionLong.comparisonOperator = @"BETWEEN";
DynamoDBAttributeValue * googleIDAttributeLong1 = [[DynamoDBAttributeValue alloc] initWithN:[NSString stringWithFormat:@"%f", location.coordinate.longitude - 0.0005]];
[googleConditionLong addAttributeValueList:googleIDAttributeLong1];
DynamoDBAttributeValue * googleIDAttributeLong2 = [[DynamoDBAttributeValue alloc] initWithN:[NSString stringWithFormat:@"%f", location.coordinate.longitude + 0.0005]];
[googleConditionLong addAttributeValueList:googleIDAttributeLong2];
[conditions setObject:googleConditionLong forKey:kLongitudeKey];
#endif

NSMutableDictionary *queryStartKey = [[NSMutableDictionary alloc] init];;
do
{
    DynamoDBQueryRequest *queryRequest = [[DynamoDBQueryRequest alloc] init];
    queryRequest.tableName = PLACE_TABLE_NAME;
    queryRequest.exclusiveStartKey = queryStartKey;
    queryRequest.keyConditions = conditions;
    queryRequest.consistentRead = false;
    queryRequest.indexName = @"lat-long-global-index";

    @try
    {
        DynamoDBQueryResponse *queryResponse = [[AmazonClientManager ddb] query:queryRequest];

我的全球二级索引是:

Index Name: lat-long-global-index Hash Key:lat (Number) Range Key:long (Number)

我在GSI上对同一个表有一个非常相似的查询,其中一个字符串哈希键使用“EQ”,工作正常。

任何想法都赞赏......

2 个答案:

答案 0 :(得分:2)

可悲的是,你不能在HASH上使用BETWEEN

来自documentation

  

对于索引的查询,您只能对索引键有条件   属性。 您必须指定索引哈希属性名称和值   作为EQ条件。您可以选择指定第二个条件,   引用索引键范围属性。

答案 1 :(得分:0)

通过在AWS控制台上尝试查询解决了这个问题。看起来您无法检查第一个键上的一系列值 - 它是与主哈希键相同的哈希键。

需要重新设计表格......