File: 22-dbCreateTableArrow.R

package info (click to toggle)
dbi 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,740 kB
  • sloc: makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#' Create a table in the database based on an Arrow object
#'
#' @description
#' `r lifecycle::badge('experimental')`
#'
#' The default `dbCreateTableArrow()` method determines the R data types
#' of the Arrow schema associated with the Arrow object,
#' and calls [dbCreateTable()].
#' Backends that implement [dbAppendTableArrow()] should typically
#' also implement this generic.
#' Use [dbCreateTable()] to create a table from the column types
#' as defined in a data frame.
#'
#' @param value An object for which a schema can be determined via
#'   [nanoarrow::infer_nanoarrow_schema()].
#' @inheritParams dbReadTable
#' @inheritParams sqlCreateTable
#'
#' @inherit DBItest::spec_arrow_create_table_arrow return
#' @inheritSection DBItest::spec_arrow_create_table_arrow Failure modes
#' @inheritSection DBItest::spec_arrow_create_table_arrow Additional arguments
#' @inheritSection DBItest::spec_arrow_create_table_arrow Specification
#'
#' @template methods
#' @templateVar method_name dbCreateTableArrow
#'
#' @family DBIConnection generics
#' @export
#' @examplesIf requireNamespace("RSQLite", quietly = TRUE) && requireNamespace("nanoarrow", quietly = TRUE)
#' con <- dbConnect(RSQLite::SQLite(), ":memory:")
#' ptype <- data.frame(a = numeric())
#' dbCreateTableArrow(con, "df", nanoarrow::infer_nanoarrow_schema(ptype))
#' dbReadTable(con, "df")
#' dbDisconnect(con)
setGeneric(
  "dbCreateTableArrow",
  def = function(conn, name, value, ..., temporary = FALSE) {
    otel_local_active_span(
      "CREATE TABLE",
      conn,
      label = .dbi_get_collection_name(name, conn),
      attributes = list(
        db.collection.name = .dbi_get_collection_name(name, conn),
        db.operation.name = "CREATE TABLE"
      )
    )
    standardGeneric("dbCreateTableArrow")
  }
)