我试图将数据上传到appengine中的bigquery。
要上传到存储空间,我有一个特殊的library for appengine
import com.google.appengine.tools.cloudstorage.*;
我的问题是:是否有一个库可以在appengine中上传到bigquery,还是应该使用常规的api库?
这是我尝试过的效果很好 - 使用此streaming sample的常规api:
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String projectId = "myprojectId";
String datasetId = "mydatasetId";
String tableId = "person";
System.out.println("Enter JSON to stream to BigQuery: \n" + "Press End-of-stream (CTRL-D) to stop");
String string = "[\n {\"Name\": \"test\", \"Age\": 0, \"Weight\": 100.0, \"IsMagic\": false},\n {\"Name\": \"test\", \"Age\": 1, \"Weight\": 100.0, \"IsMagic\": false},\n {\"Name\": \"test\", \"Age\": 2, \"Weight\": 100.0, \"IsMagic\": false},\n {\"Name\": \"test\", \"Age\": 3, \"Weight\": 100.0, \"IsMagic\": false},\n {\"Name\": \"test\", \"Age\": 0, \"Weight\": 100.0, \"IsMagic\": false}\n]";
JsonReader jsonReader = new JsonReader(new StringReader(string));
Iterator<TableDataInsertAllResponse> responses = StreamingSample.run(projectId, datasetId, tableId, jsonReader);
while (responses.hasNext()) {
log.info(responses.next());
}
jsonReader.close();
}
这是正确的方法吗?
答案 0 :(得分:1)
App Engine没有BigQuery库。您的示例是正确的,这是上传流数据的推荐方法。