Search in sources :

Example 16 with ConnectionSettings

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

the class ITBigQueryTest method testExecuteSelectWithPositionalQueryParameters.

/* TODO(prasmish): expand below test case with all the fields shown in the above test case */
@Test
public void testExecuteSelectWithPositionalQueryParameters() throws BigQuerySQLException {
    String query = "SELECT TimestampField, StringField FROM " + TABLE_ID.getTable() + " WHERE StringField = ?" + " AND TimestampField > ?";
    QueryParameterValue stringParameter = QueryParameterValue.string("stringValue");
    QueryParameterValue timestampParameter = QueryParameterValue.timestamp("2014-01-01 07:00:00.000000+00:00");
    Parameter stringParam = Parameter.newBuilder().setValue(stringParameter).build();
    Parameter timeStampParam = Parameter.newBuilder().setValue(timestampParameter).build();
    ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).build();
    Connection connection = bigquery.createConnection(connectionSettings);
    List<Parameter> parameters = ImmutableList.of(stringParam, timeStampParam);
    BigQueryResult rs = connection.executeSelect(query, parameters);
    assertEquals(2, rs.getTotalRows());
}
Also used : QueryParameterValue(com.google.cloud.bigquery.QueryParameterValue) Connection(com.google.cloud.bigquery.Connection) Parameter(com.google.cloud.bigquery.Parameter) BigQueryResult(com.google.cloud.bigquery.BigQueryResult) ConnectionSettings(com.google.cloud.bigquery.ConnectionSettings) Test(org.junit.Test)

Aggregations

Connection (com.google.cloud.bigquery.Connection)16 ConnectionSettings (com.google.cloud.bigquery.ConnectionSettings)16 Test (org.junit.Test)16 BigQueryResult (com.google.cloud.bigquery.BigQueryResult)15 ResultSet (java.sql.ResultSet)12 Schema (com.google.cloud.bigquery.Schema)6 FieldValueList (com.google.cloud.bigquery.FieldValueList)5 Parameter (com.google.cloud.bigquery.Parameter)3 QueryParameterValue (com.google.cloud.bigquery.QueryParameterValue)2 BigQueryDryRunResult (com.google.cloud.bigquery.BigQueryDryRunResult)1 QueryStatistics (com.google.cloud.bigquery.JobStatistics.QueryStatistics)1 SessionInfo (com.google.cloud.bigquery.JobStatistics.SessionInfo)1