Class: Google::Cloud::Bigquery::ExtractJob

Inherits:
Job
  • Object
show all
Defined in:
lib/google/cloud/bigquery/extract_job.rb

Overview

ExtractJob

A Job subclass representing an export operation that may be performed on a Table. A ExtractJob instance is created when you call Table#extract_job.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
table = dataset.table "my_table"

extract_job = table.extract_job "gs://my-bucket/file-name.json",
                                format: "json"
extract_job.wait_until_done!
extract_job.done? #=> true

See Also:

Direct Known Subclasses

Updater

Defined Under Namespace

Classes: Updater

Instance Method Summary collapse

Methods inherited from Job

#cancel, #configuration, #created_at, #done?, #ended_at, #error, #errors, #failed?, #job_id, #labels, #location, #pending?, #project_id, #reload!, #rerun!, #running?, #started_at, #state, #statistics, #status, #user_email, #wait_until_done!

Instance Method Details

#avro?Boolean

Checks if the destination format for the data is Avro. The default is false.

Returns:

  • (Boolean)

    true when AVRO, false otherwise.



107
108
109
110
# File 'lib/google/cloud/bigquery/extract_job.rb', line 107

def avro?
  val = @gapi.configuration.extract.destination_format
  val == "AVRO"
end

#compression?Boolean

Checks if the export operation compresses the data using gzip. The default is false.

Returns:

  • (Boolean)

    true when GZIP, false otherwise.



71
72
73
74
# File 'lib/google/cloud/bigquery/extract_job.rb', line 71

def compression?
  val = @gapi.configuration.extract.compression
  val == "GZIP"
end

#csv?Boolean

Checks if the destination format for the data is CSV. Tables with nested or repeated fields cannot be exported as CSV. The default is true.

Returns:

  • (Boolean)

    true when CSV, false otherwise.



95
96
97
98
99
# File 'lib/google/cloud/bigquery/extract_job.rb', line 95

def csv?
  val = @gapi.configuration.extract.destination_format
  return true if val.nil?
  val == "CSV"
end

#delimiterString

The character or symbol the operation uses to delimit fields in the exported data. The default is a comma (,).

Returns:

  • (String)

    A string containing the character, such as ",".



118
119
120
121
122
# File 'lib/google/cloud/bigquery/extract_job.rb', line 118

def delimiter
  val = @gapi.configuration.extract.field_delimiter
  val = "," if val.nil?
  val
end

#destinationsObject

The URI or URIs representing the Google Cloud Storage files to which the data is exported.



47
48
49
# File 'lib/google/cloud/bigquery/extract_job.rb', line 47

def destinations
  Array @gapi.configuration.extract.destination_uris
end

#destinations_countsHash<String, Integer>

A hash containing the URI or URI pattern specified in #destinations mapped to the counts of files per destination.

Returns:

  • (Hash<String, Integer>)

    A Hash with the URI patterns as keys and the counts as values.



155
156
157
# File 'lib/google/cloud/bigquery/extract_job.rb', line 155

def destinations_counts
  Hash[destinations.zip destinations_file_counts]
end

#destinations_file_countsArray<Integer>

The number of files per destination URI or URI pattern specified in #destinations.

Returns:

  • (Array<Integer>)

    An array of values in the same order as the URI patterns.



144
145
146
# File 'lib/google/cloud/bigquery/extract_job.rb', line 144

def destinations_file_counts
  Array @gapi.statistics.extract.destination_uri_file_counts
end

#json?Boolean

Checks if the destination format for the data is newline-delimited JSON. The default is false.

Returns:

  • (Boolean)

    true when NEWLINE_DELIMITED_JSON, false otherwise.



83
84
85
86
# File 'lib/google/cloud/bigquery/extract_job.rb', line 83

def json?
  val = @gapi.configuration.extract.destination_format
  val == "NEWLINE_DELIMITED_JSON"
end

Checks if the exported data contains a header row. The default is true.

Returns:

  • (Boolean)

    true when the print header configuration is present or nil, false otherwise.



131
132
133
134
135
# File 'lib/google/cloud/bigquery/extract_job.rb', line 131

def print_header?
  val = @gapi.configuration.extract.print_header
  val = true if val.nil?
  val
end

#sourceTable

The table from which the data is exported. This is the table upon which Table#extract_job was called.

Returns:

  • (Table)

    A table instance.



57
58
59
60
61
62
63
# File 'lib/google/cloud/bigquery/extract_job.rb', line 57

def source
  table = @gapi.configuration.extract.source_table
  return nil unless table
  retrieve_table table.project_id,
                 table.dataset_id,
                 table.table_id
end