简体   繁体   中英

Streamig data to bigquery in google appengine - java

I'm trying to upload data to bigquery in appengine.

For uploading to storage I have a special library for appengine

import com.google.appengine.tools.cloudstorage.*;

My question is: is there a library for uploading to bigquery in appengine or should I use the regular api library?

here is what I tried which works well - using the regular api from this streaming sample :

@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();


    }

Is this the correct way?

There is no BigQuery library for App Engine. Your example is correct though and this is recommended way to upload streaming data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM