This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 352e6533a feat(r): Add R BigQuery driver wrapper (#2235)
352e6533a is described below
commit 352e6533a883798b8a0f62b6c81e56ae68a9804a
Author: Dewey Dunnington <[email protected]>
AuthorDate: Wed Oct 9 23:27:53 2024 +0000
feat(r): Add R BigQuery driver wrapper (#2235)
This PR adds a BigQuery driver wrapper for R. It is basically the same
as the FlightSQL wrapper with the addition of one helper function to
take care of the auth (in R we have the lovely `gargle` package and
`bigrquery` which have extensive methods for handling auth in various
scenarios).
I don't think we have a way to get credentials into CI yet (but at least
we have build/package load coverage for when that happens).
``` r
library(adbcdrivermanager)
# Use the driver manager to connect to a database
db <- adbc_database_init(
adbcbigquery::adbcbigquery(),
token = bigrquery::bq_token(),
"adbc.bigquery.sql.project_id" =
Sys.getenv("ADBC_BIGQUERY_TEST_PROJECT_ID")
)
con <- adbc_connection_init(db)
con |>
read_adbc(
"SELECT zipcode, latitude, longitude
FROM `bigquery-public-data.utility_us.zipcode_area` LIMIT 10"
) |>
tibble::as_tibble()
#> # A tibble: 10 × 3
#> zipcode latitude longitude
#> <chr> <dbl> <dbl>
#> 1 96950 15.2 146.
#> 2 96952 15.0 146.
#> 3 96951 14.2 145.
#> 4 96910 13.5 145.
#> 5 96929 13.6 145.
#> 6 96921 13.5 145.
#> 7 96913 13.5 145.
#> 8 96932 13.5 145.
#> 9 50012 42.0 -93.6
#> 10 52352 42.3 -91.8
```
<sup>Created on 2024-10-09 with [reprex
v2.1.1](https://reprex.tidyverse.org)</sup>
---
.github/workflows/r-extended.yml | 4 +-
.github/workflows/r-standard.yml | 2 +-
r/adbcbigquery/.Rbuildignore | 17 ++
r/adbcbigquery/.gitignore | 20 +++
r/adbcbigquery/DESCRIPTION | 28 +++
r/adbcbigquery/LICENSE.md | 194 +++++++++++++++++++++
r/adbcbigquery/NAMESPACE | 10 ++
r/adbcbigquery/R/adbcbigquery-package.R | 122 +++++++++++++
r/adbcbigquery/README.Rmd | 77 ++++++++
r/adbcbigquery/README.md | 79 +++++++++
r/adbcbigquery/_pkgdown.yml | 38 ++++
r/adbcbigquery/adbcbigquery.Rproj | 22 +++
r/adbcbigquery/bootstrap.R | 18 ++
r/adbcbigquery/cleanup | 20 +++
r/adbcbigquery/cleanup.win | 18 ++
r/adbcbigquery/configure | 128 ++++++++++++++
r/adbcbigquery/configure.win | 23 +++
r/adbcbigquery/cran-comments.md | 9 +
r/adbcbigquery/man/adbcbigquery-package.Rd | 33 ++++
r/adbcbigquery/man/adbcbigquery.Rd | 39 +++++
r/adbcbigquery/src/.gitignore | 21 +++
r/adbcbigquery/src/Makevars.in | 31 ++++
r/adbcbigquery/src/Makevars.win | 34 ++++
r/adbcbigquery/src/go/.gitignore | 21 +++
r/adbcbigquery/src/go/symbols.map | 26 +++
r/adbcbigquery/src/init.c | 42 +++++
r/adbcbigquery/tests/testthat.R | 29 +++
.../tests/testthat/test-adbcbigquery-package.R | 57 ++++++
r/adbcbigquery/tools/download-go.R | 87 +++++++++
29 files changed, 1246 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/r-extended.yml b/.github/workflows/r-extended.yml
index 3963da25c..1ca2e821c 100644
--- a/.github/workflows/r-extended.yml
+++ b/.github/workflows/r-extended.yml
@@ -44,7 +44,7 @@ jobs:
matrix:
rversion: [oldrel, release, devel]
os: [macOS, windows, ubuntu]
- pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake]
+ pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake, adbcbigquery]
fail-fast: false
uses: ./.github/workflows/r-check.yml
@@ -61,7 +61,7 @@ jobs:
matrix:
rversion: ["3.6", "4.0", "4.1"]
os: [ubuntu]
- pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake]
+ pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake, adbcbigquery]
fail-fast: false
uses: ./.github/workflows/r-check.yml
diff --git a/.github/workflows/r-standard.yml b/.github/workflows/r-standard.yml
index 9cc8f7ac9..907d77984 100644
--- a/.github/workflows/r-standard.yml
+++ b/.github/workflows/r-standard.yml
@@ -50,7 +50,7 @@ jobs:
strategy:
matrix:
os: [ubuntu, macOS, windows]
- pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake]
+ pkg: [adbcdrivermanager, adbcsqlite, adbcpostgresql, adbcflightsql,
adbcsnowflake, adbcbigquery]
uses: ./.github/workflows/r-check.yml
with:
diff --git a/r/adbcbigquery/.Rbuildignore b/r/adbcbigquery/.Rbuildignore
new file mode 100644
index 000000000..a62253724
--- /dev/null
+++ b/r/adbcbigquery/.Rbuildignore
@@ -0,0 +1,17 @@
+^adbcbigquery\.Rproj$
+^\.Rproj\.user$
+^LICENSE\.md$
+^bootstrap\.R$
+^README\.Rmd$
+^src/Makevars$
+^\.vscode$
+^src/go/tmp$
+^_pkgdown\.yml$
+^docs$
+^pkgdown$
+^cran-comments\.md$
+^src/\.go-cache$
+^src/\.go-path$
+^configure\.win$
+^\.cache$
+^compile_commands\.json$
diff --git a/r/adbcbigquery/.gitignore b/r/adbcbigquery/.gitignore
new file mode 100644
index 000000000..11519d404
--- /dev/null
+++ b/r/adbcbigquery/.gitignore
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+.Rproj.user
+windows/
+docs
diff --git a/r/adbcbigquery/DESCRIPTION b/r/adbcbigquery/DESCRIPTION
new file mode 100644
index 000000000..cdfdb7134
--- /dev/null
+++ b/r/adbcbigquery/DESCRIPTION
@@ -0,0 +1,28 @@
+Package: adbcbigquery
+Title: 'Arrow' Database Connectivity ('ADBC') 'BigQuery' Driver
+Version: 0.14.0.9000
+Authors@R: c(
+ person("Dewey", "Dunnington", , "[email protected]", role = c("aut",
"cre"),
+ comment = c(ORCID = "0000-0002-9415-4582")),
+ person("Apache Arrow", email = "[email protected]", role = c("aut",
"cph")),
+ person("Apache Software Foundation", email = "[email protected]",
role = c("cph"))
+ )
+Description: Provides a developer-facing interface to the 'Arrow' Database
+ Connectivity ('ADBC') 'BigQuery' driver for the purposes of building
high-level
+ database interfaces for users. 'ADBC' <https://arrow.apache.org/adbc/> is
+ an API standard for database access libraries that uses 'Arrow' for result
+ sets and query parameters.
+License: Apache License (>= 2)
+Encoding: UTF-8
+Roxygen: list(markdown = TRUE)
+RoxygenNote: 7.3.2
+Suggests:
+ gargle,
+ nanoarrow,
+ testthat (>= 3.0.0)
+SystemRequirements: GNU make, Go (>= 1.21)
+Config/testthat/edition: 3
+Config/build/bootstrap: TRUE
+URL: https://arrow.apache.org/adbc/current/r/adbcbigquery/,
https://github.com/apache/arrow-adbc
+BugReports: https://github.com/apache/arrow-adbc/issues
+Imports: adbcdrivermanager
diff --git a/r/adbcbigquery/LICENSE.md b/r/adbcbigquery/LICENSE.md
new file mode 100644
index 000000000..b62a9b5ff
--- /dev/null
+++ b/r/adbcbigquery/LICENSE.md
@@ -0,0 +1,194 @@
+Apache License
+==============
+
+_Version 2.0, January 2004_
+_<<http://www.apache.org/licenses/>>_
+
+### Terms and Conditions for use, reproduction, and distribution
+
+#### 1. Definitions
+
+“License” shall mean the terms and conditions for use, reproduction, and
+distribution as defined by Sections 1 through 9 of this document.
+
+“Licensor” shall mean the copyright owner or entity authorized by the copyright
+owner that is granting the License.
+
+“Legal Entity” shall mean the union of the acting entity and all other entities
+that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, “control” means **(i)** the power, direct
or
+indirect, to cause the direction or management of such entity, whether by
+contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of
the
+outstanding shares, or **(iii)** beneficial ownership of such entity.
+
+“You” (or “Your”) shall mean an individual or Legal Entity exercising
+permissions granted by this License.
+
+“Source” form shall mean the preferred form for making modifications, including
+but not limited to software source code, documentation source, and
configuration
+files.
+
+“Object” form shall mean any form resulting from mechanical transformation or
+translation of a Source form, including but not limited to compiled object
code,
+generated documentation, and conversions to other media types.
+
+“Work” shall mean the work of authorship, whether in Source or Object form,
made
+available under the License, as indicated by a copyright notice that is
included
+in or attached to the work (an example is provided in the Appendix below).
+
+“Derivative Works” shall mean any work, whether in Source or Object form, that
+is based on (or derived from) the Work and for which the editorial revisions,
+annotations, elaborations, or other modifications represent, as a whole, an
+original work of authorship. For the purposes of this License, Derivative Works
+shall not include works that remain separable from, or merely link (or bind by
+name) to the interfaces of, the Work and Derivative Works thereof.
+
+“Contribution” shall mean any work of authorship, including the original
version
+of the Work and any modifications or additions to that Work or Derivative Works
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
+by the copyright owner or by an individual or Legal Entity authorized to submit
+on behalf of the copyright owner. For the purposes of this definition,
+“submitted” means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems, and
+issue tracking systems that are managed by, or on behalf of, the Licensor for
+the purpose of discussing and improving the Work, but excluding communication
+that is conspicuously marked or otherwise designated in writing by the
copyright
+owner as “Not a Contribution.”
+
+“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
+of whom a Contribution has been received by Licensor and subsequently
+incorporated within the Work.
+
+#### 2. Grant of Copyright License
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the Work and
such
+Derivative Works in Source or Object form.
+
+#### 3. Grant of Patent License
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable (except as stated in this section) patent license to make, have
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
+such license applies only to those patent claims licensable by such Contributor
+that are necessarily infringed by their Contribution(s) alone or by combination
+of their Contribution(s) with the Work to which such Contribution(s) was
+submitted. If You institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
+Contribution incorporated within the Work constitutes direct or contributory
+patent infringement, then any patent licenses granted to You under this License
+for that Work shall terminate as of the date such litigation is filed.
+
+#### 4. Redistribution
+
+You may reproduce and distribute copies of the Work or Derivative Works thereof
+in any medium, with or without modifications, and in Source or Object form,
+provided that You meet the following conditions:
+
+* **(a)** You must give any other recipients of the Work or Derivative Works a
copy of
+this License; and
+* **(b)** You must cause any modified files to carry prominent notices stating
that You
+changed the files; and
+* **(c)** You must retain, in the Source form of any Derivative Works that You
distribute,
+all copyright, patent, trademark, and attribution notices from the Source form
+of the Work, excluding those notices that do not pertain to any part of the
+Derivative Works; and
+* **(d)** If the Work includes a “NOTICE” text file as part of its
distribution, then any
+Derivative Works that You distribute must include a readable copy of the
+attribution notices contained within such NOTICE file, excluding those notices
+that do not pertain to any part of the Derivative Works, in at least one of the
+following places: within a NOTICE text file distributed as part of the
+Derivative Works; within the Source form or documentation, if provided along
+with the Derivative Works; or, within a display generated by the Derivative
+Works, if and wherever such third-party notices normally appear. The contents
of
+the NOTICE file are for informational purposes only and do not modify the
+License. You may add Your own attribution notices within Derivative Works that
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
+provided that such additional attribution notices cannot be construed as
+modifying the License.
+
+You may add Your own copyright statement to Your modifications and may provide
+additional or different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works as a
whole,
+provided Your use, reproduction, and distribution of the Work otherwise
complies
+with the conditions stated in this License.
+
+#### 5. Submission of Contributions
+
+Unless You explicitly state otherwise, any Contribution intentionally submitted
+for inclusion in the Work by You to the Licensor shall be under the terms and
+conditions of this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify the terms
of
+any separate license agreement you may have executed with Licensor regarding
+such Contributions.
+
+#### 6. Trademarks
+
+This License does not grant permission to use the trade names, trademarks,
+service marks, or product names of the Licensor, except as required for
+reasonable and customary use in describing the origin of the Work and
+reproducing the content of the NOTICE file.
+
+#### 7. Disclaimer of Warranty
+
+Unless required by applicable law or agreed to in writing, Licensor provides
the
+Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+including, without limitation, any warranties or conditions of TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
+solely responsible for determining the appropriateness of using or
+redistributing the Work and assume any risks associated with Your exercise of
+permissions under this License.
+
+#### 8. Limitation of Liability
+
+In no event and under no legal theory, whether in tort (including negligence),
+contract, or otherwise, unless required by applicable law (such as deliberate
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special, incidental,
+or consequential damages of any character arising as a result of this License
or
+out of the use or inability to use the Work (including but not limited to
+damages for loss of goodwill, work stoppage, computer failure or malfunction,
or
+any and all other commercial damages or losses), even if such Contributor has
+been advised of the possibility of such damages.
+
+#### 9. Accepting Warranty or Additional Liability
+
+While redistributing the Work or Derivative Works thereof, You may choose to
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
+other liability obligations and/or rights consistent with this License.
However,
+in accepting such obligations, You may act only on Your own behalf and on Your
+sole responsibility, not on behalf of any other Contributor, and only if You
+agree to indemnify, defend, and hold each Contributor harmless for any
liability
+incurred by, or claims asserted against, such Contributor by reason of your
+accepting any such warranty or additional liability.
+
+_END OF TERMS AND CONDITIONS_
+
+### APPENDIX: How to apply the Apache License to your work
+
+To apply the Apache License to your work, attach the following boilerplate
+notice, with the fields enclosed by brackets `[]` replaced with your own
+identifying information. (Don't include the brackets!) The text should be
+enclosed in the appropriate comment syntax for the file format. We also
+recommend that a file or class name and description of purpose be included on
+the same “printed page” as the copyright notice for easier identification
within
+third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/r/adbcbigquery/NAMESPACE b/r/adbcbigquery/NAMESPACE
new file mode 100644
index 000000000..743ded867
--- /dev/null
+++ b/r/adbcbigquery/NAMESPACE
@@ -0,0 +1,10 @@
+# Generated by roxygen2: do not edit by hand
+
+S3method(adbc_connection_init,adbcbigquery_database)
+S3method(adbc_database_init,adbcbigquery_driver_bigquery)
+S3method(adbc_statement_init,adbcbigquery_connection)
+export(adbcbigquery)
+importFrom(adbcdrivermanager,adbc_connection_init)
+importFrom(adbcdrivermanager,adbc_database_init)
+importFrom(adbcdrivermanager,adbc_statement_init)
+useDynLib(adbcbigquery, .registration = TRUE)
diff --git a/r/adbcbigquery/R/adbcbigquery-package.R
b/r/adbcbigquery/R/adbcbigquery-package.R
new file mode 100644
index 000000000..24a9c82ac
--- /dev/null
+++ b/r/adbcbigquery/R/adbcbigquery-package.R
@@ -0,0 +1,122 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#' @keywords internal
+#' @aliases adbcbigquery-package
+"_PACKAGE"
+
+## usethis namespace: start
+#' @useDynLib adbcbigquery, .registration = TRUE
+## usethis namespace: end
+NULL
+
+#' ADBC BigQuery Driver
+#'
+#' @inheritParams adbcdrivermanager::adbc_database_init
+#' @inheritParams adbcdrivermanager::adbc_connection_init
+#' @inheritParams adbcdrivermanager::adbc_statement_init
+#' @param token A token obtained from [bigrquery::bq_token()] or
+#' [gargle::token_fetch()]. This is the easiest way to authenticate.
+#' @param ... Extra key/value options passed to the driver.
+#'
+#' @return An [adbcdrivermanager::adbc_driver()]
+#' @export
+#'
+#' @examples
+#' adbcbigquery()
+#'
+adbcbigquery <- function() {
+ adbcdrivermanager::adbc_driver(
+ .Call(adbcbigquery_c_bigquery),
+ subclass = "adbcbigquery_driver_bigquery"
+ )
+}
+
+#' @rdname adbcbigquery
+#' @importFrom adbcdrivermanager adbc_database_init
+#' @export
+adbc_database_init.adbcbigquery_driver_bigquery <- function(driver, ..., token
= NULL) {
+ if (!is.null(token)) {
+ options <- list(options_from_token(token), ...)
+ } else {
+ options <- list(...)
+ }
+
+ adbcdrivermanager::adbc_database_init_default(
+ driver,
+ options,
+ subclass = "adbcbigquery_database"
+ )
+}
+
+#' @rdname adbcbigquery
+#' @importFrom adbcdrivermanager adbc_connection_init
+#' @export
+adbc_connection_init.adbcbigquery_database <- function(database, ...) {
+ options <- list(...)
+
+ adbcdrivermanager::adbc_connection_init_default(
+ database,
+ options,
+ subclass = "adbcbigquery_connection"
+ )
+}
+
+#' @rdname adbcbigquery
+#' @importFrom adbcdrivermanager adbc_statement_init
+#' @export
+adbc_statement_init.adbcbigquery_connection <- function(connection, ...) {
+ options <- list(...)
+
+ adbcdrivermanager::adbc_statement_init_default(
+ connection,
+ options,
+ subclass = "adbcbigquery_statement"
+ )
+}
+
+# Converts a bigrquery::bq_token() or garge::token_fetch() into the options
+# required by the ADBC driver.
+options_from_token <- function(tok) {
+ if (inherits(tok, "request")) {
+ tok <- tok$auth_token
+ }
+
+ if (!inherits(tok, "Token2.0")) {
+ stop(
+ sprintf(
+ "ADBC BigQuery database options from token failed (expected Token2.0,
got %s)",
+ paste(class(tok), sep = " / ")
+ )
+ )
+ }
+
+ # Because adbcdrivermanager:::key_value_options() is not exposed, we create
the
+ # options ourselves such that set_options() can automatically expand them.
+ structure(
+ c(
+ "adbc.bigquery.sql.auth_type" =
"adbc.bigquery.sql.auth_type.user_authentication",
+ "adbc.bigquery.sql.auth.client_id" = tok$client$id,
+ "adbc.bigquery.sql.auth.client_secret" = tok$client$secret,
+ "adbc.bigquery.sql.auth.refresh_token" = tok$credentials$refresh_token
+ # Ideally we would also pass on tok$credentials$access_token; however,
+ # the underlying Go driver does not yet implement the ability to pass
this
+ # information directly (i.e., it will always refresh on connect)
+ ),
+ class = "adbc_options"
+ )
+}
diff --git a/r/adbcbigquery/README.Rmd b/r/adbcbigquery/README.Rmd
new file mode 100644
index 000000000..9649eaef2
--- /dev/null
+++ b/r/adbcbigquery/README.Rmd
@@ -0,0 +1,77 @@
+---
+output: github_document
+---
+
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<!-- README.md is generated from README.Rmd. Please edit that file -->
+
+```{r, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>",
+ fig.path = "man/figures/README-",
+ out.width = "100%"
+)
+```
+
+# adbcbigquery
+
+<!-- badges: start -->
+<!-- badges: end -->
+
+The goal of adbcbigquery is to provide a low-level developer-facing interface
+to the Arrow Database Connectivity (ADBC) BigQuery driver.
+
+## Installation
+
+You can install the released version of adbcbigquery from
[CRAN](https://cran.r-project.org/) with:
+
+```r
+install.packages("adbcbigquery")
+```
+
+You can install the development version of adbcbigquery from
[GitHub](https://github.com/) with:
+
+``` r
+# install.packages("pak")
+pak::pak("apache/arrow-adbc/r/adbcbigquery")
+```
+
+## Example
+
+This is a basic example which shows you how to solve a common problem.
+
+```{r example}
+library(adbcdrivermanager)
+
+# Use the driver manager to connect to a database
+db <- adbc_database_init(
+ adbcbigquery::adbcbigquery(),
+ token = bigrquery::bq_token(),
+ "adbc.bigquery.sql.project_id" = Sys.getenv("ADBC_BIGQUERY_TEST_PROJECT_ID")
+)
+con <- adbc_connection_init(db)
+
+con |>
+ read_adbc(
+ "SELECT zipcode, latitude, longitude
+ FROM `bigquery-public-data.utility_us.zipcode_area` LIMIT 10"
+ ) |>
+ tibble::as_tibble()
+```
diff --git a/r/adbcbigquery/README.md b/r/adbcbigquery/README.md
new file mode 100644
index 000000000..86180908c
--- /dev/null
+++ b/r/adbcbigquery/README.md
@@ -0,0 +1,79 @@
+
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<!-- README.md is generated from README.Rmd. Please edit that file -->
+
+# adbcbigquery
+
+<!-- badges: start -->
+<!-- badges: end -->
+
+The goal of adbcbigquery is to provide a low-level developer-facing
+interface to the Arrow Database Connectivity (ADBC) BigQuery driver.
+
+## Installation
+
+You can install the released version of adbcbigquery from
+[CRAN](https://cran.r-project.org/) with:
+
+``` r
+install.packages("adbcbigquery")
+```
+
+You can install the development version of adbcbigquery from
+[GitHub](https://github.com/) with:
+
+``` r
+# install.packages("pak")
+pak::pak("apache/arrow-adbc/r/adbcbigquery")
+```
+
+## Example
+
+This is a basic example which shows you how to solve a common problem.
+
+``` r
+library(adbcdrivermanager)
+
+# Use the driver manager to connect to a database
+db <- adbc_database_init(
+ adbcbigquery::adbcbigquery(),
+ token = bigrquery::bq_token(),
+ "adbc.bigquery.sql.project_id" = Sys.getenv("ADBC_BIGQUERY_TEST_PROJECT_ID")
+)
+con <- adbc_connection_init(db)
+
+con |>
+ read_adbc(
+ "SELECT zipcode, latitude, longitude
+ FROM `bigquery-public-data.utility_us.zipcode_area` LIMIT 10"
+ ) |>
+ tibble::as_tibble()
+#> # A tibble: 10 × 3
+#> zipcode latitude longitude
+#> <chr> <dbl> <dbl>
+#> 1 96950 15.2 146.
+#> 2 96952 15.0 146.
+#> 3 96951 14.2 145.
+#> 4 96910 13.5 145.
+#> 5 96929 13.6 145.
+#> 6 96921 13.5 145.
+#> 7 96913 13.5 145.
+#> 8 96932 13.5 145.
+#> 9 50012 42.0 -93.6
+#> 10 52352 42.3 -91.8
+```
diff --git a/r/adbcbigquery/_pkgdown.yml b/r/adbcbigquery/_pkgdown.yml
new file mode 100644
index 000000000..9d213e123
--- /dev/null
+++ b/r/adbcbigquery/_pkgdown.yml
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+url: https://arrow.apache.org/adbc/current/r/adbcbigquery/
+template:
+ bootstrap: 5
+ light-switch: true
+ # Link back to ADBC R documentation
+ includes:
+ before_title: |
+ <ul class="navbar-nav me-auto">
+ <li class="nav-item">
+ <a class="nav-link" href="../index.html">
+ <span class="fa fa-arrow-left"></span>
+ </a>
+ </li>
+ </ul>
+
+repo:
+ url:
+ home: https://github.com/apache/arrow-adbc/
+ source: https://github.com/apache/arrow-adbc/blob/main/r/adbcbigquery/
+ issue: https://github.com/apache/arrow-adbc/issues/
+ user: https://github.com/
diff --git a/r/adbcbigquery/adbcbigquery.Rproj
b/r/adbcbigquery/adbcbigquery.Rproj
new file mode 100644
index 000000000..69fafd4b6
--- /dev/null
+++ b/r/adbcbigquery/adbcbigquery.Rproj
@@ -0,0 +1,22 @@
+Version: 1.0
+
+RestoreWorkspace: No
+SaveWorkspace: No
+AlwaysSaveHistory: Default
+
+EnableCodeIndexing: Yes
+UseSpacesForTab: Yes
+NumSpacesForTab: 2
+Encoding: UTF-8
+
+RnwWeave: Sweave
+LaTeX: pdfLaTeX
+
+AutoAppendNewline: Yes
+StripTrailingWhitespace: Yes
+LineEndingConversion: Posix
+
+BuildType: Package
+PackageUseDevtools: Yes
+PackageInstallArgs: --no-multiarch --with-keep.source
+PackageRoxygenize: rd,collate,namespace
diff --git a/r/adbcbigquery/bootstrap.R b/r/adbcbigquery/bootstrap.R
new file mode 100644
index 000000000..c3dd879dd
--- /dev/null
+++ b/r/adbcbigquery/bootstrap.R
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+source("../tools/bootstrap-go.R")
diff --git a/r/adbcbigquery/cleanup b/r/adbcbigquery/cleanup
new file mode 100755
index 000000000..2261ddb19
--- /dev/null
+++ b/r/adbcbigquery/cleanup
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+rm src/*.o src/go/*.a
+rm -rf src/.go-cache
+rm -rf src/.go-path
diff --git a/r/adbcbigquery/cleanup.win b/r/adbcbigquery/cleanup.win
new file mode 100755
index 000000000..7bee0e8f4
--- /dev/null
+++ b/r/adbcbigquery/cleanup.win
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+./cleanup
diff --git a/r/adbcbigquery/configure b/r/adbcbigquery/configure
new file mode 100755
index 000000000..84ceb149a
--- /dev/null
+++ b/r/adbcbigquery/configure
@@ -0,0 +1,128 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+R_BIN="$R_HOME/bin/R"
+RSCRIPT_BIN="$R_HOME/bin/Rscript"
+
+# Set to non-false for CRAN releases, which require this approach to comply
with
+# guidance regarding large dependency sources. When non-false, this script
+# will fail if the download fails or if checksum verification fails on
+# the downloaded file.
+DOWNLOAD_DEPENDENCY_ARCHIVE="false"
+
+# CRAN checks CPU time to enforce ~2 cores for building. Set GOMAXPROCS to 1
+# when building on CRAN to be safe.
+if [ ! "$DOWNLOAD_DEPENDENCY_ARCHIVE" = "false" ] && [ -z "$GOMAXPROCS" ]; then
+ echo "Using GOMAXPROCS=1 for go build"
+ echo "Set GOMAXPROCS to a higher value in ~/.Renviron for a faster build"
+ GOMAXPROCS=1
+elif [ ! -z "$GOMAXPROCS" ]; then
+ echo "Using GOMAXPROCS=$GOMAXPROCS for go build"
+fi
+
+# Run bootstrap.R. This will have already run if we are installing a source
+# package built with pkgbuild::build() with pkgbuild >1.4.0; however, we
+# run it again in case this is R CMD INSTALL on a directory or
+# devtools::load_all(). This will vendor files from elsewhere in the
+# ADBC repo into this package. If the file doesn't exist, we're installing
+# from a pre-built tarball.
+if [ -f bootstrap.R ]; then
+ echo "Running bootstrap.R..."
+ "$RSCRIPT_BIN" bootstrap.R
+fi
+
+# Find the go binary so that we can go build!
+# If we've downloaded a specific version of go to src/go/tmp, use that
+# one (helpful for testing different version of go locally)
+PREVIOUSLY_DOWNLOADED_GO="`pwd`/src/go/tmp/go/bin/go"
+if [ -z "$GO_BIN" ] && [ -f "$PREVIOUSLY_DOWNLOADED_GO" ]; then
+ GO_BIN="$PREVIOUSLY_DOWNLOADED_GO"
+fi
+
+# Check go on PATH
+if [ -z "$GO_BIN" ]; then
+ GO_BIN=`which go`
+fi
+
+# Try some default install locations that might not be on PATH
+DEFAULT_GO_WIN="C:/Program Files/Go/bin/go.exe"
+if [ -z "$GO_BIN" ] && [ -f "$DEFAULT_GO_WIN" ]; then
+ GO_BIN="$DEFAULT_GO_WIN"
+fi
+
+DEFAULT_GO_MACOS="/usr/local/go/bin/go"
+if [ -z "$GO_BIN" ] && [ -f "$DEFAULT_GO_MACOS" ]; then
+ GO_BIN="$DEFAULT_GO_MACOS"
+fi
+
+DEFAULT_GO_HOMEBREW_M1="/opt/homebrew/bin/go"
+if [ -z "$GO_BIN" ] && [ -f "$DEFAULT_GO_HOMEBREW_M1" ]; then
+ GO_BIN="$DEFAULT_GO_HOMEBREW_M1"
+fi
+
+if [ -z "$GO_BIN" ]; then
+ echo ""
+ echo "The Go compiler is required to install this package. You can install
go"
+ echo "from your faviourite package manager or set the GO_BIN environment
variable:"
+ echo "- apt-get install golang"
+ echo "- brew install golang"
+ echo "- dnf install golang"
+ echo "- apk add go"
+ echo "- pacman -S go"
+ echo "...or from the official installers available at https://go.dev/dl/"
+ exit 1
+fi
+
+echo "Trying 'go version' with GO_BIN at '$GO_BIN'"
+"$GO_BIN" version
+if [ $? -ne 0 ]; then
+ echo "go --version had a non-zero exit code"
+ exit 1
+fi
+
+# Get the CC and CXX compilers
+CC=`"$R_BIN" CMD config CC`
+CXX=`"$R_BIN" CMD config CXX`
+
+# Attempt to hide symbols where possible
+if "$R_BIN" CMD config CC | grep -e "gcc" >/dev/null ; then
+ SYMBOL_ARGS="-Wl,--version-script=go/symbols.map"
+fi
+
+# On OSX we need -framework Security because of some dependency somewhere
+if [ `uname` = "Darwin" ]; then
+ PKG_LIBS="-framework Security $PKG_LIBS"
+fi
+
+PKG_LIBS="$PKG_LIBS $SYMBOL_ARGS"
+
+sed \
+ -e "s|@gobin@|$GO_BIN|" \
+ -e "s|@libs@|$PKG_LIBS|" \
+ -e "s|@cc@|$CC|" \
+ -e "s|@cxx@|$CXX|" \
+ -e "s|@nproc@|$GOMAXPROCS|" \
+ src/Makevars.in > src/Makevars
+
+if [ -f "src/go/adbc/pkg/bigquery/driver.go" ]; then
+ echo "Found vendored ADBC BigQuery driver"
+ exit 0
+fi
+
+echo "Vendored ADBC BigQuery driver was not found."
+echo "This source package was probably built incorrectly and it's probably not
your fault"
+exit 1
diff --git a/r/adbcbigquery/configure.win b/r/adbcbigquery/configure.win
new file mode 100755
index 000000000..caf6740f6
--- /dev/null
+++ b/r/adbcbigquery/configure.win
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# See configure for a description of this process.
+# This is only for development: this file and bootstrap.R will be removed
+# prior to packaging
+if [ -f bootstrap.R ]; then
+ $R_HOME/bin/Rscript bootstrap.R
+fi
diff --git a/r/adbcbigquery/cran-comments.md b/r/adbcbigquery/cran-comments.md
new file mode 100644
index 000000000..2d2bbbdc1
--- /dev/null
+++ b/r/adbcbigquery/cran-comments.md
@@ -0,0 +1,9 @@
+
+An update to reflect the updated upstream sources for the latest
+Apache Arrow ADBC libraries version.
+
+## R CMD check results
+
+0 errors | 0 warnings | 1 note
+
+* This is a new release.
diff --git a/r/adbcbigquery/man/adbcbigquery-package.Rd
b/r/adbcbigquery/man/adbcbigquery-package.Rd
new file mode 100644
index 000000000..3f4bda219
--- /dev/null
+++ b/r/adbcbigquery/man/adbcbigquery-package.Rd
@@ -0,0 +1,33 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/adbcbigquery-package.R
+\docType{package}
+\name{adbcbigquery-package}
+\alias{adbcbigquery-package}
+\title{adbcbigquery: 'Arrow' Database Connectivity ('ADBC') 'BigQuery' Driver}
+\description{
+Provides a developer-facing interface to the 'Arrow' Database Connectivity
('ADBC') 'BigQuery' driver for the purposes of building high-level database
interfaces for users. 'ADBC' \url{https://arrow.apache.org/adbc/} is an API
standard for database access libraries that uses 'Arrow' for result sets and
query parameters.
+}
+\seealso{
+Useful links:
+\itemize{
+ \item \url{https://arrow.apache.org/adbc/current/r/adbcbigquery/}
+ \item \url{https://github.com/apache/arrow-adbc}
+ \item Report bugs at \url{https://github.com/apache/arrow-adbc/issues}
+}
+
+}
+\author{
+\strong{Maintainer}: Dewey Dunnington \email{[email protected]}
(\href{https://orcid.org/0000-0002-9415-4582}{ORCID})
+
+Authors:
+\itemize{
+ \item Apache Arrow \email{[email protected]} [copyright holder]
+}
+
+Other contributors:
+\itemize{
+ \item Apache Software Foundation \email{[email protected]} [copyright
holder]
+}
+
+}
+\keyword{internal}
diff --git a/r/adbcbigquery/man/adbcbigquery.Rd
b/r/adbcbigquery/man/adbcbigquery.Rd
new file mode 100644
index 000000000..c01048467
--- /dev/null
+++ b/r/adbcbigquery/man/adbcbigquery.Rd
@@ -0,0 +1,39 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/adbcbigquery-package.R
+\name{adbcbigquery}
+\alias{adbcbigquery}
+\alias{adbc_database_init.adbcbigquery_driver_bigquery}
+\alias{adbc_connection_init.adbcbigquery_database}
+\alias{adbc_statement_init.adbcbigquery_connection}
+\title{ADBC BigQuery Driver}
+\usage{
+adbcbigquery()
+
+\method{adbc_database_init}{adbcbigquery_driver_bigquery}(driver, ..., token =
NULL)
+
+\method{adbc_connection_init}{adbcbigquery_database}(database, ...)
+
+\method{adbc_statement_init}{adbcbigquery_connection}(connection, ...)
+}
+\arguments{
+\item{driver}{An \code{\link[adbcdrivermanager:adbc_driver]{adbc_driver()}}.}
+
+\item{...}{Extra key/value options passed to the driver.}
+
+\item{token}{A token obtained from
\code{\link[bigrquery:bq_token]{bigrquery::bq_token()}} or
+\code{\link[gargle:token_fetch]{gargle::token_fetch()}}. This is the easiest
way to authenticate.}
+
+\item{database}{An \link[adbcdrivermanager:adbc_database_init]{adbc_database}.}
+
+\item{connection}{An
\link[adbcdrivermanager:adbc_connection_init]{adbc_connection}}
+}
+\value{
+An
\code{\link[adbcdrivermanager:adbc_driver_void]{adbcdrivermanager::adbc_driver()}}
+}
+\description{
+ADBC BigQuery Driver
+}
+\examples{
+adbcbigquery()
+
+}
diff --git a/r/adbcbigquery/src/.gitignore b/r/adbcbigquery/src/.gitignore
new file mode 100644
index 000000000..e040acd74
--- /dev/null
+++ b/r/adbcbigquery/src/.gitignore
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+adbc.h
+Makevars
+.go-cache
+.go-path
diff --git a/r/adbcbigquery/src/Makevars.in b/r/adbcbigquery/src/Makevars.in
new file mode 100644
index 000000000..5a43d7fdd
--- /dev/null
+++ b/r/adbcbigquery/src/Makevars.in
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+PKG_CPPFLAGS=-I$(CURDIR)/src -DADBC_EXPORT=""
+PKG_LIBS=-L$(CURDIR)/go -ladbc_driver_bigquery -lresolv @libs@
+
+CGO_CC = @cc@
+CGO_CXX = @cxx@
+CGO_CFLAGS = $(ALL_CPPFLAGS)
+GOMAXPROCS = @nproc@
+
+.PHONY: all gostatic
+all: $(SHLIB)
+$(SHLIB): gostatic
+
+gostatic:
+ (cd "$(CURDIR)/go/adbc"; GOMAXPROCS=$(GOMAXPROCS)
GOPATH="$(CURDIR)/.go-path" GOCACHE="$(CURDIR)/.go-cache" GOFLAGS=-modcacherw
CC="$(CGO_CC)" CXX="$(CGO_CXX)" CGO_CFLAGS="$(CGO_CFLAGS)"
CGO_LDFLAGS="$(PKG_LIBS)" "@gobin@" build -v -tags driverlib -o
$(CURDIR)/go/libadbc_driver_bigquery.a -buildmode=c-archive "./pkg/bigquery")
diff --git a/r/adbcbigquery/src/Makevars.win b/r/adbcbigquery/src/Makevars.win
new file mode 100644
index 000000000..df9fb94b9
--- /dev/null
+++ b/r/adbcbigquery/src/Makevars.win
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+PKG_CPPFLAGS=-I$(CURDIR) -DADBC_EXPORT=""
+PKG_LIBS=-L$(CURDIR)/go -ladbc_driver_bigquery
+
+CGO_CC = `"${R_HOME}/bin${R_ARCH_BIN}/R.exe" CMD config CC`
+CGO_CXX = `"${R_HOME}/bin${R_ARCH_BIN}/R.exe" CMD config CXX`
+CGO_CFLAGS = $(ALL_CPPFLAGS)
+GO_BIN = $(CURDIR)/go/tmp/go/bin/go.exe
+
+.PHONY: all gostatic gobin
+all: $(SHLIB)
+$(SHLIB): gostatic
+
+gostatic: gobin
+ (cd "$(CURDIR)/go/adbc"; CC="$(CGO_CC)" CXX="$(CGO_CXX)"
CGO_CFLAGS="$(CGO_CFLAGS)" "$(GO_BIN)" build -v -tags driverlib -o
$(CURDIR)/go/libadbc_driver_bigquery.a -buildmode=c-archive "./pkg/bigquery")
+
+gobin:
+ (cd ..; "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe"
"tools/download-go.R")
diff --git a/r/adbcbigquery/src/go/.gitignore b/r/adbcbigquery/src/go/.gitignore
new file mode 100644
index 000000000..7a1a0b2c7
--- /dev/null
+++ b/r/adbcbigquery/src/go/.gitignore
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+adbc/
+tmp/
+libadbc_driver_bigquery.a
+libadbc_driver_bigquery.h
diff --git a/r/adbcbigquery/src/go/symbols.map
b/r/adbcbigquery/src/go/symbols.map
new file mode 100644
index 000000000..18a0eb29c
--- /dev/null
+++ b/r/adbcbigquery/src/go/symbols.map
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+{
+ global:
+ # Only expose symbols needed for R
+ R_init_adbcbigquery;
+ adbcbigquery_c_bigquery;
+
+ local:
+ *;
+};
diff --git a/r/adbcbigquery/src/init.c b/r/adbcbigquery/src/init.c
new file mode 100644
index 000000000..168205de6
--- /dev/null
+++ b/r/adbcbigquery/src/init.c
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#define R_NO_REMAP
+#include <R.h>
+#include <Rinternals.h>
+
+typedef int AdbcStatusCode;
+struct AdbcError;
+AdbcStatusCode AdbcDriverInit(int version, void* raw_driver, struct AdbcError*
error);
+
+static SEXP init_func_xptr = 0;
+
+SEXP adbcbigquery_c_bigquery(void) { return init_func_xptr; }
+
+static const R_CallMethodDef CallEntries[] = {
+ {"adbcbigquery_c_bigquery", (DL_FUNC)&adbcbigquery_c_bigquery, 0}, {NULL,
NULL, 0}};
+
+void R_init_adbcbigquery(DllInfo* dll) {
+ R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
+ R_useDynamicSymbols(dll, FALSE);
+
+ init_func_xptr =
+ PROTECT(R_MakeExternalPtrFn((DL_FUNC)AdbcDriverInit, R_NilValue,
R_NilValue));
+ Rf_setAttrib(init_func_xptr, R_ClassSymbol,
Rf_mkString("adbc_driver_init_func"));
+ R_PreserveObject(init_func_xptr);
+ UNPROTECT(1);
+}
diff --git a/r/adbcbigquery/tests/testthat.R b/r/adbcbigquery/tests/testthat.R
new file mode 100644
index 000000000..d91df554a
--- /dev/null
+++ b/r/adbcbigquery/tests/testthat.R
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This file is part of the standard setup for testthat.
+# It is recommended that you do not modify it.
+#
+# Where should you do additional test configuration?
+# Learn more about the roles of various files in:
+# * https://r-pkgs.org/tests.html
+# * https://testthat.r-lib.org/reference/test_package.html#special-files
+
+library(testthat)
+library(adbcbigquery)
+
+test_check("adbcbigquery")
diff --git a/r/adbcbigquery/tests/testthat/test-adbcbigquery-package.R
b/r/adbcbigquery/tests/testthat/test-adbcbigquery-package.R
new file mode 100644
index 000000000..1f0037a95
--- /dev/null
+++ b/r/adbcbigquery/tests/testthat/test-adbcbigquery-package.R
@@ -0,0 +1,57 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+test_that("adbcbigquery() works", {
+ expect_s3_class(adbcbigquery(), "adbc_driver")
+})
+
+test_that("default options can open a database and execute a query", {
+ test_credentials_file <- Sys.getenv("ADBC_BIGQUERY_TEST_CREDENTIALS_FILE",
"")
+ skip_if(identical(test_credentials_file, ""))
+
+ client <- gargle::gargle_oauth_client_from_json(test_credentials_file)
+ token <- gargle::token_fetch(
+ scopes = c(
+ "https://www.googleapis.com/auth/bigquery"
+ ),
+ client = client
+ )
+
+ db <- adbcdrivermanager::adbc_database_init(
+ adbcbigquery(),
+ "adbc.bigquery.sql.project_id" =
Sys.getenv("ADBC_BIGQUERY_TEST_PROJECT_ID"),
+ token = token
+ )
+ expect_s3_class(db, "adbcbigquery_database")
+
+ con <- adbcdrivermanager::adbc_connection_init(db)
+ expect_s3_class(con, "adbcbigquery_connection")
+
+ stmt <- adbcdrivermanager::adbc_statement_init(con)
+ expect_s3_class(stmt, "adbcbigquery_statement")
+ adbcdrivermanager::adbc_statement_release(stmt)
+
+ result <- as.data.frame(
+ adbcdrivermanager::read_adbc(
+ con,
+ "SELECT zipcode, latitude, longitude
+ FROM `bigquery-public-data.utility_us.zipcode_area` LIMIT 10"
+ )
+ )
+ expect_identical(names(result), c("zipcode", "latitude", "longitude"))
+ expect_identical(nrow(result), 10L)
+})
diff --git a/r/adbcbigquery/tools/download-go.R
b/r/adbcbigquery/tools/download-go.R
new file mode 100644
index 000000000..5f178f4c8
--- /dev/null
+++ b/r/adbcbigquery/tools/download-go.R
@@ -0,0 +1,87 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+tmp_dir <- "src/go/tmp"
+
+go_version <- Sys.getenv("R_ADBC_GO_VERSION_DOWNLOAD", "1.21.8")
+
+go_platform <- tolower(Sys.info()[["sysname"]])
+if (!(go_platform %in% c("darwin", "linux", "windows"))) {
+ stop(sprintf("Go binary not available for os '%s'", go_platform))
+}
+
+r_arch <- R.version$arch
+if (identical(r_arch, "aarch64")) {
+ go_arch <- "arm64"
+} else if (identical(r_arch, "x86_64")) {
+ go_arch <- "amd64"
+} else if (identical(r_arch, "i386")) {
+ go_arch <- "386"
+} else {
+ stop(sprintf("Go binary not available for arch '%s'", r_arch))
+}
+
+if (identical(go_platform, "windows")) {
+ go_ext <- "zip"
+ go_bin <- paste0(tmp_dir, "/go/bin/go.exe")
+} else {
+ go_ext <- "tar.gz"
+ go_bin <- paste0(tmp_dir, "/go/bin/go")
+}
+
+archive_filename <- sprintf("go%s.%s-%s.%s",
+ go_version,
+ go_platform,
+ go_arch,
+ go_ext
+)
+
+archive_url <- sprintf("https://go.dev/dl/%s", archive_filename)
+archive_dest <- file.path(tmp_dir, archive_filename)
+
+if (!dir.exists(tmp_dir)) {
+ dir.create(tmp_dir)
+}
+
+if (!file.exists(archive_dest)) {
+ download.file(archive_url, archive_dest, mode = "wb")
+}
+
+# This step takes a while and there is no good way to communicate progress.
+# We need to make sure that if the user cancels that we delete the partially
+# extracted files (or else `go version`` passes but some parts of the standard
+# library may be missing)
+do_extract <- function() {
+ extract_completed <- FALSE
+ on.exit({
+ if (!extract_completed) {
+ unlink(file.path(tmp_dir, "go"), recursive = TRUE)
+ }
+ })
+
+ if (identical(go_ext, "zip")) {
+ unzip(archive_dest, exdir = tmp_dir)
+ } else {
+ stopifnot(untar(archive_dest, exdir = tmp_dir, verbose = TRUE) == 0L)
+ }
+
+ extract_completed <- TRUE
+}
+
+if (!file.exists(go_bin)) {
+ do_extract()
+}