如何修改此 Mapreduce 代码以更改实体的命名空间?
我正在使用 Ikai Lan 创建的映射器:
package com.ikai.mapperdemo.mappers;
import java.util.Date;
import java.util.logging.Logger;
import org.apache.hadoop.io.NullWritable;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.tools.mapreduce.AppEngineMapper;
import com.google.appengine.tools.mapreduce.DatastoreMutationPool;
/**
*
* The functionality of this is exactly the same as in {@link NaiveToLowercaseMapper}.
* The advantage here is that since a {@link DatastoreMutationPool} is used, mutations
* can be done in batch, saving API calls.
*
* @author Ikai Lan
*
*/
public class PooledToLowercaseMapper extends
AppEngineMapper<Key, Entity, NullWritable, NullWritable> {
private static final Logger log = Logger
.getLogger(PooledToLowercaseMapper.class.getName());
@Override
public void map(Key key, Entity value, Context context) {
log.info("Mapping key: " + key);
if (value.hasProperty("comment")) {
String comment = (String) value.getProperty("comment");
comment = comment.toLowerCase();
value.setProperty("comment", comment);
value.setProperty("updatedAt", new Date());
DatastoreMutationPool mutationPool = this.getAppEngineContext(
context).getMutationPool();
mutationPool.put(value);
}
}
}
除了上述之外,我还想做的是更改正在修改的实体的数据存储命名空间。
这怎么可能?
I'm using this mapper created by Ikai Lan:
package com.ikai.mapperdemo.mappers;
import java.util.Date;
import java.util.logging.Logger;
import org.apache.hadoop.io.NullWritable;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.tools.mapreduce.AppEngineMapper;
import com.google.appengine.tools.mapreduce.DatastoreMutationPool;
/**
*
* The functionality of this is exactly the same as in {@link NaiveToLowercaseMapper}.
* The advantage here is that since a {@link DatastoreMutationPool} is used, mutations
* can be done in batch, saving API calls.
*
* @author Ikai Lan
*
*/
public class PooledToLowercaseMapper extends
AppEngineMapper<Key, Entity, NullWritable, NullWritable> {
private static final Logger log = Logger
.getLogger(PooledToLowercaseMapper.class.getName());
@Override
public void map(Key key, Entity value, Context context) {
log.info("Mapping key: " + key);
if (value.hasProperty("comment")) {
String comment = (String) value.getProperty("comment");
comment = comment.toLowerCase();
value.setProperty("comment", comment);
value.setProperty("updatedAt", new Date());
DatastoreMutationPool mutationPool = this.getAppEngineContext(
context).getMutationPool();
mutationPool.put(value);
}
}
}
What I want to do in addition to the above is also change the datastore namespace of the entity that is being modified.
How is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命名空间是实体不可变键的组成部分。没有改变它的想法。如果您尝试将实体“移动”到不同的命名空间中,则需要在该命名空间中创建一个新实体,跟踪对旧实体的所有引用并更新它们,然后删除旧实体。
The namespace is a component of an Entity's immutable key. There is no notion of changing it. If you're trying to 'move' an entity into a different namespace, you'll need to create a new entity in that namespace, track down any references to the old entity and update them, then delete the old entity.