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

pass job location as part of paginated queries if set. #34

Merged
merged 3 commits into from
Nov 14, 2024
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
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
Loading