Skip to content

Commit 260e2a2

Browse files
Add BadRecords to LoadStatistics (#4230)
1 parent cbe19f2 commit 260e2a2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ public static class LoadStatistics extends JobStatistics {
175175
private final Long inputFiles;
176176
private final Long outputBytes;
177177
private final Long outputRows;
178+
private final Long badRecords;
178179

179180
static final class Builder extends JobStatistics.Builder<LoadStatistics, Builder> {
180181

181182
private Long inputBytes;
182183
private Long inputFiles;
183184
private Long outputBytes;
184185
private Long outputRows;
186+
private Long badRecords;
185187

186188
private Builder() {}
187189

@@ -192,6 +194,7 @@ private Builder(com.google.api.services.bigquery.model.JobStatistics statisticsP
192194
this.inputFiles = statisticsPb.getLoad().getInputFiles();
193195
this.outputBytes = statisticsPb.getLoad().getOutputBytes();
194196
this.outputRows = statisticsPb.getLoad().getOutputRows();
197+
this.badRecords = statisticsPb.getLoad().getBadRecords();
195198
}
196199
}
197200

@@ -215,6 +218,11 @@ Builder setOutputRows(Long outputRows) {
215218
return self();
216219
}
217220

221+
Builder setBadRecords(Long badRecords) {
222+
this.badRecords = badRecords;
223+
return self();
224+
}
225+
218226
@Override
219227
LoadStatistics build() {
220228
return new LoadStatistics(this);
@@ -227,6 +235,7 @@ private LoadStatistics(Builder builder) {
227235
this.inputFiles = builder.inputFiles;
228236
this.outputBytes = builder.outputBytes;
229237
this.outputRows = builder.outputRows;
238+
this.badRecords = builder.badRecords;
230239
}
231240

232241
/** Returns the number of bytes of source data in a load job. */
@@ -249,13 +258,19 @@ public Long getOutputRows() {
249258
return outputRows;
250259
}
251260

261+
/** Returns the number of bad records reported in a job. */
262+
public Long getBadRecords() {
263+
return badRecords;
264+
}
265+
252266
@Override
253267
ToStringHelper toStringHelper() {
254268
return super.toStringHelper()
255269
.add("inputBytes", inputBytes)
256270
.add("inputFiles", inputFiles)
257271
.add("outputBytes", outputBytes)
258-
.add("outputRows", outputRows);
272+
.add("outputRows", outputRows)
273+
.add("badRecords", badRecords);
259274
}
260275

261276
@Override
@@ -268,7 +283,8 @@ public final boolean equals(Object obj) {
268283

269284
@Override
270285
public final int hashCode() {
271-
return Objects.hash(baseHashCode(), inputBytes, inputFiles, outputBytes, outputRows);
286+
return Objects.hash(
287+
baseHashCode(), inputBytes, inputFiles, outputBytes, outputRows, badRecords);
272288
}
273289

274290
@Override
@@ -278,6 +294,7 @@ com.google.api.services.bigquery.model.JobStatistics toPb() {
278294
loadStatisticsPb.setInputFiles(inputFiles);
279295
loadStatisticsPb.setOutputBytes(outputBytes);
280296
loadStatisticsPb.setOutputRows(outputRows);
297+
loadStatisticsPb.setBadRecords(badRecords);
281298
return super.toPb().setLoad(loadStatisticsPb);
282299
}
283300

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class JobStatisticsTest {
4646
private static final Long INPUT_FILES = 2L;
4747
private static final Long OUTPUT_BYTES = 3L;
4848
private static final Long OUTPUT_ROWS = 4L;
49+
private static final Long BAD_RECORDS = 1L;
4950
private static final List<TableId> REFERENCED_TABLES =
5051
ImmutableList.of(TableId.of("foo", "bar", "table1"), TableId.of("foo", "bar", "table2"));
5152
private static final List<Long> FILE_COUNT = ImmutableList.of(1L, 2L, 3L);
@@ -74,6 +75,7 @@ public class JobStatisticsTest {
7475
.setInputFiles(INPUT_FILES)
7576
.setOutputBytes(OUTPUT_BYTES)
7677
.setOutputRows(OUTPUT_ROWS)
78+
.setBadRecords(BAD_RECORDS)
7779
.build();
7880
private static final LoadStatistics LOAD_STATISTICS_INCOMPLETE =
7981
LoadStatistics.newBuilder()
@@ -82,6 +84,7 @@ public class JobStatisticsTest {
8284
.setStartTime(START_TIME)
8385
.setInputBytes(INPUT_BYTES)
8486
.setInputFiles(INPUT_FILES)
87+
.setBadRecords(BAD_RECORDS)
8588
.build();
8689
private static final List<String> SUBSTEPS1 = ImmutableList.of("substep1", "substep2");
8790
private static final List<String> SUBSTEPS2 = ImmutableList.of("substep3", "substep4");
@@ -168,6 +171,7 @@ public void testBuilder() {
168171
assertEquals(INPUT_FILES, LOAD_STATISTICS.getInputFiles());
169172
assertEquals(OUTPUT_BYTES, LOAD_STATISTICS.getOutputBytes());
170173
assertEquals(OUTPUT_ROWS, LOAD_STATISTICS.getOutputRows());
174+
assertEquals(BAD_RECORDS, LOAD_STATISTICS.getBadRecords());
171175

172176
assertEquals(CREATION_TIME, QUERY_STATISTICS.getCreationTime());
173177
assertEquals(START_TIME, QUERY_STATISTICS.getStartTime());
@@ -192,6 +196,7 @@ public void testBuilder() {
192196
assertEquals(END_TIME, LOAD_STATISTICS_INCOMPLETE.getEndTime());
193197
assertEquals(INPUT_BYTES, LOAD_STATISTICS_INCOMPLETE.getInputBytes());
194198
assertEquals(INPUT_FILES, LOAD_STATISTICS_INCOMPLETE.getInputFiles());
199+
assertEquals(BAD_RECORDS, LOAD_STATISTICS_INCOMPLETE.getBadRecords());
195200
assertEquals(null, LOAD_STATISTICS_INCOMPLETE.getOutputBytes());
196201
assertEquals(null, LOAD_STATISTICS_INCOMPLETE.getOutputRows());
197202

0 commit comments

Comments
 (0)