dina
dina

Reputation: 4289

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?

Upvotes: 0

Views: 79

Answers (1)

Vitalii Li
Vitalii Li

Reputation: 26

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

Upvotes: 1

Related Questions