func valToFloat(v bigquery.Value) float64 {
	switch v.(type) {
	case int64:
		return (float64)(v.(int64))
	case float64:
		return v.(float64)
	default:
		return math.NaN()
	}
}
valToFloat extracts a float from the bigquery.Value irrespective of the
underlying type. If the type is not int64, float64, then valToFloat returns
zero.
package query
import (
	"context"
	"math"
	"sort"
	"strings"
	"cloud.google.com/go/bigquery"
	"github.com/googleapis/google-cloud-go-testing/bigquery/bqiface"
	"github.com/m-lab/prometheus-bigquery-exporter/sql"
	"google.golang.org/api/iterator"
)
type bigQueryImpl struct {
	bqiface.Client
}
func (b *bigQueryImpl) Query(query string, visit func(row map[string]bigquery.Value) error) error {
	q := b.Client.Query(query)
	it, err := q.Read(context.Background())
	if err != nil {
		return err
	}
	var row map[string]bigquery.Value
	for err = it.Next(&row); err == nil; err = it.Next(&row) {
		err2 := visit(row)
		if err2 != nil {
			return err2
		}
	}
	if err != iterator.Done {
		return err
	}
	return nil
}
type BQRunner struct {
	runner runner
}
type runner interface {
	Query(q string, visit func(row map[string]bigquery.Value) error) error
}
func NewBQRunner(client *bigquery.Client) *BQRunner {
	return &BQRunner{
		runner: &bigQueryImpl{
			Client: bqiface.AdaptClient(client),
		},
	}
}
func (qr *BQRunner) Query(query string) ([]sql.Metric, error) {
	metrics := []sql.Metric{}
	err := qr.runner.Query(query, func(row map[string]bigquery.Value) error {
		metrics = append(metrics, rowToMetric(row))
		return nil
	})
	if err != nil {
		return nil, err
	}
	return metrics, nil
}