Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,10 @@ def wait_until_done!
def data token: nil, max: nil, start: nil
return nil unless done?
return Data.from_gapi_json({ rows: [] }, nil, @gapi, service) if dryrun?
if ddl? || dml?
if ddl? || dml? || !ensure_schema!
data_hash = { totalRows: nil, rows: [] }
return Data.from_gapi_json data_hash, nil, @gapi, service
end
ensure_schema!

data_hash = service.list_tabledata destination_table_dataset_id,
destination_table_table_id,
Expand Down Expand Up @@ -1791,10 +1790,10 @@ def self.from_gapi gapi
protected

def ensure_schema!
return unless destination_schema.nil?
return true unless destination_schema.nil?

query_results_gapi = service.job_query_results job_id, location: location, max: 0
# raise "unable to retrieve schema" if query_results_gapi.schema.nil?
return false if query_results_gapi.schema.nil?
@destination_schema_gapi = query_results_gapi.schema
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,32 @@
_(data.class).must_equal Google::Cloud::Bigquery::Data
end

it "does not call list_table_data is no schema present" do
mock = Minitest::Mock.new
bigquery.service.mocked_service = mock
query_hash = {
"kind" => "bigquery#getQueryResultsResponse",
"etag" => "etag1234567890",
"jobReference" => {
"projectId" => "my-project",
"jobId" => "job9876543210"
},
"pageToken" => "token1234567890",
"totalRows" => 3,
"totalBytesProcessed" => "456789", # String per google/google-api-ruby-client#439
"jobComplete" => true,
"cacheHit" => false
}
mock.expect :get_job_query_results,
Google::Apis::BigqueryV2::QueryResponse.from_json(query_hash.to_json),
[project, job.job_id], location: "US", max_results: 0, page_token: nil, start_index: nil, timeout_ms: nil

data = job.data start: 25
mock.verify

_(data.class).must_equal Google::Cloud::Bigquery::Data
end

def query_job_gapi
json = query_job_resp_json("SELECT name, age, score, active FROM `users`")
Google::Apis::BigqueryV2::Job.from_json json
Expand Down