Skip to content

Support credentials from InputStream with BigQuery Read API (Connection.executeSelect) #2234

@prash-mi

Description

@prash-mi

ExecuteSelect errors out while initialising connection with the read API when GOOGLE_APPLICATION_CREDENTIALS is not set and the credential are passed using setCredentials(credentials) instead.

Expected behaviour: Connection with Read API should be initialised if credentials are being passed using the mentioned method.

Details:

SampleCode:


      TableId targetTable = TableId.of(projectId, defaultDataset, UUID.randomUUID().toString());
        GoogleCredentials credentials;

        try (FileInputStream serviceAccountStream = new FileInputStream(keyFile)) {
            credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
        }

        // Instantiate a BigQuery Client
        BigQuery bigquery =
                BigQueryOptions.newBuilder()
                        .setCredentials(credentials)
                        .setProjectId(projectId)
                        .build()
                        .getService();


        ConnectionSettings connectionSettings =
                ConnectionSettings.newBuilder()
                        .setDestinationTable(targetTable)
                        .build();

        Connection connection = bigquery.createConnection(connectionSettings);
        String query = "SELECT * FROM `a.b.c`";
        BigQueryResult bigQueryResult = connection.executeSelect(query);

Exception:

com.google.cloud.bigquery.BigQuerySQLException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
    at com.google.cloud.bigquery.ConnectionImpl.executeSelect(ConnectionImpl.java:185) ~[google-cloud-bigquery-2.11.0.jar!/:2.11.0]

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/java-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions