Search in sources :

Example 1 with ConnectionProperty

use of com.google.cloud.bigquery.ConnectionProperty in project java-bigquery by googleapis.

the class ITBigQueryTest method testQuerySessionSupport.

@Test
public void testQuerySessionSupport() throws InterruptedException {
    String query = "CREATE TEMPORARY TABLE temptable AS SELECT 17 as foo";
    QueryJobConfiguration queryJobConfiguration = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).setCreateSession(true).build();
    Job remoteJob = bigquery.create(JobInfo.of(queryJobConfiguration));
    remoteJob = remoteJob.waitFor();
    assertNull(remoteJob.getStatus().getError());
    Job queryJob = bigquery.getJob(remoteJob.getJobId());
    JobStatistics.QueryStatistics statistics = queryJob.getStatistics();
    String sessionId = statistics.getSessionInfo().getSessionId();
    assertNotNull(sessionId);
    String queryTempTable = "SELECT * FROM temptable";
    ConnectionProperty connectionProperty = ConnectionProperty.newBuilder().setKey("session_id").setValue(sessionId).build();
    QueryJobConfiguration queryJobConfigurationWithSession = QueryJobConfiguration.newBuilder(queryTempTable).setDefaultDataset(DatasetId.of(DATASET)).setConnectionProperties(ImmutableList.of(connectionProperty)).build();
    Job remoteJobWithSession = bigquery.create(JobInfo.of(queryJobConfigurationWithSession));
    remoteJobWithSession = remoteJobWithSession.waitFor();
    assertNull(remoteJobWithSession.getStatus().getError());
    Job queryJobWithSession = bigquery.getJob(remoteJobWithSession.getJobId());
    QueryStatistics statisticsWithSession = queryJobWithSession.getStatistics();
    assertEquals(sessionId, statisticsWithSession.getSessionInfo().getSessionId());
}
Also used : JobStatistics(com.google.cloud.bigquery.JobStatistics) QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) ConnectionProperty(com.google.cloud.bigquery.ConnectionProperty) Job(com.google.cloud.bigquery.Job) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) QueryStatistics(com.google.cloud.bigquery.JobStatistics.QueryStatistics) Test(org.junit.Test)

Aggregations

ConnectionProperty (com.google.cloud.bigquery.ConnectionProperty)1 Job (com.google.cloud.bigquery.Job)1 JobStatistics (com.google.cloud.bigquery.JobStatistics)1 QueryStatistics (com.google.cloud.bigquery.JobStatistics.QueryStatistics)1 QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 Test (org.junit.Test)1