Title: | A 'polars' backend for 'DBI'. |
---|---|
Description: | DBI-compliant interface to 'polars'. |
Authors: | Tatsuya Shima [aut, cre] |
Maintainer: | Tatsuya Shima <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-09-21 05:23:53 UTC |
Source: | https://github.com/rpolars/r-polarssql |
Compute results of a dbplyr query
## S3 method for class 'tbl_polarssql_connection' as_polars_lf(x, ..., cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' as_polars_df(x, ..., cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' compute(x, ..., n = Inf, cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' as.data.frame(x, ..., cte = TRUE)
## S3 method for class 'tbl_polarssql_connection' as_polars_lf(x, ..., cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' as_polars_df(x, ..., cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' compute(x, ..., n = Inf, cte = TRUE) ## S3 method for class 'tbl_polarssql_connection' as.data.frame(x, ..., cte = TRUE)
x |
A tbl_polarssql_connection object. |
... |
|
cte |
|
n |
Number of rows to fetch. Defaults to |
library(dplyr, warn.conflicts = FALSE) library(polars) t <- tbl_polarssql(mtcars) |> filter(cyl == 4) as_polars_lf(t) as_polars_df(t, n_rows = 1) compute(t, n = 1) # Equivalent to `as_polars_df(t, n_rows = 1)` as.data.frame(t, n_rows = 1) # Clean up DBI::dbDisconnect(polarssql_default_connection())
library(dplyr, warn.conflicts = FALSE) library(polars) t <- tbl_polarssql(mtcars) |> filter(cyl == 4) as_polars_lf(t) as_polars_df(t, n_rows = 1) compute(t, n = 1) # Equivalent to `as_polars_df(t, n_rows = 1)` as.data.frame(t, n_rows = 1) # Clean up DBI::dbDisconnect(polarssql_default_connection())
Implementations of pure virtual functions defined in the DBI
package.
## S4 method for signature 'polarssql_result' dbClearResult(res, ...) ## S4 method for signature 'polarssql_driver' dbConnect(drv, ...) ## S4 method for signature 'polarssql_connection' dbDisconnect(conn, ...) ## S4 method for signature 'polarssql_connection,character' dbExistsTable(conn, name, ...) ## S4 method for signature 'polarssql_result' dbFetch(res, n = -1, ...) ## S4 method for signature 'polarssql_result' dbGetRowsAffected(res, ...) ## S4 method for signature 'polarssql_result' dbHasCompleted(res, ...) ## S4 method for signature 'polarssql_connection' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_driver' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_result' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_connection,character' dbListFields(conn, name, ...) ## S4 method for signature 'polarssql_connection' dbListTables(conn, ...) ## S4 method for signature 'polarssql_connection,character' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'polarssql_connection,character' dbQuoteString(conn, x, ...) ## S4 method for signature 'polarssql_connection,character' dbRemoveTable(conn, name, ..., fail_if_missing = TRUE) ## S4 method for signature 'polarssql_connection,character' dbSendQuery(conn, statement, ...) ## S4 method for signature 'polarssql_connection,character,data.frame' dbWriteTable(conn, name, value, ..., overwrite = FALSE) ## S4 method for signature 'polarssql_connection' show(object) ## S4 method for signature 'polarssql_driver' show(object) ## S4 method for signature 'polarssql_result' show(object)
## S4 method for signature 'polarssql_result' dbClearResult(res, ...) ## S4 method for signature 'polarssql_driver' dbConnect(drv, ...) ## S4 method for signature 'polarssql_connection' dbDisconnect(conn, ...) ## S4 method for signature 'polarssql_connection,character' dbExistsTable(conn, name, ...) ## S4 method for signature 'polarssql_result' dbFetch(res, n = -1, ...) ## S4 method for signature 'polarssql_result' dbGetRowsAffected(res, ...) ## S4 method for signature 'polarssql_result' dbHasCompleted(res, ...) ## S4 method for signature 'polarssql_connection' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_driver' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_result' dbIsValid(dbObj, ...) ## S4 method for signature 'polarssql_connection,character' dbListFields(conn, name, ...) ## S4 method for signature 'polarssql_connection' dbListTables(conn, ...) ## S4 method for signature 'polarssql_connection,character' dbQuoteIdentifier(conn, x, ...) ## S4 method for signature 'polarssql_connection,character' dbQuoteString(conn, x, ...) ## S4 method for signature 'polarssql_connection,character' dbRemoveTable(conn, name, ..., fail_if_missing = TRUE) ## S4 method for signature 'polarssql_connection,character' dbSendQuery(conn, statement, ...) ## S4 method for signature 'polarssql_connection,character,data.frame' dbWriteTable(conn, name, value, ..., overwrite = FALSE) ## S4 method for signature 'polarssql_connection' show(object) ## S4 method for signature 'polarssql_driver' show(object) ## S4 method for signature 'polarssql_result' show(object)
res |
An object inheriting from DBIResult. |
... |
Other arguments passed on to methods. |
drv |
an object that inherits from DBIDriver, or an existing DBIConnection object (in order to clone an existing connection). |
conn |
A DBIConnection object, as returned by
|
name |
The table name, passed on to
|
n |
maximum number of records to retrieve per fetch. Use |
dbObj |
An object inheriting from DBIObject, i.e. DBIDriver, DBIConnection, or a DBIResult |
x |
A character vector, SQL or Id object to quote as identifier. |
fail_if_missing |
If |
statement |
a character string containing SQL. |
value |
A data.frame (or coercible to data.frame). |
overwrite |
Allow overwriting the destination table. Cannot be
|
object |
Any R object |
Use simulate_polarssql()
with dbplyr::tbl_lazy()
or
dbplyr::lazy_frame()
to see simulated SQL without
converting to live access.
tbl_polarssql()
is similar to dbplyr::tbl_memdb()
, but the backend is
Polars instead of SQLite.
It uses polarssql_default_connection()
as the DBI connection.
simulate_polarssql() tbl_polarssql(df, name = deparse(substitute(df)), ..., overwrite = FALSE)
simulate_polarssql() tbl_polarssql(df, name = deparse(substitute(df)), ..., overwrite = FALSE)
df |
Data frame to copy |
name |
Name of table in database: defaults to a random name that's unlikely to conflict with an existing table. |
... |
Ignored. |
overwrite |
If |
library(dplyr, warn.conflicts = FALSE) # Test connection shows the SQL query. dbplyr::tbl_lazy(mtcars, simulate_polarssql(), name = "mtcars") |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) # Actual polarssql connection shows the Polars naive plan (LazyFrame). tbl_polarssql(mtcars) |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) # Unlike other dbplyr backends, `compute` has a special behavior. # It returns a polars DataFrame. tbl_polarssql(mtcars) |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) |> compute()
library(dplyr, warn.conflicts = FALSE) # Test connection shows the SQL query. dbplyr::tbl_lazy(mtcars, simulate_polarssql(), name = "mtcars") |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) # Actual polarssql connection shows the Polars naive plan (LazyFrame). tbl_polarssql(mtcars) |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) # Unlike other dbplyr backends, `compute` has a special behavior. # It returns a polars DataFrame. tbl_polarssql(mtcars) |> filter(cyl == 4) |> arrange(desc(mpg)) |> select(contains("c")) |> head(n = 3) |> compute()
polarssql()
creates a DBI driver instance.
polarssql()
polarssql()
polarssql()
polarssql()
Get the default built-in connection.
polarssql_default_connection()
polarssql_default_connection()
A polarssql connection object
# Clean up DBI::dbDisconnect(polarssql_default_connection()) polarssql_default_connection() # Register a Table polarssql_register(mtcars = mtcars) polarssql_default_connection() # Clean up polarssql_unregister("mtcars") polarssql_default_connection()
# Clean up DBI::dbDisconnect(polarssql_default_connection()) polarssql_default_connection() # Register a Table polarssql_register(mtcars = mtcars) polarssql_default_connection() # Clean up polarssql_unregister("mtcars") polarssql_default_connection()
Execute SQL query
polarssql_query(sql, conn = polarssql_default_connection())
polarssql_query(sql, conn = polarssql_default_connection())
sql |
A SQL string. |
conn |
A polarssql connection, created by |
polarssql_register(mtcars = mtcars) query <- "SELECT * FROM mtcars LIMIT 5" # Returns a polars LazyFrame polarssql_query(query) # Clean up polarssql_unregister("mtcars")
polarssql_register(mtcars = mtcars) query <- "SELECT * FROM mtcars LIMIT 5" # Returns a polars LazyFrame polarssql_query(query) # Clean up polarssql_unregister("mtcars")
Register data frames as tables
polarssql_register( ..., .conn = polarssql_default_connection(), .overwrite = FALSE ) polarssql_unregister(names, conn = polarssql_default_connection())
polarssql_register( ..., .conn = polarssql_default_connection(), .overwrite = FALSE ) polarssql_unregister(names, conn = polarssql_default_connection())
... |
< |
.conn , conn
|
A polarssql connection, created by |
.overwrite |
Should an existing registration be overwritten? |
names |
Names of the tables to unregister. |
The polarssql connection invisibly.
con <- dbConnect(polarssql()) polarssql_register(df1 = mtcars, df2 = mtcars, .conn = con) con polarssql_unregister(c("df1", "df2"), conn = con) con
con <- dbConnect(polarssql()) polarssql_register(df1 = mtcars, df2 = mtcars, .conn = con) con polarssql_unregister(c("df1", "df2"), conn = con) con