Class: Google::Cloud::Bigquery::CopyJob

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

Overview

CopyJob

A Job subclass representing a copy operation that may be performed on a Table. A CopyJob instance is created when you call Table#copy_job.

Examples:

require "google/cloud/bigquery"

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

copy_job = table.copy_job destination_table

copy_job.wait_until_done!
copy_job.done? #=> true

See Also:

Direct Known Subclasses

Updater

Defined Under Namespace

Classes: Updater

Attributes collapse

Instance Method Summary collapse

Methods inherited from Job

#cancel, #configuration, #created_at, #delete, #done?, #ended_at, #error, #errors, #failed?, #job_id, #labels, #location, #num_child_jobs, #parent_job_id, #pending?, #project_id, #reload!, #rerun!, #reservation_usage, #running?, #script_statistics, #session_id, #started_at, #state, #statistics, #status, #transaction_id, #user_email, #wait_until_done!

Instance Method Details

#create_if_needed?Boolean

Checks if the create disposition for the job is CREATE_IF_NEEDED, which provides the following behavior: If the table does not exist, the copy operation creates the table. This is the default create disposition for copy jobs.

Returns:

  • (Boolean)

    true when CREATE_IF_NEEDED, false otherwise.



106
107
108
109
# File 'lib/google/cloud/bigquery/copy_job.rb', line 106

def create_if_needed?
  disp = @gapi.configuration.copy.create_disposition
  disp == "CREATE_IF_NEEDED"
end

#create_never?Boolean

Checks if the create disposition for the job is CREATE_NEVER, which provides the following behavior: The table must already exist; if it does not, an error is returned in the job result.

Returns:

  • (Boolean)

    true when CREATE_NEVER, false otherwise.



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

def create_never?
  disp = @gapi.configuration.copy.create_disposition
  disp == "CREATE_NEVER"
end

#destination(view: nil) ⇒ Table

The table to which data is copied.

Parameters:

  • view (String) (defaults to: nil)

    Specifies the view that determines which table information is returned. By default, basic table information and storage statistics (STORAGE_STATS) are returned. Accepted values include :unspecified, :basic, :storage, and :full. For more information, see BigQuery Classes. The default value is the :unspecified view type.

Returns:

  • (Table)

    A table instance.



92
93
94
95
96
# File 'lib/google/cloud/bigquery/copy_job.rb', line 92

def destination view: nil
  table = @gapi.configuration.copy.destination_table
  return nil unless table
  retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
end

#encryptionGoogle::Cloud::BigQuery::EncryptionConfiguration

The encryption configuration of the destination table.

Returns:

  • (Google::Cloud::BigQuery::EncryptionConfiguration)

    Custom encryption configuration (e.g., Cloud KMS keys).



167
168
169
# File 'lib/google/cloud/bigquery/copy_job.rb', line 167

def encryption
  EncryptionConfiguration.from_gapi @gapi.configuration.copy.destination_encryption_configuration
end

#source(view: nil) ⇒ Table

The table from which data is copied. This is the table on which Table#copy_job was called.

Parameters:

  • view (String) (defaults to: nil)

    Specifies the view that determines which table information is returned. By default, basic table information and storage statistics (STORAGE_STATS) are returned. Accepted values include :unspecified, :basic, :storage, and :full. For more information, see BigQuery Classes. The default value is the :unspecified view type.

Returns:

  • (Table)

    A table instance.



75
76
77
78
79
# File 'lib/google/cloud/bigquery/copy_job.rb', line 75

def source view: nil
  table = @gapi.configuration.copy.source_table
  return nil unless table
  retrieve_table table.project_id, table.dataset_id, table.table_id, metadata_view: view
end

#write_append?Boolean

Checks if the write disposition for the job is WRITE_APPEND, which provides the following behavior: If the table already exists, the copy operation appends the data to the table.

Returns:

  • (Boolean)

    true when WRITE_APPEND, false otherwise.



142
143
144
145
# File 'lib/google/cloud/bigquery/copy_job.rb', line 142

def write_append?
  disp = @gapi.configuration.copy.write_disposition
  disp == "WRITE_APPEND"
end

#write_empty?Boolean

Checks if the write disposition for the job is WRITE_EMPTY, which provides the following behavior: If the table already exists and contains data, the job will have an error. This is the default write disposition for copy jobs.

Returns:

  • (Boolean)

    true when WRITE_EMPTY, false otherwise.



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

def write_empty?
  disp = @gapi.configuration.copy.write_disposition
  disp == "WRITE_EMPTY"
end

#write_truncate?Boolean

Checks if the write disposition for the job is WRITE_TRUNCATE, which provides the following behavior: If the table already exists, the copy operation overwrites the table data.

Returns:

  • (Boolean)

    true when WRITE_TRUNCATE, false otherwise.



130
131
132
133
# File 'lib/google/cloud/bigquery/copy_job.rb', line 130

def write_truncate?
  disp = @gapi.configuration.copy.write_disposition
  disp == "WRITE_TRUNCATE"
end