Skip to content

feat: New env argument to rel_from_sql() #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

krlmlr
Copy link
Collaborator

@krlmlr krlmlr commented Mar 13, 2025

Closes #645.

@krlmlr krlmlr changed the title f 645 rel env scan feat: New env argument to rel_from_sql() Mar 13, 2025
@krlmlr krlmlr enabled auto-merge (squash) March 13, 2025 06:52
@krlmlr krlmlr marked this pull request as draft March 13, 2025 06:52
auto-merge was automatically disabled March 13, 2025 06:52

Pull request was converted to draft

@krlmlr krlmlr force-pushed the f-645-rel-env-scan branch from c3b26d3 to 64c6560 Compare March 13, 2025 07:26
@krlmlr
Copy link
Collaborator Author

krlmlr commented Mar 13, 2025

@hannes: I'd like the code below to work. The issue is that Bind() is called twice, once during rel_from_sql() (which is fine) and once when accessing the data (how to fix?).

library(duckdb)
#> Loading required package: DBI
con <- dbConnect(duckdb(environment_scan = TRUE))

create_rel <- function() {
  df <- data.frame(a = 1)
  duckdb:::rel_from_sql(con, "FROM df")
}

# This works
rel <- create_rel()
rel
#> DuckDB Relation: 
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Subquery
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (DOUBLE)

# This fails
duckdb:::rel_to_altrep(rel)
#> Error: Error evaluating duckdb query: Catalog Error: Table with name df does not exist!
#> Did you mean "pg_depend"?
#> 
#> LINE 1: SELECT * FROM df
#>              ^

# Next level: this still works and doesn't crash the session
invisible(gc())
invisible(gc())
invisible(gc())
duckdb:::rel_to_altrep(rel)
#> Error: Error evaluating duckdb query: Catalog Error: Table with name df does not exist!
#> Did you mean "pg_depend"?
#> 
#> LINE 1: SELECT * FROM df
#>              ^

Created on 2025-03-13 with reprex v2.1.1

@krlmlr
Copy link
Collaborator Author

krlmlr commented Apr 9, 2025

Need this PR for the example to work.

@krlmlr
Copy link
Collaborator Author

krlmlr commented Apr 9, 2025

Proposed solution: on first bind, cache the mapping name -> SEXP somewhere.

Need to check the behavior with dbSendQuery() .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide necessary entry points for environment scan in read_duckdb_sql()
1 participant