BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder() .setCredentials(ServiceAccountCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings())
@Override protected BigQueryOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) { final String projectId = context.getProperty(PROJECT_ID).evaluateAttributeExpressions().getValue(); final Integer retryCount = Integer.valueOf(context.getProperty(RETRY_COUNT).getValue()); final BigQueryOptions.Builder builder = BigQueryOptions.newBuilder(); if (!StringUtils.isBlank(projectId)) { builder.setProjectId(projectId); } return builder.setCredentials(credentials) .setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(retryCount).build()) .setTransportOptions(getTransportOptions(context)) .build(); }
public static void explicit() throws IOException { // Load credentials from JSON key file. If you can't set the GOOGLE_APPLICATION_CREDENTIALS // environment variable, you can explicitly load the credentials file to construct the // credentials. GoogleCredentials credentials; File credentialsPath = new File("service_account.json"); // TODO: update to your key path. try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) { credentials = ServiceAccountCredentials.fromStream(serviceAccountStream); } // Instantiate a client. BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService(); // Use the client. System.out.println("Datasets:"); for (Dataset dataset : bigquery.listDatasets().iterateAll()) { System.out.printf("%s%n", dataset.getDatasetId().getDataset()); } } // [END bigquery_client_json_credentials]
BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder() .setCredentials(ServiceAccountCredentials.fromStream(keyStream)) .setProjectId(projectId) .setRetrySettings(retrySettings())
/** * Returns a default {@link BigQuery} instance for the specified project with credentials provided * in the specified file, which can then be used for creating, updating, and inserting into tables * from specific datasets. * * @param projectName The name of the BigQuery project to work with * @param keyFilename The name of a file containing a JSON key that can be used to provide * credentials to BigQuery, or null if no authentication should be performed. * @return The resulting BigQuery object. */ public BigQuery connect(String projectName, String keyFilename) { if (keyFilename == null) { return connect(projectName); } logger.debug("Attempting to open file {} for service account json key", keyFilename); try (InputStream credentialsStream = new FileInputStream(keyFilename)) { logger.debug("Attempting to authenticate with BigQuery using provided json key"); return new BigQueryOptions.DefaultBigQueryFactory().create( BigQueryOptions.newBuilder() .setProjectId(projectName) .setCredentials(GoogleCredentials.fromStream(credentialsStream)) .build() ); } catch (IOException err) { throw new BigQueryConnectException("Failed to access json key file", err); } }
public static BigQuery createClient(BigQueryDatastoreProperties datastore) { if (StringUtils.isEmpty(datastore.serviceAccountFile.getValue())) { return BigQueryOptions.getDefaultInstance().getService(); } else { return BigQueryOptions.newBuilder().setProjectId(datastore.projectName.getValue()) .setCredentials(createCredentials(datastore)).build().getService(); } }
public static BigQuery createClient(BigQueryDatastoreProperties datastore) { if (StringUtils.isEmpty(datastore.serviceAccountFile.getValue())) { return BigQueryOptions.getDefaultInstance().getService(); } else { return BigQueryOptions.newBuilder().setProjectId(datastore.projectName.getValue()) .setCredentials(createCredentials(datastore)).build().getService(); } }
public BigQuery bigQuery() { if (bigQuery == null) { bigQuery = BigQueryOptions.newBuilder().setCredentials(credentials).setProjectId(projectId).build().getService(); } return bigQuery; }
BigQueryOptions.newBuilder() .setProjectId("p1") .setCredentials(NoCredentials.getInstance()) .build(); BigQueryOptions otherOptions = options.toBuilder().setProjectId("p2").build();