【问题标题】:DynamoDB fetch queryDynamoDB 获取查询
【发布时间】:2017-01-12 17:31:46
【问题描述】:
@DynamoDBTable(tableName = "OrderDashboardMetadata")
public class OrderDashBoardMetaData {

private int position;
private Date ETA = null;
private List<String> notes;

@DynamoDBHashKey(attributeName = "queueName")
private String queueName;

@DynamoDBRangeKey(attributeName = "orderId")
private String orderId;

@DynamoDBIndexHashKey(globalSecondaryIndexName = "city")
private String city;

@DynamoDBIndexRangeKey(globalSecondaryIndexName = "city")
private String fcId;

@DynamoDBIndexHashKey(globalSecondaryIndexName = "orderState")
private String orderState;

@DynamoDBAttribute(attributeName = "action")
private String action;

@DynamoDBAttribute(attributeName = "createdTime")
private Date createdTime = new Date();

@DynamoDBAttribute(attributeName = "updatedTime")
private Date updatedTime = new Date();

我有一个像上面那样的表结构。 什么是查询以获取仅具有的结果

1) 队列名 --> PFS
2) ETA --> 大于 2017 年 1 月 1 日
3)订单状态——PO

请建议在 JAVA 中对上述场景进行完整查询。

【问题讨论】:

    标签: java amazon-dynamodb


    【解决方案1】:

    由于你没有注释所以假设 ETA 也是一个 DDBAttribute

     Map<String, AttributeValue> expValues = new HashMap<>();
     expValues.put(":hv", new AttributeValue("PFS"));
     expValues.put(":osv", new AttributeValue("PO"));
     expValues.put(":etav", new AttributeValue("2017-01-01"));
    
     QueryRequest q = new QueryRequest("OrderDashboardMetadata");
     q.setKeyConditionExpression("queueName = :hv");
     q.setFilterExpression("orderState = :osv and ETA > :etav");
     q.setExpressionAttributeValues(expValues);
     QueryResult r = dbClient.query(q);
    

    注意:日期存储为 S(字符串类型)。日期值存储为 ISO-8601 格式的字符串。

    【讨论】:

    • 点赞和接受是表达感谢的好方法,也会帮助其他人。
    猜你喜欢
    • 2014-12-18
    • 2020-07-26
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2021-09-05
    • 2020-07-02
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多