query.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2015 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bigquery
  15. import bq "google.golang.org/api/bigquery/v2"
  16. // Query represents a query to be executed.
  17. type Query struct {
  18. // The query to execute. See https://cloud.google.com/bigquery/query-reference for details.
  19. Q string
  20. // DefaultProjectID and DefaultDatasetID specify the dataset to use for unqualified table names in the query.
  21. // If DefaultProjectID is set, DefaultDatasetID must also be set.
  22. DefaultProjectID string
  23. DefaultDatasetID string
  24. }
  25. func (q *Query) implementsSource() {}
  26. func (q *Query) implementsReadSource() {}
  27. func (q *Query) customizeQuerySrc(conf *bq.JobConfigurationQuery, projectID string) {
  28. conf.Query = q.Q
  29. if q.DefaultProjectID != "" || q.DefaultDatasetID != "" {
  30. conf.DefaultDataset = &bq.DatasetReference{
  31. DatasetId: q.DefaultDatasetID,
  32. ProjectId: q.DefaultProjectID,
  33. }
  34. }
  35. }