-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Search statistics (#2787)
- Loading branch information
1 parent
07760b7
commit 344f695
Showing
5 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/IndexUnusedReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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; | ||
|
||
/** Represents Reason of why the index was not used in a SQL search. */ | ||
@AutoValue | ||
public abstract class IndexUnusedReason implements Serializable { | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
|
||
/** | ||
* Specifies the name of the unused search index, if available. | ||
* | ||
* @param indexName indexName or {@code null} for none | ||
*/ | ||
public abstract Builder setIndexName(String indexName); | ||
|
||
/** | ||
* Specifies the high-level reason for the scenario when no search index was used. | ||
* | ||
* @param code code or {@code null} for none | ||
*/ | ||
public abstract Builder setCode(String code); | ||
|
||
/** | ||
* Free form human-readable reason for the scenario when no search index was used. | ||
* | ||
* @param message message or {@code null} for none | ||
*/ | ||
public abstract Builder setMessage(String message); | ||
|
||
/** | ||
* Specifies the base table involved in the reason that no search index was used. | ||
* | ||
* @param tableReference tableReference or {@code null} for none | ||
*/ | ||
public abstract Builder setBaseTable(TableReference tableReference); | ||
|
||
/** Creates a @code IndexUnusedReason} object. */ | ||
public abstract IndexUnusedReason build(); | ||
} | ||
|
||
public abstract Builder toBuilder(); | ||
|
||
public static Builder newBuilder() { | ||
return new AutoValue_IndexUnusedReason.Builder(); | ||
} | ||
|
||
/** | ||
* Returns the name of the unused search index, if available. | ||
* | ||
* @return value or {@code null} for none | ||
*/ | ||
@Nullable | ||
public abstract String getIndexName(); | ||
|
||
/** | ||
* Returns the high-level reason for the scenario when no search index was used. | ||
* | ||
* @return value or {@code null} for none | ||
*/ | ||
@Nullable | ||
public abstract String getCode(); | ||
|
||
/** | ||
* Returns free form human-readable reason for the scenario when no search index was used. | ||
* | ||
* @return value or {@code null} for none | ||
*/ | ||
@Nullable | ||
public abstract String getMessage(); | ||
|
||
/** | ||
* Returns the base table involved in the reason that no search index was used. | ||
* | ||
* @return value or {@code null} for none | ||
*/ | ||
@Nullable | ||
public abstract TableReference getBaseTable(); | ||
|
||
com.google.api.services.bigquery.model.IndexUnusedReason toPb() { | ||
com.google.api.services.bigquery.model.IndexUnusedReason indexUnusedReason = | ||
new com.google.api.services.bigquery.model.IndexUnusedReason(); | ||
if (getIndexName() != null) { | ||
indexUnusedReason.setIndexName(indexUnusedReason.getIndexName()); | ||
} | ||
if (getCode() != null) { | ||
indexUnusedReason.setCode(indexUnusedReason.getCode()); | ||
} | ||
if (getMessage() != null) { | ||
indexUnusedReason.setMessage(indexUnusedReason.getMessage()); | ||
} | ||
if (getBaseTable() != null) { | ||
indexUnusedReason.setBaseTable(indexUnusedReason.getBaseTable()); | ||
} | ||
return indexUnusedReason; | ||
} | ||
|
||
static IndexUnusedReason fromPb( | ||
com.google.api.services.bigquery.model.IndexUnusedReason indexUnusedReason) { | ||
Builder builder = newBuilder(); | ||
if (indexUnusedReason.getIndexName() != null) { | ||
builder.setIndexName(indexUnusedReason.getIndexName()); | ||
} | ||
if (indexUnusedReason.getCode() != null) { | ||
builder.setCode(indexUnusedReason.getCode()); | ||
} | ||
if (indexUnusedReason.getMessage() != null) { | ||
builder.setMessage(indexUnusedReason.getMessage()); | ||
} | ||
if (indexUnusedReason.getBaseTable() != null) { | ||
builder.setBaseTable(indexUnusedReason.getBaseTable()); | ||
} | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/SearchStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.bigquery; | ||
|
||
import com.google.api.services.bigquery.model.SearchStatistics; | ||
import com.google.auto.value.AutoValue; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
|
||
/** Represents Search statistics information of a search query. */ | ||
@AutoValue | ||
public abstract class SearchStats implements Serializable { | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
|
||
/** | ||
* Specifies index usage mode for the query. | ||
* | ||
* @param indexUsageMode, has three modes UNUSED, PARTIALLY_USED, and FULLY_USED | ||
*/ | ||
public abstract Builder setIndexUsageMode(String indexUsageMode); | ||
|
||
/** | ||
* When index_usage_mode is UNUSED or PARTIALLY_USED, this field explains why index was not used | ||
* in all or part of the search query. If index_usage_mode is FULLY_USED, this field is not | ||
* populated. | ||
* | ||
* @param indexUnusedReasons | ||
*/ | ||
public abstract Builder setIndexUnusedReasons(List<IndexUnusedReason> indexUnusedReasons); | ||
|
||
/** Creates a @code SearchStats} object. */ | ||
public abstract SearchStats build(); | ||
} | ||
|
||
public abstract Builder toBuilder(); | ||
|
||
public static Builder newBuilder() { | ||
return new AutoValue_SearchStats.Builder(); | ||
} | ||
|
||
@Nullable | ||
public abstract String getIndexUsageMode(); | ||
|
||
@Nullable | ||
public abstract List<IndexUnusedReason> getIndexUnusedReasons(); | ||
|
||
SearchStatistics toPb() { | ||
SearchStatistics searchStatistics = new SearchStatistics(); | ||
if (getIndexUsageMode() != null) { | ||
searchStatistics.setIndexUsageMode(getIndexUsageMode()); | ||
} | ||
if (getIndexUnusedReasons() != null) { | ||
searchStatistics.setIndexUnusedReason( | ||
getIndexUnusedReasons().stream() | ||
.map(IndexUnusedReason::toPb) | ||
.collect(Collectors.toList())); | ||
} | ||
return searchStatistics; | ||
} | ||
|
||
static SearchStats fromPb(SearchStatistics searchStatistics) { | ||
Builder builder = newBuilder(); | ||
if (searchStatistics.getIndexUsageMode() != null) { | ||
builder.setIndexUsageMode(searchStatistics.getIndexUsageMode()); | ||
} | ||
if (searchStatistics.getIndexUnusedReason() != null) { | ||
builder.setIndexUnusedReasons( | ||
searchStatistics.getIndexUnusedReason().stream() | ||
.map(IndexUnusedReason::fromPb) | ||
.collect(Collectors.toList())); | ||
} | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters