我试图通过在DoFn步骤中查询数据存储来增强管道中的数据.来自Class CustomClass的对象中的字段用于对数据存储表执行查询,返回的值用于增强对象.
代码如下所示:
public class EnhanceWithDataStore extends DoFn<CustomClass, CustomClass> {
private static Datastore datastore = DatastoreOptions.defaultInstance().service();
private static KeyFactory articleKeyFactory = datastore.newKeyFactory().kind("article");
@Override
public void processElement(ProcessContext c) throws Exception {
CustomClass event = c.element();
Entity article = datastore.get(articleKeyFactory.newKey(event.getArticleId()));
String articleName = "";
try{
articleName = article.getString("articleName");
} catch(Exception e) {}
CustomClass enhanced = new CustomClass(event);
enhanced.setArticleName(articleName);
c.output(enhanced);
}
Run Code Online (Sandbox Code Playgroud)
当它在本地运行时,这很快,但是当它在云中运行时,此步骤会显着减慢管道的速度.是什么导致了这个?有没有解决方法或更好的方法来做到这一点?
可以在此处找到管道的图片(最后一步是增强步骤): 管道架构