简体   繁体   English

导入数据时如何在Amazon dynamodb表中添加新字段?

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

I am trying to use the new query filter feature of dynamodb. 我正在尝试使用dynamodb的新查询过滤器功能。 But the problem is i need to query filter on the range key attribute which .net sdk complains about "query filter only works on non-key attributes". 但是问题是我需要对.net sdk抱怨的范围键属性进行查询过滤,“查询过滤器仅适用于非键属性”。

So i decided to add a new field to each row which has the value of range key attribute. 因此,我决定为具有范围键属性值的每一行添加一个新字段。

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

Now i can query the table with Hash and Range Key and i can use queryfilter on ContentIdFilter because ContentIdFilter isnt a key attribute. 现在,我可以使用哈希和范围键查询表,并且可以在ContentIdFilter上使用queryfilter,因为ContentIdFilter不是键属性。

My question is how can i add ContentIdForQueryFilter field with the value of ContentId field on each row? 我的问题是如何在每行上添加ContentIdForQueryFilter字段和ContentId字段的值? Should i use Hive or Elastic Map Reduce? 我应该使用Hive还是Elastic Map Reduce?

How can i achieve this? 我怎样才能做到这一点?

Thanks in advance. 提前致谢。

If you want to query with conditions on the range key, you can set the "KeyConditions" property of your query request. 如果要使用范围键上的条件进行查询,则可以设置查询请求的“ KeyConditions”属性。

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

Here is a java example that does a query on items with hash key equals to "id_1" and range key greater or equal to 3 这是一个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);
    }

from the doc it seems key condition supports the following comparator on range key: 从文档看来,关键条件支持范围键上的以下比较器:

EQ | 情商| LE | LE | LT | LT | GE | GE | GT | GT | BEGINS_WITH | BEGINS_WITH | BETWEEN 之间

is that enough for your usecase? 这足以满足您的用例吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM