Skip to content

Commit

Permalink
Merge branch 'dev/snowflake-privatekey' of ssh://github.com/davidhcoe…
Browse files Browse the repository at this point in the history
…/arrow-adbc into dev/snowflake-privatekey
  • Loading branch information
David Coe committed Oct 20, 2023
2 parents cddad4b + 0b7299a commit 395a8bb
Show file tree
Hide file tree
Showing 24 changed files with 1,315 additions and 309 deletions.
9 changes: 4 additions & 5 deletions go/adbc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a //indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
Expand Down
121 changes: 8 additions & 113 deletions go/adbc/go.sum

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions r/adbcdrivermanager/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ S3method(str,adbc_driver)
S3method(str,adbc_error)
S3method(str,adbc_xptr)
S3method(write_adbc,default)
export(adbc_connection_cancel)
export(adbc_connection_commit)
export(adbc_connection_get_info)
export(adbc_connection_get_objects)
export(adbc_connection_get_option)
export(adbc_connection_get_option_bytes)
export(adbc_connection_get_option_double)
export(adbc_connection_get_option_int)
export(adbc_connection_get_statistic_names)
export(adbc_connection_get_statistics)
export(adbc_connection_get_table_schema)
export(adbc_connection_get_table_types)
export(adbc_connection_init)
Expand All @@ -45,6 +52,10 @@ export(adbc_connection_read_partition)
export(adbc_connection_release)
export(adbc_connection_rollback)
export(adbc_connection_set_options)
export(adbc_database_get_option)
export(adbc_database_get_option_bytes)
export(adbc_database_get_option_double)
export(adbc_database_get_option_int)
export(adbc_database_init)
export(adbc_database_init_default)
export(adbc_database_release)
Expand All @@ -53,9 +64,15 @@ export(adbc_driver)
export(adbc_driver_log)
export(adbc_driver_monkey)
export(adbc_driver_void)
export(adbc_error_from_array_stream)
export(adbc_statement_bind)
export(adbc_statement_bind_stream)
export(adbc_statement_execute_query)
export(adbc_statement_execute_schema)
export(adbc_statement_get_option)
export(adbc_statement_get_option_bytes)
export(adbc_statement_get_option_double)
export(adbc_statement_get_option_int)
export(adbc_statement_get_parameter_schema)
export(adbc_statement_init)
export(adbc_statement_init_default)
Expand Down
143 changes: 71 additions & 72 deletions r/adbcdrivermanager/R/adbc.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#'
#' @param driver An [adbc_driver()].
#' @param database An [adbc_database][adbc_database_init].
#' @param option A specific option name
#' @param ... Driver-specific options. For the default method, these are
#' named values that are converted to strings.
#' @param options A named `character()` or `list()` whose values are converted
Expand Down Expand Up @@ -66,26 +67,6 @@ adbc_database_init_default <- function(driver, options = NULL, subclass = charac
})
}

#' @rdname adbc_database_init
#' @export
adbc_database_set_options <- function(database, options) {
options <- key_value_options(options)
error <- adbc_allocate_error()
for (i in seq_along(options)) {
key <- names(options)[i]
value <- options[i]
status <- .Call(
RAdbcDatabaseSetOption,
database,
key,
value,
error
)
stop_for_error(status, error)
}
invisible(database)
}

#' @rdname adbc_database_init
#' @export
adbc_database_release <- function(database) {
Expand Down Expand Up @@ -135,26 +116,6 @@ adbc_connection_init_default <- function(database, options = NULL, subclass = ch
})
}

#' @rdname adbc_connection_init
#' @export
adbc_connection_set_options <- function(connection, options) {
options <- key_value_options(options)
error <- adbc_allocate_error()
for (i in seq_along(options)) {
key <- names(options)[i]
value <- options[i]
status <- .Call(
RAdbcConnectionSetOption,
connection,
key,
value,
error
)
stop_for_error(status, error)
}
invisible(connection)
}

#' @rdname adbc_connection_init
#' @export
adbc_connection_release <- function(connection) {
Expand Down Expand Up @@ -184,14 +145,18 @@ adbc_connection_release <- function(connection) {
#' @param db_schema Only show tables in the given database schema. If NULL, do
#' not filter by database schema. If an empty string, only show tables without
#' a database schema. May be a search pattern.
#' @param table_name Only show tables with the given name. If NULL, do not
#' filter by name. May be a search pattern.
#' @param table_name Constrain an object or statistics query for a specific table.
#' If NULL, do not filter by name. May be a search pattern.
#' @param table_type Only show tables matching one of the given table types. If
#' NULL, show tables of any type. Valid table types can be fetched from
#' GetTableTypes. Terminate the list with a NULL entry.
#' @param column_name Only show columns with the given name. If NULL, do not
#' filter by name. May be a search pattern.
#' @param serialized_partition The partition descriptor.
#' @param approximate If `FALSE`, request exact values of statistics,
#' else allow for best-effort, approximate, or cached values. The database
#' may return approximate values regardless, as indicated in the result.
#' Requesting exact values may be expensive or unsupported.
#' @param value A string or identifier.
#'
#' @return
Expand All @@ -210,13 +175,13 @@ adbc_connection_release <- function(connection) {
#' # (not implemented by the void driver)
#' try(adbc_connection_get_info(con, 0))
#'
adbc_connection_get_info <- function(connection, info_codes) {
adbc_connection_get_info <- function(connection, info_codes = NULL) {
error <- adbc_allocate_error()
out_stream <- nanoarrow::nanoarrow_allocate_array_stream()
status <- .Call(
RAdbcConnectionGetInfo,
connection,
as.integer(info_codes),
info_codes,
out_stream,
error
)
Expand Down Expand Up @@ -303,6 +268,56 @@ adbc_connection_commit <- function(connection) {
invisible(connection)
}


#' @rdname adbc_connection_get_info
#' @export
adbc_connection_rollback <- function(connection) {
error <- adbc_allocate_error()
.Call(RAdbcConnectionRollback, connection, error)
invisible(connection)
}

#' @rdname adbc_connection_get_info
#' @export
adbc_connection_cancel <- function(connection) {
error <- adbc_allocate_error()
.Call(RAdbcConnectionCancel, connection, error)
invisible(connection)
}

#' @rdname adbc_connection_get_info
#' @export
adbc_connection_get_statistic_names <- function(connection) {
error <- adbc_allocate_error()
out_stream <- nanoarrow::nanoarrow_allocate_array_stream()
status <- .Call(RAdbcConnectionGetStatisticNames, connection, out_stream, error)
stop_for_error(status, error)

out_stream
}

#' @rdname adbc_connection_get_info
#' @export
adbc_connection_get_statistics <- function(connection, catalog, db_schema,
table_name, approximate = FALSE) {
error <- adbc_allocate_error()
out_stream <- nanoarrow::nanoarrow_allocate_array_stream()

status <- .Call(
RAdbcConnectionGetStatistics,
connection,
catalog,
db_schema,
table_name,
approximate,
out_stream,
error
)
stop_for_error(status, error)

out_stream
}

#' @rdname adbc_connection_get_info
#' @export
adbc_connection_quote_identifier <- function(connection, value, ...) {
Expand All @@ -327,14 +342,6 @@ adbc_connection_quote_string.default <- function(connection, value, ...) {
paste0("'", out, "'")
}

#' @rdname adbc_connection_get_info
#' @export
adbc_connection_rollback <- function(connection) {
error <- adbc_allocate_error()
.Call(RAdbcConnectionRollback, connection, error)
invisible(connection)
}

#' Statements
#'
#' @inheritParams adbc_connection_init
Expand Down Expand Up @@ -370,26 +377,6 @@ adbc_statement_init_default <- function(connection, options = NULL, subclass = c
})
}

#' @rdname adbc_statement_init
#' @export
adbc_statement_set_options <- function(statement, options) {
options <- key_value_options(options)
error <- adbc_allocate_error()
for (i in seq_along(options)) {
key <- names(options)[i]
value <- options[i]
status <- .Call(
RAdbcStatementSetOption,
statement,
key,
value,
error
)
stop_for_error(status, error)
}
invisible(statement)
}

#' @rdname adbc_statement_init
#' @export
adbc_statement_release <- function(statement) {
Expand Down Expand Up @@ -498,3 +485,15 @@ adbc_statement_execute_query <- function(statement, stream = NULL) {
stop_for_error(result$status, error)
result$rows_affected
}

#' @rdname adbc_statement_set_sql_query
#' @export
adbc_statement_execute_schema <- function(statement) {
error <- adbc_allocate_error()
out_schema <- nanoarrow::nanoarrow_allocate_schema()

status <- .Call(RAdbcStatementExecuteSchema, statement, out_schema, error)
stop_for_error(status, error)

out_schema
}
31 changes: 29 additions & 2 deletions r/adbcdrivermanager/R/error.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
# specific language governing permissions and limitations
# under the License.


#' Get extended error information from an array stream
#'
#' @param stream A [nanoarrow_array_stream][nanoarrow::as_nanoarrow_array_stream]
#'
#' @return `NULL` if stream was not created by a driver that supports
#' extended error information or a list whose first element is the
#' status code and second element is the `adbc_error` object. The
#' `acbc_error` must not be accessed if `stream` is explicitly released.
#' @export
#'
#' @examples
#' db <- adbc_database_init(adbc_driver_monkey())
#' con <- adbc_connection_init(db)
#' stmt <- adbc_statement_init(con, mtcars)
#' stream <- nanoarrow::nanoarrow_allocate_array_stream()
#' adbc_statement_execute_query(stmt, stream)
#' adbc_error_from_array_stream(stream)
#'
adbc_error_from_array_stream <- function(stream) {
if (!inherits(stream, "nanoarrow_array_stream") || !adbc_xptr_is_valid(stream)) {
stop("`stream` must be a valid nanoarrow_array_stream")
}

.Call(RAdbcErrorFromArrayStream, stream)
}

adbc_allocate_error <- function(shelter = NULL) {
.Call(RAdbcAllocateError, shelter)
}
Expand Down Expand Up @@ -62,12 +89,12 @@ str.adbc_error <- function(object, ...) {

#' @export
length.adbc_error <- function(x, ...) {
3L
4L
}

#' @export
names.adbc_error <- function(x, ...) {
c("message", "vendor_code", "sqlstate")
c("message", "vendor_code", "sqlstate", "details")
}

#' @export
Expand Down
Loading

0 comments on commit 395a8bb

Please sign in to comment.