Skip to content

Commit

Permalink
fix: SearchStats IndexUnusedReasons null bug
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan0102 committed Aug 17, 2023
1 parent eb250a8 commit 5a723c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.cloud.bigquery;

import com.google.api.services.bigquery.model.TableReference;
import com.google.auto.value.AutoValue;
import java.io.Serializable;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -54,7 +53,7 @@ public abstract static class Builder {
*
* @param tableReference tableReference or {@code null} for none
*/
public abstract Builder setBaseTable(TableReference tableReference);
public abstract Builder setBaseTableId(TableId tableReference);

/** Creates a @code IndexUnusedReason} object. */
public abstract IndexUnusedReason build();
Expand Down Expand Up @@ -96,7 +95,7 @@ public static Builder newBuilder() {
* @return value or {@code null} for none
*/
@Nullable
public abstract TableReference getBaseTable();
public abstract TableId getBaseTableId();

com.google.api.services.bigquery.model.IndexUnusedReason toPb() {
com.google.api.services.bigquery.model.IndexUnusedReason indexUnusedReason =
Expand All @@ -110,8 +109,8 @@ com.google.api.services.bigquery.model.IndexUnusedReason toPb() {
if (getMessage() != null) {
indexUnusedReason.setMessage(indexUnusedReason.getMessage());
}
if (getBaseTable() != null) {
indexUnusedReason.setBaseTable(indexUnusedReason.getBaseTable());
if (getBaseTableId() != null) {
indexUnusedReason.setBaseTable(getBaseTableId().toPb());
}
return indexUnusedReason;
}
Expand All @@ -129,7 +128,7 @@ static IndexUnusedReason fromPb(
builder.setMessage(indexUnusedReason.getMessage());
}
if (indexUnusedReason.getBaseTable() != null) {
builder.setBaseTable(indexUnusedReason.getBaseTable());
builder.setBaseTableId(TableId.fromPb(indexUnusedReason.getBaseTable()));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SearchStatistics toPb() {
searchStatistics.setIndexUsageMode(getIndexUsageMode());
}
if (getIndexUnusedReasons() != null) {
searchStatistics.setIndexUnusedReason(
searchStatistics.setIndexUnusedReasons(
getIndexUnusedReasons().stream()
.map(IndexUnusedReason::toPb)
.collect(Collectors.toList()));
Expand All @@ -81,9 +81,9 @@ static SearchStats fromPb(SearchStatistics searchStatistics) {
if (searchStatistics.getIndexUsageMode() != null) {
builder.setIndexUsageMode(searchStatistics.getIndexUsageMode());
}
if (searchStatistics.getIndexUnusedReason() != null) {
if (searchStatistics.getIndexUnusedReasons() != null) {
builder.setIndexUnusedReasons(
searchStatistics.getIndexUnusedReason().stream()
searchStatistics.getIndexUnusedReasons().stream()
.map(IndexUnusedReason::fromPb)
.collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5090,7 +5090,7 @@ public void testQueryJobWithLabels() throws InterruptedException, TimeoutExcepti
}

@Test
public void testQueryJobWithSearchReturnsSearchStatistics() throws InterruptedException {
public void testQueryJobWithSearchReturnsSearchStatisticsUnused() throws InterruptedException {
String tableName = "test_query_job_table";
String query =
"SELECT * FROM "
Expand All @@ -5109,6 +5109,10 @@ public void testQueryJobWithSearchReturnsSearchStatistics() throws InterruptedEx
JobStatistics.QueryStatistics stats = remoteJob.getStatistics();
assertNotNull(stats.getSearchStats());
assertEquals(stats.getSearchStats().getIndexUsageMode(), "UNUSED");
assertNotNull(stats.getSearchStats().getIndexUnusedReasons());
assertNotNull(
stats.getSearchStats().getIndexUnusedReasons().get(0).getCode(),
"INDEX_CONFIG_NOT_AVAILABLE");
} finally {
bigquery.delete(destinationTable);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<github.global.server>github</github.global.server>
<site.installationModule>google-cloud-bigquery-parent</site.installationModule>
<google-api-services-bigquery.version>v2-rev20230520-2.0.0</google-api-services-bigquery.version>
<google-api-services-bigquery.version>v2-rev20230805-2.0.0</google-api-services-bigquery.version>
<google.cloud.shared-dependencies.version>3.13.1</google.cloud.shared-dependencies.version>
<arrow.version>12.0.1</arrow.version>
</properties>
Expand Down

0 comments on commit 5a723c9

Please sign in to comment.