简体   繁体   English

过滤 Dynamo DB 行

[英]Filter Dynamo DB rows

I want to filter all dynamo db rows where 2 columns have same value我想过滤所有 dynamo db 行,其中 2 列具有相同的值

 table = client.Table('XXX')
   response = table.query(
   KeyConditionExpression=Key('column1').eq(KeyConditionExpression=Key('column2'))
 )

this is wrong as we can't pass KeyConditionExpression inside eq statement.这是错误的,因为我们不能在 eq 语句中传递 KeyConditionExpression。 I don't want to scan through all the rows and filter the rows.我不想扫描所有行并过滤行。

Scanned through multipole resources and answers but every resources talks about the multiple column checking with some value not multiple condition involving columns通过多极资源和答案进行扫描,但每个资源都谈到了多列检查,其中包含一些值而不是涉及列的多个条件

Is there anyway we can achieve this?无论如何我们可以做到这一点吗?

Yes, this is possible.是的,这是可能的。

If you want query over all records you need to use scan , if you want to query only records with one specific partition key you can use query .如果要查询需要使用的所有记录scan ,如果只想查询具有特定分区键的记录,则可以使用query

For both you can use a FilterExpression , which will filter the records after retrieving them from the database, but before returning them to the user (so beware, using a scan with this will read all your records).对于这两者,您都可以使用FilterExpression ,它将在从数据库中检索记录后过滤记录,但在将它们返回给用户之前(因此请注意,使用扫描将读取您的所有记录)。

A scan from the CLI could look like this:来自 CLI 的扫描可能如下所示:

aws dynamodb scan \
    --table-name your-table \
    --filter-expression "#i = #j" \
    --expression-attribute-names '{"#i": "column1", "#j": "column2"}'

Create a Global Secondary Index with a partition key of 'Column1Value#Column2Value'创建分区键为“Column1Value#Column2Value”的全局二级索引

Then it's simply a matter of querying the GSI.然后只需查询 GSI 即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM