仅使用 hashKey 查询 dynamoDB

2024-02-11

我想仅使用 Hashkey 查询我的 dynamoDB。 我的表(名称= testTable)架构如下:

  • 字符串自动ID(HashKey)
  • 字符串 AlexandriaID (RangeKey)
  • 字符串文档类型

我的 dynamoDBQueryExpression 是:


String hashKey = "dummyHashKey";

testTable hashKeyValues = new testTable();

hashKeyValues.setAutoID(hashKey);

DynamoDBQueryExpression<testTable> queryExpression = new DynamoDBQueryExpression<testTable>();
queryExpression.withHashKeyValues(hashKeyValues);

//Assuming I have a dynamoDBMapper object mapper

List<testTable> docList = mapper.query(testTable.class, queryExpression);

我期待一个具有相同 autoID 的 testTable 对象列表。由于我是新手,如果我错了,请纠正我。

当我做的时候什么也没有发生mapper.query() call.

参考 Vikdor 在 StackOverflow 问题上的评论在 dynamoDB 中使用 hashKey 进行查询 https://stackoverflow.com/questions/30969594/query-all-items-in-dynamodb-from-a-given-hash-key-with-a-hash-range-schema-using

进一步编辑:

我的确切查询方法:

public void queryFromRFIDocumentDetails(String hashKey){
    System.out.println((new Throwable()).getStackTrace()[0].toString() + "***Enter***");

    testTable hashKeyValues = new testTable();
    hashKeyValues.setAutoID(hashKey);

    System.out.println("AutoID for hashKeyValues " + hashKeyValues.getAutoID());
    System.out.println("DocTYpe for hashKeyValues " + hashKeyValues.getDocType());
    System.out.println("AlexandriaID for hashKeyValues " + hashKeyValues.getAlexandraiID());

    DynamoDBQueryExpression<testTable> queryExpression = new DynamoDBQueryExpression<testTable>();
    queryExpression.withHashKeyValues(hashKeyValues);
    queryExpression.withConsistentRead(false);

    System.out.println("calling mapper.query");  //nothing happens after this

    List<testTable> docList = new ArrayList<testTable>();
    docList = mapper.query(testTable.class, queryExpression);

    for(int i=0; i<docList.size(); i++){
        System.out.println("***iterating at retrieved index " + i);
        System.out.println("AutoID for retrieved document " + docList.get(i).getAutoID());
        System.out.println("DocTYpe for retrieved document " + docList.get(i).getDocType());
        System.out.println("AlexandriaID for retrieved document " + docList.get(i).getAlexandraiID());
    }
}

我的程序的堆栈跟踪:

调用方法保存表中的对象:

***iterating at index 0
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id1
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] ***iterating at index 1
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id2
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] ***iterating at index 2
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id3
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] hashKey is abc

根据autoID查询表的调用方法:

[java] com.amazon.sduservice.db.dynamoDB.queryFromRFIDocumentDetails(dynamoDB.java:207)***Enter***
[java] AutoID for hashKeyValues abc
[java] DocTYpe for hashKeyValues null
[java] AlexandriaID for hashKeyValues null
[java] calling mapper.query

扫描表上的操作输出:

Scanning Table RFIDocumentDetails
 [java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id1,}}
 [java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id2,}}
 [java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id3,}}
 [java] {docType={S: pdf,}, autoID={S: HashKey,}, alexandriaID={S: alexandriaID1,}}
 [java] {docType={S: pdf,}, autoID={S: HashKey,}, alexandriaID={S: alexandriaID2,}}
 [java] {docType={S: foo,}, autoID={S: asdf,}, alexandriaID={S: id1,}}
 [java] {docType={S: foo,}, autoID={S: asdf,}, alexandriaID={S: id2,}}
 [java] {docType={S: foo,}, autoID={S: foo,}, alexandriaID={S: id1,}}
 [java] {docType={S: foo,}, autoID={S: foo,}, alexandriaID={S: id2,}}
 [java] Scanning Table Finishes 

测试表类:

public class testTable {    
   private String autoID;   
   private String docType;  
   private String alexandriaID;     

   @DynamoDBHashKey(attributeName="autoID") 
   public String getAutoID(){   return autoID;} 
   public void setAutoID(String autoID){    this.autoID = autoID;}      

   @DynamoDBRangeKey(attributeName="alexandriaID")  
   public String getAlexandraiID(){ return alexandriaID;}   
   public void setAlexandriaID(String alexandriaID){    this.alexandriaID = alexandriaID;}      

   @DynamoDBAttribute(attributeName="docType")  
   public String getDocType(){  return docType;}    
   public void setDocType(String docType){  this.docType = docType;}    

}

正如所讨论的,问题似乎出在 getAlexandraiID 声明中。

请更改方法名称,如下所述:-

From:-

public String getAlexandraiID(){ return alexandriaID;} 

To:-

@DynamoDBRangeKey(attributeName = "alexandriaID")
public String getAlexandriaID() {
    return alexandriaID;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅使用 hashKey 查询 dynamoDB 的相关文章

随机推荐

  • 从 PHP 脚本运行 PHP 脚本而不阻塞

    我正在构建一个蜘蛛 它将遍历各个站点并对它们进行数据挖掘 由于我需要单独获取每个页面 这可能需要很长时间 可能 100 页 我已经将 set time limit 设置为每页 2 分钟 但 apache 似乎无论如何都会在 5 分钟后杀死脚
  • Firebase函数:支持跨函数的全局变量

    我想在 http firebase 函数中缓存最近的记录 比如最近 24 小时 在 http firebase 函数 例如 fetchLastXRecords 中 我在缓存 定义的全局变量来存储记录 中查找记录 如果找不到 则从数据库中获取
  • pandas KeyError,使用浮点数时找不到索引

    我遇到以下问题 import pandas as pd import numpy as np df pd DataFrame np random rand 401 index np linspace 0 1 401 print np lin
  • 通过VBA插入Excel公式

    作为另一个问题的延续 我试图解决通过 VBA 在宏上插入公式的问题 这是我的代码 Range F1 Select ActiveCell Formula IF C1 LPPD MIPRU IF C1 LPGR DCT IF OR C1 LPF
  • Grails 中具有一个域类的依赖下拉菜单

    因此 我有一个域类 它有很多字段 我在 GSP 中准备了五个下拉菜单 并且数据在任何下拉菜单的 onChange 上正确过滤 但存在问题 对于在下拉列表中选择的几组组合 我们在数据库中没有数据 并且这些组合不是固定的 所以 我在想是否有可能
  • 如何将 asp:SiteMapPath 的输出转换为列表?

    我对 NET 和 VB NET 都非常不熟悉 不太清楚如何做到这一点 假设我有这样的代码 div class breadcrumb div
  • WPF 在 InitializeComponent 期间获取 Control null 引用

    So my InitializeComponentWindow 构造函数中的方法调用通过 XML 运行并添加控件并将它们插入到事件中 因此 当其中一个控件的属性发生更改时 它会调用订阅该事件的方法 该方法引用尚未构建的控件 为什么这里会按这
  • 如何在c中绘制直方图

    如何在 c 中从 2 个数组绘制直方图 您可以用这个字符 来表示图表中的计数 这是一个可以打印的字符 printf c char 254u 考虑一些随机的float arr and hist保存计数的数组 Code Function gen
  • 越野车弹跳球

    我在处理中制作碰撞球草图时 遇到了一个奇怪的错误 尽管有从墙上弹起的条件 有些球粘在上面 我在这里找不到错误的根源 有人可以帮忙吗 我还意识到可能很少 很多 糟糕的编码实践 但我事先道歉 我在下面发布代码 1 主要 https pasteb
  • Webpack / ES6:如何导入样式表

    我看到像 bootstrap 这样的存储库开始在它们的中包含额外的标签package json 文件 例如 style 和 less https github com twbs bootstrap blob v4 0 0 alpha 2 p
  • 在文本区域“内部”加粗文本

    我有一个文本区域 myarea我正在其中输入文本 我已经输入了这段文字 这是一个句子 只有这个词 最终会被加粗 现在我的侧面有一个按钮 就像一个粗体按钮 我想选择想要加粗的字母 单击按钮 然后看到这些字母在文本区域内变成粗体 它与许多编辑器
  • UITableViewCell - 如何在重用之前重置内容

    有一个烦人的错误我无法修复 我有一个CustomCell 其中我有一个子视图 可以根据对象的值更改其颜色 UITableViewCell tableView UITableView tableView cellForRowAtIndexPa
  • 如何使用 jQuery 选择的插件重置表单?

    我有一堆select元素的形式为我正在使用 Jquery Chosen 插件 https github com harvesthq chosen 如何重置表格 以下不起作用
  • Three.js 图块具有使用平面几何的多个纹理

    所以我正在尝试构建一个由图块组成的基于 3D 的世界 我已经成功地使用平面几何和高度值等做到了这一点 但现在我已经到了我可能必须改变一切的地步 问题是我希望一个图块具有多个纹理 使用着色器 因为我想混合它们 我能够在全球范围内执行此操作 因
  • 获取任意变换的 MatrixTransform

    我在 WPF 堆栈中工作 我希望能够为任何 Transform 获取 MatrixTransform 根据链接here http msdn microsoft com en us library system windows media t
  • Swing 数据绑定框架

    几乎同样的问题被问过year ago https stackoverflow com questions 510655 jgoodies binding vs jsr 295 但是这方面已经有了一些新的发展 为 Swing 应用程序选择一个
  • 尝试获取 PDO 中非对象的属性

    首先 我知道这可能是一个重复的问题 但我做了一些搜索 例如这个问题 https stackoverflow com questions 5891911 trying to get property of non object in但我不明白
  • 将 xml 转换为 json 以将文件处理为 Bigquery

    我想将 stackexchange 原始数据处理到 BigQuery 中 但首先数据使用 7z 压缩格式 因此我解压缩数据以将其移植为 gz 格式 但内部文件是 xml 所以我需要将文件从 xml 转换为 json 有任何想法吗 我使用 p
  • 我如何使用 Objective C 中的照片框架从图库访问照片

    我是照片框架的新手 我不知道如何使用它 我使用了很多链接 但我很困惑如何在 imageview 中显示图像 我想使用我正在尝试的照片框架从图库中获取所有照片 NSMutableOrderedSet recentsDataSource PHF
  • 仅使用 hashKey 查询 dynamoDB

    我想仅使用 Hashkey 查询我的 dynamoDB 我的表 名称 testTable 架构如下 字符串自动ID HashKey 字符串 AlexandriaID RangeKey 字符串文档类型 我的 dynamoDBQueryExpr