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 Jul 27, 2023
1 parent eb250a8 commit beb6c64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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 setBaseTable(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 getBaseTable();

com.google.api.services.bigquery.model.IndexUnusedReason toPb() {
com.google.api.services.bigquery.model.IndexUnusedReason indexUnusedReason =
Expand All @@ -110,8 +109,9 @@ com.google.api.services.bigquery.model.IndexUnusedReason toPb() {
if (getMessage() != null) {
indexUnusedReason.setMessage(indexUnusedReason.getMessage());
}
// From other examples i can see TableId.tbPb() for Base table in CloneDefinition
if (getBaseTable() != null) {
indexUnusedReason.setBaseTable(indexUnusedReason.getBaseTable());
indexUnusedReason.setBaseTable(getBaseTable().toPb());
}
return indexUnusedReason;
}
Expand All @@ -129,7 +129,7 @@ static IndexUnusedReason fromPb(
builder.setMessage(indexUnusedReason.getMessage());
}
if (indexUnusedReason.getBaseTable() != null) {
builder.setBaseTable(indexUnusedReason.getBaseTable());
builder.setBaseTable(TableId.fromPb(indexUnusedReason.getBaseTable()));
}
return builder.build();
}
Expand Down
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,11 @@ public void testQueryJobWithSearchReturnsSearchStatistics() throws InterruptedEx
JobStatistics.QueryStatistics stats = remoteJob.getStatistics();
assertNotNull(stats.getSearchStats());
assertEquals(stats.getSearchStats().getIndexUsageMode(), "UNUSED");

System.out.println("Penguins");
System.out.println(stats.getSearchStats().getIndexUnusedReasons());
System.out.println("Horses");

} finally {
bigquery.delete(destinationTable);
}
Expand Down

0 comments on commit beb6c64

Please sign in to comment.