Skip to content

Commit b78c89b

Browse files
authored
feat(bigquery): add BI Engine information to query statistics (#5081)
Fixes: #5080
1 parent 6be4cae commit b78c89b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Diff for: bigquery/integration_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,20 @@ func TestIntegration_QueryStatistics(t *testing.T) {
20152015
if len(qStats.Timeline) == 0 {
20162016
t.Error("expected query timeline, none present")
20172017
}
2018+
2019+
if qStats.BIEngineStatistics == nil {
2020+
t.Error("expected BIEngine statistics, none present")
2021+
}
2022+
2023+
expectedMode := true
2024+
for _, m := range []string{"FULL", "PARTIAL", "DISABLED"} {
2025+
if qStats.BIEngineStatistics.BIEngineMode == m {
2026+
expectedMode = true
2027+
}
2028+
}
2029+
if !expectedMode {
2030+
t.Errorf("unexpected BIEngineMode for BI Engine statistics, got %s", qStats.BIEngineStatistics.BIEngineMode)
2031+
}
20182032
}
20192033

20202034
func TestIntegration_Load(t *testing.T) {

Diff for: bigquery/job.go

+50
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ type LoadStatistics struct {
419419

420420
// QueryStatistics contains statistics about a query job.
421421
type QueryStatistics struct {
422+
423+
// BI-Engine specific statistics.
424+
BIEngineStatistics *BIEngineStatistics
425+
422426
// Billing tier for the job.
423427
BillingTier int64
424428

@@ -483,6 +487,51 @@ type QueryStatistics struct {
483487
DDLTargetRoutine *Routine
484488
}
485489

490+
// BIEngineStatistics contains query statistics specific to the use of BI Engine.
491+
type BIEngineStatistics struct {
492+
// Specifies which mode of BI Engine acceleration was performed.
493+
BIEngineMode string
494+
495+
// In case of DISABLED or PARTIAL BIEngineMode, these
496+
// contain the explanatory reasons as to why BI Engine could not
497+
// accelerate. In case the full query was accelerated, this field is not
498+
// populated.
499+
BIEngineReasons []*BIEngineReason
500+
}
501+
502+
func bqToBIEngineStatistics(in *bq.BiEngineStatistics) *BIEngineStatistics {
503+
if in == nil {
504+
return nil
505+
}
506+
stats := &BIEngineStatistics{
507+
BIEngineMode: in.BiEngineMode,
508+
}
509+
for _, v := range in.BiEngineReasons {
510+
stats.BIEngineReasons = append(stats.BIEngineReasons, bqToBIEngineReason(v))
511+
}
512+
return stats
513+
}
514+
515+
// BIEngineReason contains more detailed information about why a query wasn't fully
516+
// accelerated.
517+
type BIEngineReason struct {
518+
// High-Level BI engine reason for partial or disabled acceleration.
519+
Code string
520+
521+
// Human-readable reason for partial or disabled acceleration.
522+
Message string
523+
}
524+
525+
func bqToBIEngineReason(in *bq.BiEngineReason) *BIEngineReason {
526+
if in == nil {
527+
return nil
528+
}
529+
return &BIEngineReason{
530+
Code: in.Code,
531+
Message: in.Message,
532+
}
533+
}
534+
486535
// ExplainQueryStage describes one stage of a query.
487536
type ExplainQueryStage struct {
488537
// CompletedParallelInputs: Number of parallel input segments completed.
@@ -922,6 +971,7 @@ func (j *Job) setStatistics(s *bq.JobStatistics, c *Client) {
922971
tables = append(tables, bqToTable(tr, c))
923972
}
924973
js.Details = &QueryStatistics{
974+
BIEngineStatistics: bqToBIEngineStatistics(s.Query.BiEngineStatistics),
925975
BillingTier: s.Query.BillingTier,
926976
CacheHit: s.Query.CacheHit,
927977
DDLTargetTable: bqToTable(s.Query.DdlTargetTable, c),

0 commit comments

Comments
 (0)