Search in sources :

Example 1 with Bigquery

use of com.google.api.services.bigquery.Bigquery in project beam by apache.

the class BigqueryMatcher method matchesSafely.

@Override
protected boolean matchesSafely(PipelineResult pipelineResult) {
    LOG.info("Verifying Bigquery data");
    Bigquery bigqueryClient = newBigqueryClient(applicationName);
    // execute query
    LOG.debug("Executing query: {}", query);
    try {
        QueryRequest queryContent = new QueryRequest();
        queryContent.setQuery(query);
        response = queryWithRetries(bigqueryClient, queryContent, Sleeper.DEFAULT, BackOffAdapter.toGcpBackOff(BACKOFF_FACTORY.backoff()));
    } catch (IOException | InterruptedException e) {
        if (e instanceof InterruptedIOException) {
            Thread.currentThread().interrupt();
        }
        throw new RuntimeException("Failed to fetch BigQuery data.", e);
    }
    if (!response.getJobComplete()) {
        // query job not complete, verification failed
        return false;
    } else {
        // compute checksum
        actualChecksum = generateHash(response.getRows());
        LOG.debug("Generated a SHA1 checksum based on queried data: {}", actualChecksum);
        return expectedChecksum.equals(actualChecksum);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) QueryRequest(com.google.api.services.bigquery.model.QueryRequest) Bigquery(com.google.api.services.bigquery.Bigquery) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Aggregations

Bigquery (com.google.api.services.bigquery.Bigquery)1 QueryRequest (com.google.api.services.bigquery.model.QueryRequest)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1