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 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
kernel-io authored Nov 14, 2024
1 parent c5ee540 commit ee4ff64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
include:
- pair:
elixir: '1.12'
elixir: '1.15'
otp: 24
lint: lint
steps:
Expand Down
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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule ReqBigQuery.MixProject do
version: @version,
description: @description,
name: "ReqBigQuery",
elixir: "~> 1.12",
elixir: "~> 1.15",
preferred_cli_env: [
"test.all": :test,
docs: :docs,
Expand Down

0 comments on commit ee4ff64

Please sign in to comment.