简体   繁体   中英

Java Code error while Streaming Data into BigQuery

I'm beginner in Java. Can you tell me please why the following code detected an error though I take exactly the same code given as an example in the following URL of google: https://developers.google.com/bigquery/streaming-data-into-bigquery#streaminginsertexamples

the word bigquery is underlying in red and the error is: bigquery cannot be resolved.

I remember that I want to stream my data into BigQuery one record at a time by using the tabledata().insertAll() method.

This is my code:

import java.io.IOException;
import java.util.*;
import com.google.api.services.bigquery.*;
import com.google.api.services.bigquery.model.*;


public class sdz1 {

    public static void main(String[] args) {

        TableRow row = new TableRow();
        row.set("Average", 7.7);
        TableDataInsertAllRequest.Rows rows = new TableDataInsertAllRequest.Rows();
        rows.setInsertId(""+System.currentTimeMillis());
        rows.setJson(row);
        List  rowList = new ArrayList();
        rowList.add(rows);
        TableDataInsertAllRequest content = new TableDataInsertAllRequest().setRows(rowList);
        try
        {
            TableDataInsertAllResponse response = bigquery
                            .tabledata()
                            .insertAll("Vigicolis", "wi_vigicolis", "TestTable", content)
                            .execute();
            // TableDataInsertAllResponse response = new TableDataInsertAllResponse();
            // response.bigquery.tabledata().insertAll("Vigicolis", "wi_vigicolis", "TestTable", content).execute();
            System.out.println("Response: " + response);
        }
        catch (IOException e)
        {
            // handle
        }
    }

}

You are missing jar file of BigQuery which provides the required packages and classes required to run this program. Find the jar and add it to your classpath via command or in IDE.

Maven dependency link for the jar and jar can be downloaded as well from this link.

You need to create the bigquery object.

Ex: Bigquery bigquery = new Bigquery(new NetHttpTransport(), new JacksonFactory(), new AppIdentityCredential(SQLSERVICE_ADMIN));

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