• <i id='FPJo3'><tr id='FPJo3'><dt id='FPJo3'><q id='FPJo3'><span id='FPJo3'><b id='FPJo3'><form id='FPJo3'><ins id='FPJo3'></ins><ul id='FPJo3'></ul><sub id='FPJo3'></sub></form><legend id='FPJo3'></legend><bdo id='FPJo3'><pre id='FPJo3'><center id='FPJo3'></center></pre></bdo></b><th id='FPJo3'></th></span></q></dt></tr></i><div id='FPJo3'><tfoot id='FPJo3'></tfoot><dl id='FPJo3'><fieldset id='FPJo3'></fieldset></dl></div>
  • <tfoot id='FPJo3'></tfoot>
    1. <legend id='FPJo3'><style id='FPJo3'><dir id='FPJo3'><q id='FPJo3'></q></dir></style></legend>

        <small id='FPJo3'></small><noframes id='FPJo3'>

          <bdo id='FPJo3'></bdo><ul id='FPJo3'></ul>

        使用 IN 子句查询 DynamoDB

        Query DynamoDB with IN Clause(使用 IN 子句查询 DynamoDB)

          <bdo id='HT5sK'></bdo><ul id='HT5sK'></ul>
          <tfoot id='HT5sK'></tfoot>
            <legend id='HT5sK'><style id='HT5sK'><dir id='HT5sK'><q id='HT5sK'></q></dir></style></legend>

            <small id='HT5sK'></small><noframes id='HT5sK'>

                    <tbody id='HT5sK'></tbody>
                1. <i id='HT5sK'><tr id='HT5sK'><dt id='HT5sK'><q id='HT5sK'><span id='HT5sK'><b id='HT5sK'><form id='HT5sK'><ins id='HT5sK'></ins><ul id='HT5sK'></ul><sub id='HT5sK'></sub></form><legend id='HT5sK'></legend><bdo id='HT5sK'><pre id='HT5sK'><center id='HT5sK'></center></pre></bdo></b><th id='HT5sK'></th></span></q></dt></tr></i><div id='HT5sK'><tfoot id='HT5sK'></tfoot><dl id='HT5sK'><fieldset id='HT5sK'></fieldset></dl></div>

                  本文介绍了使用 IN 子句查询 DynamoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 DynamoDB 的新手,想知道如何使用 Java 在带有 IN 子句的 DynamoDB 中的表上进行查询.

                  I am new to DynamoDB and wanted to know how can we query on a table in DynamoDB with IN clause using Java.

                  我有一个名为 items 的表.它的架构是

                  I have a table named items. It`s schema is

                  1. Product (Partition Key of type String)
                  2. ID (Sort Key of type int)
                  3. Date ( attribute of type String)
                  

                  我想查询类似

                  SELECT ID FROM items WHERE Product IN ("apple","orange"). 
                  

                  SELECT Product FROM items WHERE ID IN (100,200). 
                  

                  推荐答案

                  由于要求是获取没有分区键的产品,有两种选择.

                  As the requirement is to get the products without the partition key, there are two options available.

                  1) 在排序键属性 Id 上创建 GSI(全局二级索引)以使用查询 API

                  1) Create GSI (Global Secondary Index) on sort key attribute Id to use the Query API

                  2) 扫描整个表格以获取产品 - 因为它扫描整个表格效率不高

                  2) Scan the entire table to get the products - not very efficient as it scans the full table

                  这两个选项都使用 DynamoDB 上可用的 IN 运算符.

                  Both the options use the IN operator available on DynamoDB.

                  使用 ID 进行扫描的示例代码:-

                  Map<String, AttributeValue> attributeValues = new HashMap<>();
                  attributeValues.put(":id1", new AttributeValue().withN("100"));
                  attributeValues.put(":id2", new AttributeValue().withN("200"));
                  
                  DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression()
                                                                      .withFilterExpression("ID IN (:id1, :id2)")
                                                                      .withExpressionAttributeValues(attributeValues);
                  
                  
                  PaginatedScanList<yourModelClass> scanList = dynamoDBMapper.scan(yourModelClass.class, dynamoDBScanExpression,
                          new DynamoDBMapperConfig(DynamoDBMapperConfig.ConsistentReads.CONSISTENT));
                  
                  Iterator<yourModelClass> iterator = scanList.iterator();
                  
                  while (iterator.hasNext()) {
                      System.out.println(iterator.next().getTitle());
                  }
                  

                  按产品查询:-

                  1) 不能使用 IN 运算符 作为分区键

                  1) Cannot use IN operator for partition key

                  2) 在不知道排序键的情况下无法使用 batchLoad API

                  2) Cannot use batchLoad API without knowing the sort key

                  结论:-

                  有效的解决方案是在属性 Id 上创建 GSI(不带排序键)并使用 batchLoad API.

                  The efficient solution is to create GSI (without sort key) on attribute Id and use batchLoad API.

                  注意: GSI 的分区键不必唯一

                  Note: The partition key of GSI need not be unique

                  这篇关于使用 IN 子句查询 DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                    <bdo id='UOeyA'></bdo><ul id='UOeyA'></ul>

                            <small id='UOeyA'></small><noframes id='UOeyA'>

                            <tfoot id='UOeyA'></tfoot>
                            <legend id='UOeyA'><style id='UOeyA'><dir id='UOeyA'><q id='UOeyA'></q></dir></style></legend>

                          • <i id='UOeyA'><tr id='UOeyA'><dt id='UOeyA'><q id='UOeyA'><span id='UOeyA'><b id='UOeyA'><form id='UOeyA'><ins id='UOeyA'></ins><ul id='UOeyA'></ul><sub id='UOeyA'></sub></form><legend id='UOeyA'></legend><bdo id='UOeyA'><pre id='UOeyA'><center id='UOeyA'></center></pre></bdo></b><th id='UOeyA'></th></span></q></dt></tr></i><div id='UOeyA'><tfoot id='UOeyA'></tfoot><dl id='UOeyA'><fieldset id='UOeyA'></fieldset></dl></div>

                              <tbody id='UOeyA'></tbody>