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 d3eb03a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Expand Up @@ -54,7 +54,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 +96,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 +110,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 +130,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 d3eb03a

Please sign in to comment.