Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
pass job location as part of paginated queries if set.
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel-io committed Nov 14, 2024
1 parent c5ee540 commit 6e8c4a0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/req_bigquery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ defmodule ReqBigQuery do

%{
"pageToken" => page_token,
"jobReference" => %{"jobId" => job_id, "projectId" => project_id}
"jobReference" => job_reference
} ->
resp = page_request(request_options, project_id, job_id, page_token)
%{"jobId" => job_id, "projectId" => project_id} = job_reference

job_location = Map.get(job_reference, "location")

resp = page_request(request_options, project_id, job_id, job_location, page_token)
{resp.body["rows"], resp.body}

_end ->
Expand All @@ -267,12 +271,18 @@ defmodule ReqBigQuery do
|> Stream.flat_map(& &1)
end

defp page_request(options, project_id, job_id, page_token) do
defp page_request(options, project_id, job_id, job_location, page_token) do
uri =
URI.parse(
"#{@base_url}/projects/#{project_id}/queries/#{job_id}?maxResults=#{options[:max_results]}&pageToken=#{page_token}"
)

uri =
case job_location do
nil -> uri
job_location -> URI.append_query(uri, "location=#{job_location}")
end

token = Goth.fetch!(options[:goth]).token

Req.new(url: uri)
Expand Down

0 comments on commit 6e8c4a0

Please sign in to comment.