Search in sources :

Example 1 with QueryResponse

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

the class BigqueryMatcherTest method createResponseContainingTestData.

private QueryResponse createResponseContainingTestData() {
    TableCell field1 = new TableCell();
    field1.setV("abc");
    TableCell field2 = new TableCell();
    field2.setV("2");
    TableCell field3 = new TableCell();
    field3.setV("testing BigQuery matcher.");
    TableRow row = new TableRow();
    row.setF(Lists.newArrayList(field1, field2, field3));
    QueryResponse response = new QueryResponse();
    response.setJobComplete(true);
    response.setRows(Lists.newArrayList(row));
    response.setTotalRows(BigInteger.ONE);
    return response;
}
Also used : TableCell(com.google.api.services.bigquery.model.TableCell) TableRow(com.google.api.services.bigquery.model.TableRow) QueryResponse(com.google.api.services.bigquery.model.QueryResponse)

Example 2 with QueryResponse

use of com.google.api.services.bigquery.model.QueryResponse in project zeppelin by apache.

the class BigQueryInterpreter method run.

//Function to run the SQL on bigQuery service
public static Iterator<GetQueryResultsResponse> run(final String queryString, final String projId, final long wTime, final long maxRows) throws IOException {
    try {
        QueryResponse query = service.jobs().query(projId, new QueryRequest().setTimeoutMs(wTime).setQuery(queryString).setMaxResults(maxRows)).execute();
        jobId = query.getJobReference().getJobId();
        projectId = query.getJobReference().getProjectId();
        GetQueryResults getRequest = service.jobs().getQueryResults(projectId, jobId);
        return getPages(getRequest);
    } catch (IOException ex) {
        throw ex;
    }
}
Also used : QueryRequest(com.google.api.services.bigquery.model.QueryRequest) QueryResponse(com.google.api.services.bigquery.model.QueryResponse) IOException(java.io.IOException) GetQueryResults(com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults)

Example 3 with QueryResponse

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

the class BigqueryMatcherTest method testBigqueryMatcherFailsWhenQueryJobNotComplete.

@Test
public void testBigqueryMatcherFailsWhenQueryJobNotComplete() throws Exception {
    BigqueryMatcher matcher = spy(new BigqueryMatcher(appName, projectId, query, "some-checksum"));
    doReturn(mockBigqueryClient).when(matcher).newBigqueryClient(anyString());
    when(mockQuery.execute()).thenReturn(new QueryResponse().setJobComplete(false));
    thrown.expect(AssertionError.class);
    thrown.expectMessage("The query job hasn't completed.");
    thrown.expectMessage("jobComplete=false");
    try {
        assertThat(mockResult, matcher);
    } finally {
        verify(matcher).newBigqueryClient(eq(appName));
        verify(mockJobs).query(eq(projectId), eq(new QueryRequest().setQuery(query)));
    }
}
Also used : QueryRequest(com.google.api.services.bigquery.model.QueryRequest) QueryResponse(com.google.api.services.bigquery.model.QueryResponse) Test(org.junit.Test)

Aggregations

QueryResponse (com.google.api.services.bigquery.model.QueryResponse)3 QueryRequest (com.google.api.services.bigquery.model.QueryRequest)2 GetQueryResults (com.google.api.services.bigquery.Bigquery.Jobs.GetQueryResults)1 TableCell (com.google.api.services.bigquery.model.TableCell)1 TableRow (com.google.api.services.bigquery.model.TableRow)1 IOException (java.io.IOException)1 Test (org.junit.Test)1