Skip to content

Commit

Permalink
Updated QuerySample tests to use StandardSQL instead of LegacySQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg committed Nov 1, 2017
1 parent 6f79d79 commit 3972e70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.FieldValue;
import com.google.cloud.bigquery.QueryParameterValue;
import com.google.cloud.bigquery.QueryRequest;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.QueryResponse;
import com.google.cloud.bigquery.QueryResult;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -122,8 +122,8 @@ private static void runNamed(final String corpus, final long minWordCount)
+ "WHERE corpus = @corpus\n"
+ "AND word_count >= @min_word_count\n"
+ "ORDER BY word_count DESC";
QueryRequest queryRequest =
QueryRequest.newBuilder(queryString)
QueryJobConfiguration queryRequest =
QueryJobConfiguration.newBuilder(queryString)
.addNamedParameter("corpus", QueryParameterValue.string(corpus))
.addNamedParameter("min_word_count", QueryParameterValue.int64(minWordCount))
// Standard SQL syntax is required for parameterized queries.
Expand Down Expand Up @@ -177,8 +177,8 @@ private static void runArray(String gender, String[] states) throws InterruptedE
+ "GROUP BY name\n"
+ "ORDER BY count DESC\n"
+ "LIMIT 10;";
QueryRequest queryRequest =
QueryRequest.newBuilder(queryString)
QueryJobConfiguration queryRequest =
QueryJobConfiguration.newBuilder(queryString)
.addNamedParameter("gender", QueryParameterValue.string(gender))
.addNamedParameter("states", QueryParameterValue.array(states, String.class))
// Standard SQL syntax is required for parameterized queries.
Expand Down Expand Up @@ -224,8 +224,8 @@ private static void runTimestamp() throws InterruptedException {
DateTime timestamp = new DateTime(2016, 12, 7, 8, 0, 0, DateTimeZone.UTC);

String queryString = "SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR);";
QueryRequest queryRequest =
QueryRequest.newBuilder(queryString)
QueryJobConfiguration queryRequest =
QueryJobConfiguration.newBuilder(queryString)
.addNamedParameter(
"ts_value",
QueryParameterValue.timestamp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void tearDown() {

@Test
public void testSimpleQuery() throws Exception {
QuerySample.main(new String[]{"--query", LEGACY_SQL_QUERY, "--runSimpleQuery"});
QuerySample.main(new String[]{"--query", STANDARD_SQL_QUERY, "--runSimpleQuery"});
String got = bout.toString();
assertThat(got).contains(CORPUS_NAME);
}
Expand All @@ -87,7 +87,7 @@ public void testStandardSqlQuery() throws Exception {

@Test
public void testUncachedQuery() throws Exception {
QuerySample.main(new String[]{"--query", LEGACY_SQL_QUERY, "--runSimpleQuery"});
QuerySample.main(new String[]{"--query", STANDARD_SQL_QUERY, "--runSimpleQuery"});
String got = bout.toString();
assertThat(got).contains(CORPUS_NAME);
}
Expand All @@ -98,7 +98,7 @@ public void testUncachedQuery() throws Exception {
// See: https://cloud.google.com/bigquery/querying-data#interactive-batch
@Ignore
public void testBatchQuery() throws Exception {
QuerySample.main(new String[]{"--query", LEGACY_SQL_QUERY, "--runBatchQuery"});
QuerySample.main(new String[]{"--query", STANDARD_SQL_QUERY, "--runBatchQuery"});
String got = bout.toString();
assertThat(got).contains(CORPUS_NAME);
}
Expand All @@ -112,7 +112,7 @@ public void testPermanentTableQuery() throws Exception {
QuerySample.main(
new String[]{
"--query",
LEGACY_SQL_QUERY,
STANDARD_SQL_QUERY,
"--runPermanentTableQuery",
"--destDataset",
TEST_DATASET,
Expand Down

0 comments on commit 3972e70

Please sign in to comment.