Iam*_*ule 4 csv google-app-engine google-cloud-datastore google-cloud-dataflow
我有一个包含 2 列和 20,000 行的 CSV 文件,我想导入到 Google Cloud Datastore 中。我是 Google Cloud 和 NoSQL 数据库的新手。我曾尝试使用数据流,但需要提供 Javascript UDF 函数名称。有没有人有这样的例子?一旦它在数据存储中,我将查询这些数据。任何关于如何创建它的建议或指导将不胜感激。
使用 Apache Beam,您可以使用TextIO
该类读取 CSV 文件。请参阅TextIO文档。
Pipeline p = Pipeline.create();
p.apply(TextIO.read().from("gs://path/to/file.csv"));
Run Code Online (Sandbox Code Playgroud)
接下来,应用将解析 CSV 文件中的每一行并返回一个Entity
对象的转换。根据您希望如何存储每一行,构造适当的Entity
对象。此页面有一个如何创建Entity
对象的示例。
.apply(ParDo.of(new DoFn<String, Entity>() {
@ProcessElement
public void processElement(ProcessContext c) {
String row = c.element();
// TODO: parse row (split) and construct Entity object
Entity entity = ...
c.output(entity);
}
}));
Run Code Online (Sandbox Code Playgroud)
最后,将Entity
对象写入Cloud Datastore。请参阅DatastoreIO文档。
.apply(DatastoreIO.v1().write().withProjectId(projectId));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4256 次 |
最近记录: |