Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19b7c3a

Browse files
PhongChuonggcf-owl-bot[bot]
andauthoredNov 9, 2023
feat: Add InputBytes to extract job statistics (#2998)
* feat: Add InputBytes to extract job statistics * feat: Add InputBytes to extract job statistics * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 6d14b27 commit 19b7c3a

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ implementation 'com.google.cloud:google-cloud-bigquery'
6060
If you are using Gradle without BOM, add this to your dependencies:
6161

6262
```Groovy
63-
implementation 'com.google.cloud:google-cloud-bigquery:2.34.1'
63+
implementation 'com.google.cloud:google-cloud-bigquery:2.34.2'
6464
```
6565

6666
If you are using SBT, add this to your dependencies:
6767

6868
```Scala
69-
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.34.1"
69+
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.34.2"
7070
```
7171
<!-- {x-version-update-end} -->
7272

@@ -351,7 +351,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
351351
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigquery/java11.html
352352
[stability-image]: https://img.shields.io/badge/stability-stable-green
353353
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigquery.svg
354-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.34.1
354+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-bigquery/2.34.2
355355
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
356356
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
357357
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,21 @@ public static class ExtractStatistics extends JobStatistics {
101101

102102
private final List<Long> destinationUriFileCounts;
103103

104+
private final Long inputBytes;
105+
104106
static final class Builder extends JobStatistics.Builder<ExtractStatistics, Builder> {
105107

106108
private List<Long> destinationUriFileCounts;
107109

110+
private Long inputBytes;
111+
108112
private Builder() {}
109113

110114
private Builder(com.google.api.services.bigquery.model.JobStatistics statisticsPb) {
111115
super(statisticsPb);
112116
if (statisticsPb.getExtract() != null) {
113117
this.destinationUriFileCounts = statisticsPb.getExtract().getDestinationUriFileCounts();
118+
this.inputBytes = statisticsPb.getExtract().getInputBytes();
114119
}
115120
}
116121

@@ -119,6 +124,11 @@ Builder setDestinationUriFileCounts(List<Long> destinationUriFileCounts) {
119124
return self();
120125
}
121126

127+
Builder setInputBytes(Long inputBytes) {
128+
this.inputBytes = inputBytes;
129+
return self();
130+
}
131+
122132
@Override
123133
ExtractStatistics build() {
124134
return new ExtractStatistics(this);
@@ -128,6 +138,7 @@ ExtractStatistics build() {
128138
private ExtractStatistics(Builder builder) {
129139
super(builder);
130140
this.destinationUriFileCounts = builder.destinationUriFileCounts;
141+
this.inputBytes = builder.inputBytes;
131142
}
132143

133144
/**
@@ -139,6 +150,11 @@ public List<Long> getDestinationUriFileCounts() {
139150
return destinationUriFileCounts;
140151
}
141152

153+
/** Returns number of user bytes extracted into the result. */
154+
public Long getInputBytes() {
155+
return inputBytes;
156+
}
157+
142158
@Override
143159
ToStringHelper toStringHelper() {
144160
return super.toStringHelper().add("destinationUriFileCounts", destinationUriFileCounts);
@@ -159,9 +175,10 @@ public final int hashCode() {
159175

160176
@Override
161177
com.google.api.services.bigquery.model.JobStatistics toPb() {
162-
com.google.api.services.bigquery.model.JobStatistics statisticsPb = super.toPb();
163-
return statisticsPb.setExtract(
164-
new JobStatistics4().setDestinationUriFileCounts(destinationUriFileCounts));
178+
JobStatistics4 extractStatisticsPb = new JobStatistics4();
179+
extractStatisticsPb.setDestinationUriFileCounts(destinationUriFileCounts);
180+
extractStatisticsPb.setInputBytes(inputBytes);
181+
return super.toPb().setExtract(extractStatisticsPb);
165182
}
166183

167184
static Builder newBuilder() {

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class JobStatisticsTest {
9797
.setEndTime(END_TIME)
9898
.setStartTime(START_TIME)
9999
.setDestinationUriFileCounts(FILE_COUNT)
100+
.setInputBytes(INPUT_BYTES)
100101
.build();
101102
private static final LoadStatistics LOAD_STATISTICS =
102103
LoadStatistics.newBuilder()
@@ -249,6 +250,7 @@ public void testBuilder() {
249250
assertEquals(START_TIME, EXTRACT_STATISTICS.getStartTime());
250251
assertEquals(END_TIME, EXTRACT_STATISTICS.getEndTime());
251252
assertEquals(FILE_COUNT, EXTRACT_STATISTICS.getDestinationUriFileCounts());
253+
assertEquals(INPUT_BYTES, EXTRACT_STATISTICS.getInputBytes());
252254

253255
assertEquals(CREATION_TIME, LOAD_STATISTICS.getCreationTime());
254256
assertEquals(START_TIME, LOAD_STATISTICS.getStartTime());
@@ -385,6 +387,7 @@ private void compareExtractStatistics(ExtractStatistics expected, ExtractStatist
385387
assertEquals(expected, value);
386388
compareStatistics(expected, value);
387389
assertEquals(expected.getDestinationUriFileCounts(), value.getDestinationUriFileCounts());
390+
assertEquals(expected.getInputBytes(), value.getInputBytes());
388391
}
389392

390393
private void compareLoadStatistics(LoadStatistics expected, LoadStatistics value) {

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import com.google.cloud.bigquery.JobId;
8888
import com.google.cloud.bigquery.JobInfo;
8989
import com.google.cloud.bigquery.JobStatistics;
90+
import com.google.cloud.bigquery.JobStatistics.ExtractStatistics;
9091
import com.google.cloud.bigquery.JobStatistics.LoadStatistics;
9192
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
9293
import com.google.cloud.bigquery.JobStatistics.QueryStatistics.StatementType;
@@ -5304,6 +5305,8 @@ public void testExtractJob() throws InterruptedException, TimeoutException {
53045305
assertNull(remoteLoadJob.getStatus().getError());
53055306
LoadJobConfiguration loadJobConfiguration = remoteLoadJob.getConfiguration();
53065307
assertEquals(labels, loadJobConfiguration.getLabels());
5308+
LoadStatistics loadStatistics = remoteLoadJob.getStatistics();
5309+
assertNotNull(loadStatistics);
53075310

53085311
ExtractJobConfiguration extractConfiguration =
53095312
ExtractJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + EXTRACT_FILE)
@@ -5313,6 +5316,12 @@ public void testExtractJob() throws InterruptedException, TimeoutException {
53135316
remoteExtractJob = remoteExtractJob.waitFor();
53145317
assertNull(remoteExtractJob.getStatus().getError());
53155318

5319+
ExtractStatistics extractStatistics = remoteExtractJob.getStatistics();
5320+
assertNotNull(extractStatistics);
5321+
assertEquals(1L, extractStatistics.getDestinationUriFileCounts().size());
5322+
assertEquals(
5323+
loadStatistics.getOutputBytes().longValue(), extractStatistics.getInputBytes().longValue());
5324+
53165325
String extractedCsv =
53175326
new String(storage.readAllBytes(BUCKET, EXTRACT_FILE), StandardCharsets.UTF_8);
53185327
assertEquals(

0 commit comments

Comments
 (0)
Failed to load comments.