Skip to content

feat(r/sedonadb): Add SQL translation for nested field - #1171

Merged
paleolimbot merged 3 commits into
apache:mainfrom
yutannihilation:feat/r-translate-nested-field
Aug 16, 2026
Merged

feat(r/sedonadb): Add SQL translation for nested field #1171
paleolimbot merged 3 commits into
apache:mainfrom
yutannihilation:feat/r-translate-nested-field

Conversation

@yutannihilation

Copy link
Copy Markdown
Contributor

Fix #1169

Translate an R expression a$b as SQL get_field(a, 'b').

library(sdplyr)
#> ── Attaching sdplyr packages ───────────────────────────────────── 0.4.0.9000 ──
#> ✔ sedonadb  0.4.0.9000
#> ✔ sedonafns 0.4.0.9000
#> ✔ dplyr     1.2.0

df <- sedonadb::sd_sql(
  "SELECT named_struct('bar', named_struct('baz', 1)) AS foo"
)

df |> 
  filter(foo$bar$baz > 0) |>
  transmute(value = foo$bar$baz) |>
  collect()
#> # A tibble: 1 × 1
#>   value
#>   <dbl>
#> 1     1

Created on 2026-08-16 with reprex v2.1.1

I was thinking the implementation would be simpler than this, but it seems sd_eval_expr_inner() needs to be executed recursively in order to support a mixed case like this.

df |> 
  transmute(value = .fns$get_field(foo, 'bar')$baz)

@github-actions
github-actions Bot requested a review from prantogg August 15, 2026 17:23

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

For what it's worth I did go with a "custom evaluation" approach which made this a little awkward, and possibly I should have started with a "manipulate the environment and mask and use regular evaluation" approach (like arrow and maybe others).

@paleolimbot paleolimbot changed the title feat(r/sedonadb): Add SQL translateion for nested field feat(r/sedonadb): Add SQL translation for nested field Aug 16, 2026
@paleolimbot
paleolimbot merged commit 7c5386b into apache:main Aug 16, 2026
10 checks passed
@yutannihilation
yutannihilation deleted the feat/r-translate-nested-field branch August 16, 2026 03:01
@yutannihilation

Copy link
Copy Markdown
Contributor Author

Thanks!

Btw, I was wondering if there's some reason not to build on dbplyr. Maybe something related to interoperability with Arrow...?

@paleolimbot

Copy link
Copy Markdown
Member

At the time I started this there was no good integration with ADBC which would be the natural way to execute the SQL (the latest dbplyr does, I think). Other than that, it seemed like a bit of a waste to compile expressions into SQL and then parse the SQL immediately. DataFusion has a great logical plan/expression API, and this seemed closest to duckplyr so I mostly followed what they did there.

It's probably easy to prototype this and I'm happy to add it as an option if it makes things easier!

@yutannihilation

Copy link
Copy Markdown
Contributor Author

Other than that, it seemed like a bit of a waste to compile expressions into SQL and then parse the SQL immediately. DataFusion has a great logical plan/expression API

Ah, thanks, this makes sense to me!

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.

r/sdplyr: translate nested fields in WHERE clause

2 participants