Skip to content

Commit d4008a4

Browse files
authored
Merge pull request #1154 from mziccard/translate-alpha
Fetch latest changes from master and bump translate version
2 parents 36c66a5 + 7873773 commit d4008a4

File tree

41 files changed

+194
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+194
-91
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ If you are using Maven, add this to your pom.xml file
3636
<dependency>
3737
<groupId>com.google.cloud</groupId>
3838
<artifactId>gcloud-java</artifactId>
39-
<version>0.2.6</version>
39+
<version>0.2.7</version>
4040
</dependency>
4141
```
4242
If you are using Gradle, add this to your dependencies
4343
```Groovy
44-
compile 'com.google.cloud:gcloud-java:0.2.6'
44+
compile 'com.google.cloud:gcloud-java:0.2.7'
4545
```
4646
If you are using SBT, add this to your dependencies
4747
```Scala
48-
libraryDependencies += "com.google.cloud" % "gcloud-java" % "0.2.6"
48+
libraryDependencies += "com.google.cloud" % "gcloud-java" % "0.2.7"
4949
```
5050

5151
Example Applications

gcloud-java-bigquery/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ If you are using Maven, add this to your pom.xml file
2222
<dependency>
2323
<groupId>com.google.cloud</groupId>
2424
<artifactId>gcloud-java-bigquery</artifactId>
25-
<version>0.2.6</version>
25+
<version>0.2.7</version>
2626
</dependency>
2727
```
2828
If you are using Gradle, add this to your dependencies
2929
```Groovy
30-
compile 'com.google.cloud:gcloud-java-bigquery:0.2.6'
30+
compile 'com.google.cloud:gcloud-java-bigquery:0.2.7'
3131
```
3232
If you are using SBT, add this to your dependencies
3333
```Scala
34-
libraryDependencies += "com.google.cloud" % "gcloud-java-bigquery" % "0.2.6"
34+
libraryDependencies += "com.google.cloud" % "gcloud-java-bigquery" % "0.2.7"
3535
```
3636

3737
Example Application

gcloud-java-bigquery/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>com.google.cloud</groupId>
1313
<artifactId>gcloud-java-pom</artifactId>
14-
<version>0.2.7-SNAPSHOT</version>
14+
<version>0.2.8-SNAPSHOT</version>
1515
</parent>
1616
<properties>
1717
<site.installationModule>gcloud-java-bigquery</site.installationModule>

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public final class QueryJobConfiguration extends JobConfiguration {
5151
private final Boolean useQueryCache;
5252
private final Boolean flattenResults;
5353
private final Boolean dryRun;
54+
private final Boolean useLegacySql;
5455

5556
/**
5657
* Priority levels for a query. If not specified the priority is assumed to be
@@ -87,6 +88,7 @@ public static final class Builder
8788
private Boolean useQueryCache;
8889
private Boolean flattenResults;
8990
private Boolean dryRun;
91+
private Boolean useLegacySql;
9092

9193
private Builder() {
9294
super(Type.QUERY);
@@ -106,6 +108,7 @@ private Builder(QueryJobConfiguration jobConfiguration) {
106108
this.useQueryCache = jobConfiguration.useQueryCache;
107109
this.flattenResults = jobConfiguration.flattenResults;
108110
this.dryRun = jobConfiguration.dryRun;
111+
this.useLegacySql = jobConfiguration.useLegacySql;
109112
}
110113

111114
private Builder(com.google.api.services.bigquery.model.JobConfiguration configurationPb) {
@@ -115,6 +118,7 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
115118
allowLargeResults = queryConfigurationPb.getAllowLargeResults();
116119
useQueryCache = queryConfigurationPb.getUseQueryCache();
117120
flattenResults = queryConfigurationPb.getFlattenResults();
121+
useLegacySql = queryConfigurationPb.getUseLegacySql();
118122
dryRun = configurationPb.getDryRun();
119123
if (queryConfigurationPb.getDestinationTable() != null) {
120124
destinationTable = TableId.fromPb(queryConfigurationPb.getDestinationTable());
@@ -293,6 +297,20 @@ public Builder dryRun(Boolean dryRun) {
293297
return this;
294298
}
295299

300+
/**
301+
* Sets whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
302+
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
303+
* Standard SQL</a>. When set to {@code false}, the values of
304+
* {@link #allowLargeResults(Boolean)} and {@link #flattenResults(Boolean)} are ignored; query
305+
* will be run as if {@link #allowLargeResults(Boolean)} is {@code true} and
306+
* {@link #flattenResults(Boolean)} is {@code false}. If not set, legacy SQL dialect is used.
307+
* This property is experimental and might be subject to change.
308+
*/
309+
public Builder useLegacySql(Boolean useLegacySql) {
310+
this.useLegacySql = useLegacySql;
311+
return this;
312+
}
313+
296314
public QueryJobConfiguration build() {
297315
return new QueryJobConfiguration(this);
298316
}
@@ -313,6 +331,7 @@ private QueryJobConfiguration(Builder builder) {
313331
this.tableDefinitions =
314332
builder.tableDefinitions != null ? ImmutableMap.copyOf(builder.tableDefinitions) : null;
315333
this.dryRun = builder.dryRun;
334+
this.useLegacySql = builder.useLegacySql;
316335
}
317336

318337
/**
@@ -426,6 +445,18 @@ public Boolean dryRun() {
426445
return dryRun;
427446
}
428447

448+
/**
449+
* Returns whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
450+
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
451+
* Standard SQL</a>. When set to {@code false}, the values of {@link #allowLargeResults()} and
452+
* {@link #flattenResults()} are ignored; query will be run as if {@link #allowLargeResults()} is
453+
* {@code true} and {@link #flattenResults()} is {@code false}. If not set, legacy SQL dialect is
454+
* used. This property is experimental and might be subject to change.
455+
*/
456+
public Boolean useLegacySql() {
457+
return useLegacySql;
458+
}
459+
429460
@Override
430461
public Builder toBuilder() {
431462
return new Builder(this);
@@ -445,7 +476,8 @@ ToStringHelper toStringHelper() {
445476
.add("userDefinedFunctions", userDefinedFunctions)
446477
.add("createDisposition", createDisposition)
447478
.add("writeDisposition", writeDisposition)
448-
.add("dryRun", dryRun);
479+
.add("dryRun", dryRun)
480+
.add("useLegacySql", useLegacySql);
449481
}
450482

451483
@Override
@@ -459,7 +491,7 @@ public boolean equals(Object obj) {
459491
public int hashCode() {
460492
return Objects.hash(baseHashCode(), allowLargeResults, createDisposition, destinationTable,
461493
defaultDataset, flattenResults, priority, query, tableDefinitions, useQueryCache,
462-
userDefinedFunctions, writeDisposition, dryRun);
494+
userDefinedFunctions, writeDisposition, dryRun, useLegacySql);
463495
}
464496

465497
@Override
@@ -513,6 +545,9 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
513545
if (writeDisposition != null) {
514546
queryConfigurationPb.setWriteDisposition(writeDisposition.toString());
515547
}
548+
if (useLegacySql != null) {
549+
queryConfigurationPb.setUseLegacySql(useLegacySql);
550+
}
516551
return configurationPb.setQuery(queryConfigurationPb);
517552
}
518553

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequest.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public final class QueryRequest implements Serializable {
7070
private final Long maxWaitTime;
7171
private final Boolean dryRun;
7272
private final Boolean useQueryCache;
73+
private final Boolean useLegacySql;
7374

7475
public static final class Builder {
7576

@@ -79,6 +80,7 @@ public static final class Builder {
7980
private Long maxWaitTime;
8081
private Boolean dryRun;
8182
private Boolean useQueryCache;
83+
private Boolean useLegacySql;
8284

8385
private Builder() {}
8486

@@ -150,6 +152,17 @@ public Builder useQueryCache(Boolean useQueryCache) {
150152
return this;
151153
}
152154

155+
/**
156+
* Sets whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
157+
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
158+
* Standard SQL</a>. If not set, legacy SQL dialect is used. This property is experimental and
159+
* might be subject to change.
160+
*/
161+
public Builder useLegacySql(Boolean useLegacySql) {
162+
this.useLegacySql = useLegacySql;
163+
return this;
164+
}
165+
153166
public QueryRequest build() {
154167
return new QueryRequest(this);
155168
}
@@ -162,6 +175,7 @@ private QueryRequest(Builder builder) {
162175
maxWaitTime = builder.maxWaitTime;
163176
dryRun = builder.dryRun;
164177
useQueryCache = builder.useQueryCache;
178+
useLegacySql = builder.useLegacySql;
165179
}
166180

167181
/**
@@ -218,6 +232,16 @@ public Boolean useQueryCache() {
218232
return useQueryCache;
219233
}
220234

235+
/**
236+
* Returns whether to use BigQuery's legacy SQL dialect for this query. If set to {@code false},
237+
* the query will use BigQuery's <a href="https://cloud.google.com/bigquery/sql-reference/">
238+
* Standard SQL</a>. If not set, legacy SQL dialect is used. This property is experimental and
239+
* might be subject to change.
240+
*/
241+
public Boolean useLegacySql() {
242+
return useLegacySql;
243+
}
244+
221245
/**
222246
* Returns a builder for the {@code QueryRequest} object.
223247
*/
@@ -228,7 +252,8 @@ public Builder toBuilder() {
228252
.defaultDataset(defaultDataset)
229253
.maxWaitTime(maxWaitTime)
230254
.dryRun(dryRun)
231-
.useQueryCache(useQueryCache);
255+
.useQueryCache(useQueryCache)
256+
.useLegacySql(useLegacySql);
232257
}
233258

234259
@Override
@@ -240,12 +265,14 @@ public String toString() {
240265
.add("maxWaitTime", maxWaitTime)
241266
.add("dryRun", dryRun)
242267
.add("useQueryCache", useQueryCache)
268+
.add("useLegacySql", useLegacySql)
243269
.toString();
244270
}
245271

246272
@Override
247273
public int hashCode() {
248-
return Objects.hash(query, pageSize, defaultDataset, maxWaitTime, dryRun, useQueryCache);
274+
return Objects.hash(query, pageSize, defaultDataset, maxWaitTime, dryRun, useQueryCache,
275+
useLegacySql);
249276
}
250277

251278
@Override
@@ -281,6 +308,9 @@ com.google.api.services.bigquery.model.QueryRequest toPb() {
281308
if (useQueryCache != null) {
282309
queryRequestPb.setUseQueryCache(useQueryCache);
283310
}
311+
if (useLegacySql != null) {
312+
queryRequestPb.setUseLegacySql(useLegacySql);
313+
}
284314
return queryRequestPb;
285315
}
286316

@@ -315,6 +345,9 @@ static QueryRequest fromPb(com.google.api.services.bigquery.model.QueryRequest q
315345
if (queryRequestPb.getUseQueryCache() != null) {
316346
builder.useQueryCache(queryRequestPb.getUseQueryCache());
317347
}
348+
if (queryRequestPb.getUseLegacySql() != null) {
349+
builder.useLegacySql(queryRequestPb.getUseLegacySql());
350+
}
318351
return builder.build();
319352
}
320353
}

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public static class StreamingBuffer implements Serializable {
5353
private static final long serialVersionUID = 822027055549277843L;
5454
private final long estimatedRows;
5555
private final long estimatedBytes;
56-
private final long oldestEntryTime;
56+
private final Long oldestEntryTime;
5757

58-
StreamingBuffer(long estimatedRows, long estimatedBytes, long oldestEntryTime) {
58+
StreamingBuffer(long estimatedRows, long estimatedBytes, Long oldestEntryTime) {
5959
this.estimatedRows = estimatedRows;
6060
this.estimatedBytes = estimatedBytes;
6161
this.oldestEntryTime = oldestEntryTime;
@@ -77,9 +77,9 @@ public long estimatedBytes() {
7777

7878
/**
7979
* Returns the timestamp of the oldest entry in the streaming buffer, in milliseconds since
80-
* epoch.
80+
* epoch. Returns {@code null} if the streaming buffer is empty.
8181
*/
82-
public long oldestEntryTime() {
82+
public Long oldestEntryTime() {
8383
return oldestEntryTime;
8484
}
8585

@@ -111,9 +111,13 @@ Streamingbuffer toPb() {
111111
}
112112

113113
static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
114+
Long oldestEntryTime = null;
115+
if (streamingBufferPb.getOldestEntryTime() != null) {
116+
oldestEntryTime = streamingBufferPb.getOldestEntryTime().longValue();
117+
}
114118
return new StreamingBuffer(streamingBufferPb.getEstimatedRows().longValue(),
115119
streamingBufferPb.getEstimatedBytes().longValue(),
116-
streamingBufferPb.getOldestEntryTime().longValue());
120+
oldestEntryTime);
117121
}
118122
}
119123

gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/QueryJobConfigurationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class QueryJobConfigurationTest {
7272
private static final boolean ALLOW_LARGE_RESULTS = true;
7373
private static final boolean USE_QUERY_CACHE = false;
7474
private static final boolean FLATTEN_RESULTS = true;
75+
private static final boolean USE_LEGACY_SQL = true;
7576
private static final List<UserDefinedFunction> USER_DEFINED_FUNCTIONS = ImmutableList.of(
7677
UserDefinedFunction.inline("Function"), UserDefinedFunction.fromUri("URI"));
7778
private static final QueryJobConfiguration QUERY_JOB_CONFIGURATION =
@@ -87,6 +88,7 @@ public class QueryJobConfigurationTest {
8788
.flattenResults(FLATTEN_RESULTS)
8889
.userDefinedFunctions(USER_DEFINED_FUNCTIONS)
8990
.dryRun(true)
91+
.useLegacySql(USE_LEGACY_SQL)
9092
.build();
9193

9294
@Test
@@ -127,6 +129,7 @@ public void testBuilder() {
127129
assertEquals(USER_DEFINED_FUNCTIONS, QUERY_JOB_CONFIGURATION.userDefinedFunctions());
128130
assertEquals(WRITE_DISPOSITION, QUERY_JOB_CONFIGURATION.writeDisposition());
129131
assertTrue(QUERY_JOB_CONFIGURATION.dryRun());
132+
assertTrue(QUERY_JOB_CONFIGURATION.useLegacySql());
130133
}
131134

132135
@Test
@@ -165,5 +168,6 @@ private void compareQueryJobConfiguration(QueryJobConfiguration expected,
165168
assertEquals(expected.useQueryCache(), value.useQueryCache());
166169
assertEquals(expected.userDefinedFunctions(), value.userDefinedFunctions());
167170
assertEquals(expected.writeDisposition(), value.writeDisposition());
171+
assertEquals(expected.useLegacySql(), value.useLegacySql());
168172
}
169173
}

gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNull;
21+
import static org.junit.Assert.assertTrue;
2122

2223
import org.junit.Rule;
2324
import org.junit.Test;
@@ -31,12 +32,14 @@ public class QueryRequestTest {
3132
private static final Boolean DRY_RUN = false;
3233
private static final Long PAGE_SIZE = 42L;
3334
private static final Long MAX_WAIT_TIME = 42000L;
35+
private static final Boolean USE_LEGACY_SQL = true;
3436
private static final QueryRequest QUERY_REQUEST = QueryRequest.builder(QUERY)
3537
.useQueryCache(USE_QUERY_CACHE)
3638
.defaultDataset(DATASET_ID)
3739
.dryRun(DRY_RUN)
3840
.pageSize(PAGE_SIZE)
3941
.maxWaitTime(MAX_WAIT_TIME)
42+
.useLegacySql(USE_LEGACY_SQL)
4043
.build();
4144

4245
@Rule
@@ -67,6 +70,7 @@ public void testBuilder() {
6770
assertEquals(DRY_RUN, QUERY_REQUEST.dryRun());
6871
assertEquals(PAGE_SIZE, QUERY_REQUEST.pageSize());
6972
assertEquals(MAX_WAIT_TIME, QUERY_REQUEST.maxWaitTime());
73+
assertTrue(QUERY_REQUEST.useLegacySql());
7074
thrown.expect(NullPointerException.class);
7175
QueryRequest.builder(null);
7276
}
@@ -80,6 +84,7 @@ public void testOf() {
8084
assertNull(request.dryRun());
8185
assertNull(request.pageSize());
8286
assertNull(request.maxWaitTime());
87+
assertNull(request.useLegacySql());
8388
thrown.expect(NullPointerException.class);
8489
QueryRequest.of(null);
8590
}
@@ -104,5 +109,6 @@ private void compareQueryRequest(QueryRequest expected, QueryRequest value) {
104109
assertEquals(expected.dryRun(), value.dryRun());
105110
assertEquals(expected.pageSize(), value.pageSize());
106111
assertEquals(expected.maxWaitTime(), value.maxWaitTime());
112+
assertEquals(expected.useLegacySql(), value.useLegacySql());
107113
}
108114
}

gcloud-java-compute/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ If you are using Maven, add this to your pom.xml file
2222
<dependency>
2323
<groupId>com.google.cloud</groupId>
2424
<artifactId>gcloud-java-compute</artifactId>
25-
<version>0.2.6</version>
25+
<version>0.2.7</version>
2626
</dependency>
2727
```
2828
If you are using Gradle, add this to your dependencies
2929
```Groovy
30-
compile 'com.google.cloud:gcloud-java-compute:0.2.6'
30+
compile 'com.google.cloud:gcloud-java-compute:0.2.7'
3131
```
3232
If you are using SBT, add this to your dependencies
3333
```Scala
34-
libraryDependencies += "com.google.cloud" % "gcloud-java-compute" % "0.2.6"
34+
libraryDependencies += "com.google.cloud" % "gcloud-java-compute" % "0.2.7"
3535
```
3636

3737
Example Application

0 commit comments

Comments
 (0)