You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
2.7 KiB

  1. // Copyright 2015 Google LLC
  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 (
  16. "io"
  17. bq "google.golang.org/api/bigquery/v2"
  18. )
  19. // GCSReference is a reference to one or more Google Cloud Storage objects, which together constitute
  20. // an input or output to a BigQuery operation.
  21. type GCSReference struct {
  22. // URIs refer to Google Cloud Storage objects.
  23. URIs []string
  24. FileConfig
  25. // DestinationFormat is the format to use when writing exported files.
  26. // Allowed values are: CSV, Avro, JSON. The default is CSV.
  27. // CSV is not supported for tables with nested or repeated fields.
  28. DestinationFormat DataFormat
  29. // Compression specifies the type of compression to apply when writing data
  30. // to Google Cloud Storage, or using this GCSReference as an ExternalData
  31. // source with CSV or JSON SourceFormat. Default is None.
  32. Compression Compression
  33. }
  34. // NewGCSReference constructs a reference to one or more Google Cloud Storage objects, which together constitute a data source or destination.
  35. // In the simple case, a single URI in the form gs://bucket/object may refer to a single GCS object.
  36. // Data may also be split into mutiple files, if multiple URIs or URIs containing wildcards are provided.
  37. // Each URI may contain one '*' wildcard character, which (if present) must come after the bucket name.
  38. // For more information about the treatment of wildcards and multiple URIs,
  39. // see https://cloud.google.com/bigquery/exporting-data-from-bigquery#exportingmultiple
  40. func NewGCSReference(uri ...string) *GCSReference {
  41. return &GCSReference{URIs: uri}
  42. }
  43. // Compression is the type of compression to apply when writing data to Google Cloud Storage.
  44. type Compression string
  45. const (
  46. // None specifies no compression.
  47. None Compression = "NONE"
  48. // Gzip specifies gzip compression.
  49. Gzip Compression = "GZIP"
  50. )
  51. func (gcs *GCSReference) populateLoadConfig(lc *bq.JobConfigurationLoad) io.Reader {
  52. lc.SourceUris = gcs.URIs
  53. gcs.FileConfig.populateLoadConfig(lc)
  54. return nil
  55. }
  56. func (gcs *GCSReference) toBQ() bq.ExternalDataConfiguration {
  57. conf := bq.ExternalDataConfiguration{
  58. Compression: string(gcs.Compression),
  59. SourceUris: append([]string{}, gcs.URIs...),
  60. }
  61. gcs.FileConfig.populateExternalDataConfig(&conf)
  62. return conf
  63. }