Java Code Examples for com.google.cloud.bigquery.BigQueryOptions#getService()

The following examples show how to use com.google.cloud.bigquery.BigQueryOptions#getService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBigQueryIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws IOException {
    final Map<PropertyDescriptor, String> propertiesMap = new HashMap<>();
    propertiesMap.put(CredentialPropertyDescriptors.SERVICE_ACCOUNT_JSON_FILE, SERVICE_ACCOUNT_JSON);
    Credentials credentials = credentialsProviderFactory.getGoogleCredentials(propertiesMap, new ProxyAwareTransportFactory(null));

    BigQueryOptions bigQueryOptions = BigQueryOptions.newBuilder()
            .setProjectId(PROJECT_ID)
            .setCredentials(credentials)
            .build();

    bigquery = bigQueryOptions.getService();

    DatasetInfo datasetInfo = DatasetInfo.newBuilder(RemoteBigQueryHelper.generateDatasetName()).build();
    dataset = bigquery.create(datasetInfo);
}
 
Example 2
Source File: GcpBigQueryAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public BigQuery bigQuery() throws IOException {
	BigQueryOptions bigQueryOptions = BigQueryOptions.newBuilder()
			.setProjectId(this.projectId)
			.setCredentials(this.credentialsProvider.getCredentials())
			.setHeaderProvider(new UserAgentHeaderProvider(GcpBigQueryAutoConfiguration.class))
			.build();
	return bigQueryOptions.getService();
}
 
Example 3
Source File: BigQueryIOIT.java    From beam with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDown() {
  BigQueryOptions options = BigQueryOptions.newBuilder().build();
  BigQuery client = options.getService();
  TableId tableId = TableId.of(options.getProjectId(), testBigQueryDataset, testBigQueryTable);
  client.delete(tableId);
}
 
Example 4
Source File: BigQueryDelegate.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public static BigQuery getBigquery(Credentials credentials, String projectId) {
  BigQueryOptions options = BigQueryOptions.newBuilder()
      .setCredentials(credentials)
      .setProjectId(projectId)
      .build();
  return options.getService();
}
 
Example 5
Source File: BigQueryClient.java    From beam with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the publisher with a application default credentials from the environment and default
 * project name.
 */
public static BigQueryClient create(String dataset) {
  BigQueryOptions options = BigQueryOptions.newBuilder().build();

  return new BigQueryClient(options.getService(), options.getProjectId(), dataset);
}