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

      • <bdo id='9ccob'></bdo><ul id='9ccob'></ul>
      <tfoot id='9ccob'></tfoot>

      <small id='9ccob'></small><noframes id='9ccob'>

      1. <legend id='9ccob'><style id='9ccob'><dir id='9ccob'><q id='9ccob'></q></dir></style></legend>
      2. 如何在 DynamoDB 中根据 HashKey 和 range Key 进行查询?

        How to do Query in DynamoDB on the basis of HashKey and range Key?(如何在 DynamoDB 中根据 HashKey 和 range Key 进行查询?)
          <tbody id='UntSJ'></tbody>

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

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

                  本文介绍了如何在 DynamoDB 中根据 HashKey 和 range Key 进行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 DynamoDb 的新手.我只想知道如何使用 hashKeyrangeKey 查询 DynamoDB 中的表.

                  I am new to DynamoDb stuff. I just want to know how can we query on a table in DynamoDB with the hashKey and rangeKey.

                  假设我的表是 TestTable,它的架构是这样的:

                  Let's say my Table is TestTable and it's schema is something like this:

                  1.Id (HK of type String)
                  2 Date (RK of type String )
                  3 Name (attribute of type String)
                  

                  现在如果我想根据 hashKey 查询这张表,这里是 Id,我们将 query 设为:

                  Now If I want to query on this table on the basis of hashKey which is Id here, we make a query as :

                  假设我的查询是获取所有具有 Id ="123" 的项目.

                  Let's say my query is to get all Items having Id ="123".

                  TestTable testTable = new TestTable();
                  testTable.setId("123");
                  
                  DynamoDBQueryExpression<TestTable> queryExpression = new DynamoDBQueryExpression<TestTable>()
                                                                                  .withHashKeyValues(TestTable)
                                                                                  .withConsistentRead(false);
                  

                  现在我想获取所有具有 Id ="123" 和 Date ="1234" 的项目.

                  Now I want to get all Items having Id ="123" and Date ="1234".

                  如何在DynamoDB

                  我使用 java 作为我的编程语言.

                  I am using java as my programming language.

                  推荐答案

                  我前段时间写了一篇关于使用 AWS Java SDK 进行 DynamoDB 查询和索引的文章:http://labs.journwe.com/2013/12/15/dynamodb-secondary-indexes/

                  I wrote an article about DynamoDB queries and indexing using the AWS Java SDK some time ago: http://labs.journwe.com/2013/12/15/dynamodb-secondary-indexes/

                  在您的情况下,它应该像这样工作(请参阅 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaQueryScanORMModelExample.html):

                  In your case, it should work like this (see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaQueryScanORMModelExample.html):

                  AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
                  DynamoDBMapper mapper = new DynamoDBMapper(client);
                  
                  String hashKey = "123";
                  long twoWeeksAgoMilli = (new Date()).getTime() - (15L*24L*60L*60L*1000L);
                  Date twoWeeksAgo = new Date();
                  twoWeeksAgo.setTime(twoWeeksAgoMilli);
                  SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                  dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
                  String twoWeeksAgoStr = dateFormatter.format(twoWeeksAgo);            
                  Condition rangeKeyCondition = new Condition()
                          .withComparisonOperator(ComparisonOperator.GT.toString())
                          .withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr.toString()));
                  
                  Reply replyKey = new Reply();
                  replyKey.setId(hashKey);
                  
                  DynamoDBQueryExpression<Reply> queryExpression = new DynamoDBQueryExpression<Reply>()
                          .withHashKeyValues(replyKey)
                          .withRangeKeyCondition("ReplyDateTime", rangeKeyCondition);
                  
                  List<Reply> latestReplies = mapper.query(Reply.class, queryExpression);
                  

                  查看 DynamoDB 文档的 Java 对象持久性模型部分了解更多信息.

                  Check out the Java Object Persistence Model section of the DynamoDB docs for more info.

                  这篇关于如何在 DynamoDB 中根据 HashKey 和 range Key 进行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                      <bdo id='tgzSW'></bdo><ul id='tgzSW'></ul>
                      <legend id='tgzSW'><style id='tgzSW'><dir id='tgzSW'><q id='tgzSW'></q></dir></style></legend>
                      <tfoot id='tgzSW'></tfoot>

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

                      1. <small id='tgzSW'></small><noframes id='tgzSW'>

                          <tbody id='tgzSW'></tbody>