Search in sources :

Example 1 with BigQueryOptions

use of com.google.cloud.bigquery.BigQueryOptions in project google-cloud-java by GoogleCloudPlatform.

the class RemoteBigQueryHelperTest method testCreateFromStream.

@Test
public void testCreateFromStream() {
    RemoteBigQueryHelper helper = RemoteBigQueryHelper.create(PROJECT_ID, JSON_KEY_STREAM);
    BigQueryOptions options = helper.getOptions();
    assertEquals(PROJECT_ID, options.getProjectId());
    assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout());
    assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout());
    assertEquals(10, options.getRetrySettings().getMaxAttempts());
    assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay());
    assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout());
    assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay());
}
Also used : BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) Test(org.junit.Test)

Example 2 with BigQueryOptions

use of com.google.cloud.bigquery.BigQueryOptions in project beam by apache.

the class BigQueryIOIT method tearDown.

@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);
}
Also used : TableId(com.google.cloud.bigquery.TableId) BigQuery(com.google.cloud.bigquery.BigQuery) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) AfterClass(org.junit.AfterClass)

Example 3 with BigQueryOptions

use of com.google.cloud.bigquery.BigQueryOptions in project google-cloud-java by GoogleCloudPlatform.

the class RemoteBigQueryHelper method create.

/**
   * Creates a {@code RemoteBigQueryHelper} object using default project id and authentication
   * credentials.
   */
public static RemoteBigQueryHelper create() {
    HttpTransportOptions transportOptions = BigQueryOptions.getDefaultHttpTransportOptions();
    transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
    BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder().setRetrySettings(retrySettings()).setTransportOptions(transportOptions).build();
    return new RemoteBigQueryHelper(bigqueryOptions);
}
Also used : BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) HttpTransportOptions(com.google.cloud.http.HttpTransportOptions)

Example 4 with BigQueryOptions

use of com.google.cloud.bigquery.BigQueryOptions in project google-cloud-java by GoogleCloudPlatform.

the class RemoteBigQueryHelper method create.

/**
   * Creates a {@code RemoteBigQueryHelper} object for the given project id and JSON key input
   * stream.
   *
   * @param projectId id of the project to be used for running the tests
   * @param keyStream input stream for a JSON key
   * @return A {@code RemoteBigQueryHelper} object for the provided options
   * @throws BigQueryHelperException if {@code keyStream} is not a valid JSON key stream
   */
public static RemoteBigQueryHelper create(String projectId, InputStream keyStream) throws BigQueryHelperException {
    try {
        HttpTransportOptions transportOptions = BigQueryOptions.getDefaultHttpTransportOptions();
        transportOptions = transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build();
        BigQueryOptions bigqueryOptions = BigQueryOptions.newBuilder().setCredentials(ServiceAccountCredentials.fromStream(keyStream)).setProjectId(projectId).setRetrySettings(retrySettings()).setTransportOptions(transportOptions).build();
        return new RemoteBigQueryHelper(bigqueryOptions);
    } catch (IOException ex) {
        if (log.isLoggable(Level.WARNING)) {
            log.log(Level.WARNING, ex.getMessage());
        }
        throw BigQueryHelperException.translate(ex);
    }
}
Also used : BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) IOException(java.io.IOException) HttpTransportOptions(com.google.cloud.http.HttpTransportOptions)

Example 5 with BigQueryOptions

use of com.google.cloud.bigquery.BigQueryOptions in project beam by apache.

the class BigQueryIOIT method setup.

@BeforeClass
public static void setup() throws IOException {
    options = IOITHelper.readIOTestPipelineOptions(BigQueryPerfTestOptions.class);
    tempRoot = options.getTempRoot();
    sourceOptions = SyntheticOptions.fromJsonString(options.getSourceOptions(), SyntheticSourceOptions.class);
    testBigQueryDataset = options.getTestBigQueryDataset();
    testBigQueryTable = options.getTestBigQueryTable();
    writeFormat = WriteFormat.valueOf(options.getWriteFormat());
    BigQueryOptions bigQueryOptions = BigQueryOptions.newBuilder().build();
    tableQualifier = String.format("%s:%s.%s", bigQueryOptions.getProjectId(), testBigQueryDataset, testBigQueryTable);
    settings = InfluxDBSettings.builder().withHost(options.getInfluxHost()).withDatabase(options.getInfluxDatabase()).withMeasurement(options.getInfluxMeasurement()).get();
}
Also used : BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) SyntheticSourceOptions(org.apache.beam.sdk.io.synthetic.SyntheticSourceOptions) BeforeClass(org.junit.BeforeClass)

Aggregations

BigQueryOptions (com.google.cloud.bigquery.BigQueryOptions)5 HttpTransportOptions (com.google.cloud.http.HttpTransportOptions)2 BigQuery (com.google.cloud.bigquery.BigQuery)1 TableId (com.google.cloud.bigquery.TableId)1 IOException (java.io.IOException)1 SyntheticSourceOptions (org.apache.beam.sdk.io.synthetic.SyntheticSourceOptions)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1