Amazon web services 如何在导入数据时向amazon dynamodb表添加新字段?
我正在尝试使用dynamodb的新查询过滤器特性。但问题是我需要对range key属性进行查询筛选,.NETSDK抱怨“查询筛选只对非key属性有效” 因此,我决定在每一行中添加一个新字段,该字段的值为range key属性Amazon web services 如何在导入数据时向amazon dynamodb表添加新字段?,amazon-web-services,amazon-dynamodb,Amazon Web Services,Amazon Dynamodb,我正在尝试使用dynamodb的新查询过滤器特性。但问题是我需要对range key属性进行查询筛选,.NETSDK抱怨“查询筛选只对非key属性有效” 因此,我决定在每一行中添加一个新字段,该字段的值为range key属性 This: Hash Key | Range Key User Id ContentId Will become this: Hash Key | Range Key | NewField User Id ContentId ContentI
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不是键属性
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
我的问题是,如何在每行添加ContentId字段值为的ContentIdForQueryFilter字段?我应该使用蜂巢还是弹性贴图
我怎样才能做到这一点
提前感谢。如果要使用范围键上的条件进行查询,可以设置查询请求的“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);
}
QueryRequest QueryRequest=new QueryRequest();
queryRequest.setTableName(“查询”);
queryRequest.addKeyConditionsEntry(“哈希”,new Condition()。带有AttributeValue列表(new AttributeValue(“id_1”))。带有ComparisonOperator(ComparisonOperator.EQ));
queryRequest.addKeyConditionsEntry(“范围”,新条件()。带有AttributeValue列表(新AttributeValue(“3”))。带有ComparisonOperator(ComparisonOperator.GE));
QueryResult结果=dynamo.query(queryRequest);
对于(映射项:result.getItems()){
系统输出打印项次(项);
}
从文档中可以看出,key condition在范围键上支持以下比较器:
等式| LE | LT | GE | GT |以|之间开始
这对于您的用例来说够了吗?嗨,谢谢您的回答,但这不是关于我的问题。我的问题是,在将数据导入dynamodb表时,如何向每行添加一个新字段。谢谢。您想添加一个新列,因为您需要对范围键进行筛选。上面描述了对范围键进行过滤的属性方法。这是一个比添加包含重复数据的新列更简单、更便宜的解决方案。如果确实要添加新列,可以使用并行扫描+更新项。并行扫描允许您使用多个线程并行扫描表的不同段。对于扫描返回的每个结果,您都会执行一个updateItem,它会使用与范围键相同的数据添加新字段。我再次不推荐这种方法,因为1)它很昂贵(重复数据,整表扫描)2)它需要额外的开发时间