如何从DynamoDB(; PHP的iOS&AMP)得到行数?行数、PHP、DynamoDB、AMP

由网友(指尖落樱舞)分享简介:我需要查询一个DynamoDB表获取行的数量有所帮助。I need help with querying a DynamoDB table to get the count of rows.考虑,我有一个表用户有三个字段,用户名,密码和用户类型。用户类型可以是管理员,雇员或@客人。现在,我想获得的管理伯爵表中。在S...

我需要查询一个DynamoDB表获取行的数量有所帮助。

I need help with querying a DynamoDB table to get the count of rows.

考虑,我有一个表用户有三个字段,用户名,密码和用户类型。用户类型可以是管理员,雇员或@客人。现在,我想获得的管理伯爵表中。在SQL中,我们写这样的查询,

Consider, I have a table "Users" with three fields, "UserName", "Password" and "UserType". UserType can be "Admin", "Employee" or @"Guest". Now I want to get the count of "Admin" in the table. In SQL we write the query like this,

SELECT COUNT(*) FROM Users WHERE UserType='Admin'

现在我需要做同样的使用DynamoDB的iOS SDK。现在,我这样做是这样的。

Now I need to do the same using DynamoDB iOS SDK. For now, I am doing it like this.

- (int)adminUsersCount {
    DynamoDBScanRequest *request = [[[DynamoDBScanRequest alloc] initWithTableName:@"Users"] autorelease];
    DynamoDBCondition *condition = [[[DynamoDBCondition alloc] init] autorelease];
    NSMutableArray *attrList = [NSMutableArray arrayWithObject:[[[DynamoDBAttributeValue alloc] initWithS:@"Admin"]] autorelease]];
    condition.attributeValueList = attrList;
    condition.comparisonOperator = @"EQ";
    [request setScanFilterValue:condition forKey:@"UserType"];
    DynamoDBScanResponse *response = [[AmazonClientManager ddb] scan:request];
    return response.items.count;
}

我在这里取的所有行知道计数。我知道这是不正确的做法,是一个真正的坏主意。我不知道怎么去计数单独运行,免去所有行。

Here I am fetching all the rows to know that count. I know this is not the right way and is really a bad idea. I don't know how to get the count alone without fetching all the rows.

我想知道如何做到这一点的的iOS SDK。 我想知道如何做到这一点在PHP SDK为好。

感谢。

推荐答案

我不能为PHP也不IOS SDK回答,因为我用都没有(我使用Python)的。但是,从低水平DynamoDB点:

I can not answer for PHP nor IOS SDK since I use neither of them (I use Python). But, from a low level DynamoDB point of view:

如果所有用户都管理员,您可以使用 ItemCount中 DescribeTable 。它只是更新,每6个小时,但它是免费的 如果用户类型 range_key (外观极好),你可以设置计数参数查询然后读计数答案的领域。 在其他情况下(坏的),使用扫描,你会与查询连同你的筛选条件。 If all users are admin, you can use ItemCount from DescribeTable. It is updated only every 6 hours but it's free If UserType is the range_key (excelent), you can set Count param of Query to True then read Count field of the answer. In all other cases (bad), use Scan as you would with Query along with your filter condition.

这表示,查询扫描将始终返回的项目计数。该计数参数只指示他们不要返回真实的项目。请注意,它仅有备用带宽。这不会是任何更快,也更便宜的供应吞吐量方面。

This said, Query and Scan will always return the the item count. The Count param only instruct them not to return the real items. Please note that it only spares bandwidth. It won't be any faster nor be cheaper in terms of provisioned throughput.

如果你是在第三的情况下,我建议你重新设计你的,你的模式,因为这将是的非常的速度慢,价格昂贵。在所有的请求,则需要通过整个表。

If you are in the 3rd case, I suggest you re-engineer your you schema as it would be very slow and expensive. At all requests, you will need to go through the entire table.

阅读全文

相关推荐

最新文章