Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run a load job in bq emulator with auth service account json? #347

Open
Bitsy-Chuck opened this issue Aug 9, 2024 · 2 comments
Open

Comments

@Bitsy-Chuck
Copy link

I am trying to load a file in bigquery emulator using a load job

 LoadJobConfiguration loadConfig =
                    LoadJobConfiguration.newBuilder(tableIdObj, csvFilePath)
                            .setFormatOptions(FormatOptions.csv())
                            .setCreateDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED)
                            .setWriteDisposition(JobInfo.WriteDisposition.WRITE_APPEND)
                            .setAutodetect(true)  // Automatically detect schema
                            .build();

bigquery.create(JobInfo.of(loadConfig));

fails with

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST http://localhost:57058/bigquery/v2/projects/test-project/jobs?prettyPrint=false
{
  "code": 400,
  "errors": [
    {
      "location": "",
      "message": "failed to import from gcs: dialing: google: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information",
      "reason": "jobInternalError",
      "debugInfo": ""
    }
  ],
  "message": "failed to import from gcs: dialing: google: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information"
}

But when running normal queries like bigquery.query(conf) works with auth. How to pass the auth? bigquery client is init with NoCredentials()

@Bitsy-Chuck
Copy link
Author

public BigQuery getBqService(BigQueryEmulatorContainer bigQueryEmulatorContainer) {
        String url = bigQueryEmulatorContainer.getEmulatorHttpEndpoint();
        BigQueryOptions options = BigQueryOptions
                .newBuilder()
                .setProjectId(bigQueryEmulatorContainer.getProjectId())
                .setHost(url)
                .setLocation(url)
                .setCredentials(NoCredentials.getInstance())
                .build();
        return options.getService();
    }

@Ojasv-Singh-Zeotap
Copy link

Any update here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants