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

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

Open
prash-mi opened this issue Aug 16, 2022 · 0 comments
Assignees
Labels
api: bigquery Issues related to the googleapis/java-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@prash-mi
Copy link
Contributor

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]
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/java-bigquery API. label Aug 16, 2022
@prash-mi prash-mi self-assigned this Aug 16, 2022
@prash-mi prash-mi added priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed api: bigquery Issues related to the googleapis/java-bigquery API. labels Aug 16, 2022
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/java-bigquery API. label Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/java-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant