gpt4 book ai didi

ios - 全局二级索引的 DynamoDB 查询 BETWEEN 不起作用(ObjectiveC)

转载 作者:行者123 更新时间:2023-11-28 22:19:14 26 4
gpt4 key购买 nike

我的 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”,效果很好。

任何想法表示赞赏...

最佳答案

遗憾的是,您不能在 HASH 上使用 BETWEEN

来自documentation :

For a query on an index, you can only have conditions on the index key attributes. You must specify the index hash attribute name and value as an EQ condition. You can optionally specify a second condition, referring to the index key range attribute.

关于ios - 全局二级索引的 DynamoDB 查询 BETWEEN 不起作用(ObjectiveC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com