簡體   English   中英

導入數據時如何在Amazon dynamodb表中添加新字段?

[英]How to add a new field to amazon dynamodb table while importing data?

我正在嘗試使用dynamodb的新查詢過濾器功能。 但是問題是我需要對.net sdk抱怨的范圍鍵屬性進行查詢過濾,“查詢過濾器僅適用於非鍵屬性”。

因此,我決定為具有范圍鍵屬性值的每一行添加一個新字段。

This:
Hash Key  | Range Key
User Id     ContentId

Will become this:
Hash Key  | Range Key  | NewField
User Id     ContentId    ContentIdForQueryFilter
1           1            1
1           2            2
1           3            3

現在,我可以使用哈希和范圍鍵查詢表,並且可以在ContentIdFilter上使用queryfilter,因為ContentIdFilter不是鍵屬性。

我的問題是如何在每行上添加ContentIdForQueryFilter字段和ContentId字段的值? 我應該使用Hive還是Elastic Map Reduce?

我怎樣才能做到這一點?

提前致謝。

如果要使用范圍鍵上的條件進行查詢,則可以設置查詢請求的“ KeyConditions”屬性。

http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-KeyConditions

這是一個Java示例,它對哈希鍵等於“ id_1”且范圍鍵大於或等於3的項目進行查詢

    QueryRequest queryRequest = new QueryRequest();
    queryRequest.setTableName("Query");
    queryRequest.addKeyConditionsEntry("Hash", new Condition().withAttributeValueList(new AttributeValue("id_1")).withComparisonOperator(ComparisonOperator.EQ));
    queryRequest.addKeyConditionsEntry("Range", new Condition().withAttributeValueList(new AttributeValue("3")).withComparisonOperator(ComparisonOperator.GE));

    QueryResult result = dynamo.query(queryRequest);
    for(Map<String, AttributeValue> item : result.getItems()) {
        System.out.println(item);
    }

從文檔看來,關鍵條件支持范圍鍵上的以下比較器:

情商| LE | LT | GE | GT | BEGINS_WITH | 之間

這足以滿足您的用例嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM