use of com.google.cloud.bigquery.ConnectionSettings in project java-bigquery by googleapis.
the class ITBigQueryTest method testBQResultSetPagination.
@Test
public void testBQResultSetPagination() throws SQLException {
String query = "SELECT date, county, state_name, confirmed_cases, deaths FROM " + TABLE_ID_LARGE.getTable() + " where date is not null and county is not null and state_name is not null order by date limit 300000";
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setNumBufferedRows(// page size
10000).build();
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryResult bigQueryResult = connection.executeSelect(query);
ResultSet rs = bigQueryResult.getResultSet();
int cnt = 0;
while (rs.next()) {
// pagination starts after approx 120,000 records
assertNotNull(rs.getDate(0));
assertNotNull(rs.getString(1));
assertNotNull(rs.getString(2));
assertTrue(rs.getInt(3) >= 0);
assertTrue(rs.getInt(4) >= 0);
++cnt;
}
// total 300000 rows should be read
assertEquals(300000, cnt);
}
use of com.google.cloud.bigquery.ConnectionSettings in project java-bigquery by googleapis.
the class ITBigQueryTest method testBQResultSetMultiThreadedOrder.
@Test
public // to the multithreaded BigQueryResult implementation
void testBQResultSetMultiThreadedOrder() throws SQLException {
String query = "SELECT date FROM " + TABLE_ID_LARGE.getTable() + " where date is not null order by date asc limit 300000";
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setNumBufferedRows(// page size
10000).build();
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryResult bigQueryResult = connection.executeSelect(query);
ResultSet rs = bigQueryResult.getResultSet();
int cnt = 0;
assertTrue(rs.next());
++cnt;
java.sql.Date lastDate = rs.getDate(0);
while (rs.next()) {
assertNotNull(rs.getDate(0));
// sorted order is maintained
assertTrue(rs.getDate(0).getTime() >= lastDate.getTime());
lastDate = rs.getDate(0);
++cnt;
}
// total 300000 rows should be read
assertEquals(300000, cnt);
}
use of com.google.cloud.bigquery.ConnectionSettings in project java-bigquery by googleapis.
the class ITBigQueryTest method testBQResultSetPaginationSlowQuery.
@Test
public void testBQResultSetPaginationSlowQuery() throws SQLException {
String query = "SELECT date, county, state_name, confirmed_cases, deaths FROM " + TABLE_ID_LARGE.getTable() + " where date is not null and county is not null and state_name is not null order by date limit 300000";
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setNumBufferedRows(// page size
10000).setJobTimeoutMs(// So that ConnectionImpl.isFastQuerySupported returns false, and the slow
15000L).build();
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryResult bigQueryResult = connection.executeSelect(query);
ResultSet rs = bigQueryResult.getResultSet();
int cnt = 0;
while (rs.next()) {
// pagination starts after approx 120,000 records
assertNotNull(rs.getDate(0));
assertNotNull(rs.getString(1));
assertNotNull(rs.getString(2));
assertTrue(rs.getInt(3) >= 0);
assertTrue(rs.getInt(4) >= 0);
++cnt;
}
// total 300000 rows should be read
assertEquals(300000, cnt);
}
use of com.google.cloud.bigquery.ConnectionSettings in project java-bigquery by googleapis.
the class ITBigQueryTest method testConnectionImplDryRun.
@Test
public void testConnectionImplDryRun() throws SQLException {
String query = String.format("select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from %s where StringField = ? order by TimestampField", TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable());
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setCreateSession(true).build();
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryDryRunResult bigQueryDryRunResultSet = connection.dryRun(query);
assertNotNull(bigQueryDryRunResultSet.getSchema());
assertEquals(BQ_RESULTSET_EXPECTED_SCHEMA, // match the schema
bigQueryDryRunResultSet.getSchema());
List<Parameter> queryParameters = bigQueryDryRunResultSet.getQueryParameters();
assertEquals(StandardSQLTypeName.STRING, queryParameters.get(0).getValue().getType());
QueryStatistics queryStatistics = bigQueryDryRunResultSet.getStatistics().getQueryStatistics();
assertNotNull(queryStatistics);
SessionInfo sessionInfo = bigQueryDryRunResultSet.getStatistics().getSessionInfo();
assertNotNull(sessionInfo.getSessionId());
assertEquals(StatementType.SELECT, queryStatistics.getStatementType());
}
use of com.google.cloud.bigquery.ConnectionSettings in project java-bigquery by googleapis.
the class ITBigQueryTest method testReadAPIConnectionMultiClose.
@Test
public void testReadAPIConnectionMultiClose() throws SQLException {
// use read API to read 300K records, then closes the connection. This test
// repeats it multiple times and assets if the connection was closed
String query = "SELECT date, county, state_name, confirmed_cases, deaths FROM " + TABLE_ID_LARGE.getTable() + " where date is not null and county is not null and state_name is not null order by confirmed_cases asc limit 300000";
ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).setPriority(QueryJobConfiguration.Priority.INTERACTIVE).build();
int closeCnt = 0, runCnt = 3;
for (int run = 0; run < runCnt; run++) {
Connection connection = bigquery.createConnection(connectionSettings);
BigQueryResult bigQueryResult = connection.executeSelect(query);
ResultSet rs = bigQueryResult.getResultSet();
int cnt = 0;
while (rs.next()) {
// pagination starts after approx 120,000 records
assertNotNull(rs.getDate(0));
++cnt;
}
// total 300000 rows should be read
assertEquals(300000, cnt);
// check if connection closed
assertTrue(connection.close());
closeCnt++;
}
assertEquals(closeCnt, // check if the connection closed for the required number of times
runCnt);
}
Aggregations