Skip to content

Commit

Permalink
feat(bigquery): add BI Engine information to query statistics (#5081)
Browse files Browse the repository at this point in the history
Fixes: #5080
  • Loading branch information
shollyman committed Nov 4, 2021
1 parent 6be4cae commit b78c89b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bigquery/integration_test.go
Expand Up @@ -2015,6 +2015,20 @@ func TestIntegration_QueryStatistics(t *testing.T) {
if len(qStats.Timeline) == 0 {
t.Error("expected query timeline, none present")
}

if qStats.BIEngineStatistics == nil {
t.Error("expected BIEngine statistics, none present")
}

expectedMode := true
for _, m := range []string{"FULL", "PARTIAL", "DISABLED"} {
if qStats.BIEngineStatistics.BIEngineMode == m {
expectedMode = true
}
}
if !expectedMode {
t.Errorf("unexpected BIEngineMode for BI Engine statistics, got %s", qStats.BIEngineStatistics.BIEngineMode)
}
}

func TestIntegration_Load(t *testing.T) {
Expand Down
50 changes: 50 additions & 0 deletions bigquery/job.go
Expand Up @@ -419,6 +419,10 @@ type LoadStatistics struct {

// QueryStatistics contains statistics about a query job.
type QueryStatistics struct {

// BI-Engine specific statistics.
BIEngineStatistics *BIEngineStatistics

// Billing tier for the job.
BillingTier int64

Expand Down Expand Up @@ -483,6 +487,51 @@ type QueryStatistics struct {
DDLTargetRoutine *Routine
}

// BIEngineStatistics contains query statistics specific to the use of BI Engine.
type BIEngineStatistics struct {
// Specifies which mode of BI Engine acceleration was performed.
BIEngineMode string

// In case of DISABLED or PARTIAL BIEngineMode, these
// contain the explanatory reasons as to why BI Engine could not
// accelerate. In case the full query was accelerated, this field is not
// populated.
BIEngineReasons []*BIEngineReason
}

func bqToBIEngineStatistics(in *bq.BiEngineStatistics) *BIEngineStatistics {
if in == nil {
return nil
}
stats := &BIEngineStatistics{
BIEngineMode: in.BiEngineMode,
}
for _, v := range in.BiEngineReasons {
stats.BIEngineReasons = append(stats.BIEngineReasons, bqToBIEngineReason(v))
}
return stats
}

// BIEngineReason contains more detailed information about why a query wasn't fully
// accelerated.
type BIEngineReason struct {
// High-Level BI engine reason for partial or disabled acceleration.
Code string

// Human-readable reason for partial or disabled acceleration.
Message string
}

func bqToBIEngineReason(in *bq.BiEngineReason) *BIEngineReason {
if in == nil {
return nil
}
return &BIEngineReason{
Code: in.Code,
Message: in.Message,
}
}

// ExplainQueryStage describes one stage of a query.
type ExplainQueryStage struct {
// CompletedParallelInputs: Number of parallel input segments completed.
Expand Down Expand Up @@ -922,6 +971,7 @@ func (j *Job) setStatistics(s *bq.JobStatistics, c *Client) {
tables = append(tables, bqToTable(tr, c))
}
js.Details = &QueryStatistics{
BIEngineStatistics: bqToBIEngineStatistics(s.Query.BiEngineStatistics),
BillingTier: s.Query.BillingTier,
CacheHit: s.Query.CacheHit,
DDLTargetTable: bqToTable(s.Query.DdlTargetTable, c),
Expand Down

0 comments on commit b78c89b

Please sign in to comment.