question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I receive Data from Google BigQuery with Eclipse and Java?

See original GitHub issue

I’m trying to receive some Data from google BigQuery and show the result in my eclipse console to get started with BigQuery and Java. Basically, I followed the Instructions provided by google, which I found here: https://cloud.google.com/bigquery/docs/reference/libraries

So my example Java Code looks like the quick start example from google:

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Dataset;
import com.google.cloud.bigquery.DatasetInfo;

public class QuickstartSample {
  public static void main(String... args){
        // Instantiates a client
        BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

        // The name for the new dataset
        String datasetName = "bigquery-public-data:hacker_news.comments";

        // Prepares a new dataset
        Dataset dataset = null;
        DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();

        // Creates the dataset
        dataset = bigquery.create(datasetInfo);

        System.out.printf("Dataset %s created.%n", dataset.getDatasetId().getDataset());
  } 
}

But when I run this Code I get the following error:

HTTP ERROR 500

Problem accessing /getbigquery. Reason: 
    Could not get the access token.


Caused by:
com.google.cloud.bigquery.BigQueryException: Could not get the access token.
    at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.translate(HttpBigQueryRpc.java:86)
    at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.create(HttpBigQueryRpc.java:141)
    at com.google.cloud.bigquery.BigQueryImpl$1.call(BigQueryImpl.java:172)
    at com.google.cloud.bigquery.BigQueryImpl$1.call(BigQueryImpl.java:169)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
    at com.google.cloud.bigquery.BigQueryImpl.create(BigQueryImpl.java:169)
    at testpackage.dto.QuickstartSample.main(QuickstartSample.java:27)
    at testpackage.getbigquery.doPost(getbigquery.java:27)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
I tried to authenticate with Default Credentials so I ran “gcloud auth application-default login“ in my google SDK console. Although I could login in SDK, eclipse gave me the previous shown error.

Then I tried a few other things like downloading my token as Json file and revering to it with java in my application or setting my environment variable manually but it didn’t work as well.

Does anyone have an idea what I’m doing wrong? Any help is appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelbausorcommented, Aug 23, 2017

Hi @Electricks94,

It looks like you are trying to fetch an existing dataset, but your code is creating it. Can you try the following code to see if you get the same problem?

  public static void main(String... args){
    // Instantiates a client
    BigQuery bigquery = BigQueryOptions.getDefaultInstance()
        .toBuilder()
        .setProjectId("bigquery-public-data")
        .build()
        .getService();

    // The name for the new dataset
    String datasetName = "hacker_news";

    // Fetches the dataset
    Dataset dataset = bigquery.getDataset(datasetName);

    System.out.printf("Dataset %s fetched.%n", dataset.getDatasetId().getDataset());
  }
0reactions
Electricks94commented, Aug 23, 2017

Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I receive Data from Google BigQuery with Eclipse ...
Create a service account in your Google Cloud Platform Console->IAM->Service Accounts with necessary permission. You will be allowed to download ...
Read more >
How can I receive Data from Google BigQuery with Eclipse ...
Create a service account in your Google Cloud Platform Console->IAM->Service Accounts with necessary permission. You will be allowed to download JSON key file....
Read more >
Quickstart: Using client libraries | BigQuery - Google Cloud
Enable the BigQuery API. Create a service account: In the Google Cloud console, go to the Create service account page. Select your project....
Read more >
How To Use Google BigQuery to upload Big Data for free ...
Get Java Code API to upload Big Data of google Bigquery via Eclipse. Analytics, Schema, .gip compress supportable format of .csv file is ......
Read more >
ETL Part I: Apache Beam, Eclipse, Google Cloud Storage and ...
Some Java knowledge · Eclipse IDE and Cloud Tools for Eclipse Plugin: Follow [1] to set up · GCP Project: to get a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found