bigqueryquerier.go 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package gcp
  2. import (
  3. "context"
  4. "cloud.google.com/go/bigquery"
  5. "github.com/opencost/opencost/pkg/cloud"
  6. cloudconfig "github.com/opencost/opencost/pkg/cloud/config"
  7. )
  8. type BigQueryQuerier struct {
  9. BigQueryConfiguration
  10. ConnectionStatus cloud.ConnectionStatus
  11. }
  12. func (bqq *BigQueryQuerier) Equals(config cloudconfig.Config) bool {
  13. thatConfig, ok := config.(*BigQueryQuerier)
  14. if !ok {
  15. return false
  16. }
  17. return bqq.BigQueryConfiguration.Equals(&thatConfig.BigQueryConfiguration)
  18. }
  19. func (bqq *BigQueryQuerier) Query(ctx context.Context, queryStr string) (*bigquery.RowIterator, error) {
  20. err := bqq.Validate()
  21. if err != nil {
  22. bqq.ConnectionStatus = cloud.InvalidConfiguration
  23. return nil, err
  24. }
  25. client, err := bqq.GetBigQueryClient(ctx)
  26. if err != nil {
  27. bqq.ConnectionStatus = cloud.FailedConnection
  28. return nil, err
  29. }
  30. query := client.Query(queryStr)
  31. return query.Read(ctx)
  32. }