Skip to content
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

Static & dynamic field accessors for product types #213

Closed
jserranohidalgo opened this issue Apr 26, 2022 · 3 comments
Closed

Static & dynamic field accessors for product types #213

jserranohidalgo opened this issue Apr 26, 2022 · 3 comments
Labels
API enhancement New feature or request type system

Comments

@jserranohidalgo
Copy link
Member

jserranohidalgo commented Apr 26, 2022

We can't create column expressions that access fields of product type columns. For instance, given the following product type:

case class User(name: String, age: Int)

we would like to access fields of users as follows:

col[User]("user").getChildSafe("name"): DoricColumn[String]
col[User]("user").getChildSafe("age"): DoricColumn[Int]

Moreover, we would like to get a compilation error if we try to access a non-existing field:

col[User]("user").getChildSafe("surname") // should not compile

Dynamic invocations should be allowed too:

col[User]("user").child.name[String]: DoricColumn[String]
col[User]("user").child.age[Int]: DoricColumn[Int]
col[User]("user").child.surname[String] // should raise a non-existent column error at runtime
@jserranohidalgo jserranohidalgo added the enhancement New feature or request label Apr 26, 2022
@jserranohidalgo jserranohidalgo changed the title Custom type field accessors Static & dynamic field accessors for product types Jul 14, 2022
@jserranohidalgo
Copy link
Member Author

The approach followed in the Compossible library for implementing records could be of interest for us:

https://github.com/cvogt/compossible/blob/master/src/main/scala/Record.scala#L32

Basically, they use macros for implementing the Dynamic interface.

This may help in simplifying syntax for safe access, i.e. dc.name instead of dc.getChildSafe('name) , and reporting errors (#265)

@jserranohidalgo
Copy link
Member Author

Preliminary work on macro-based implementations of the Dynamic interface here:
https://github.com/jserranohidalgo/doric/tree/jm/struct-macros

Besides the problems of IDEs with whitebox macros, the current proposal in that branch uses the applyDynamic method, which is ugly. More work is needed to use the selectDynamic one.

@jserranohidalgo
Copy link
Member Author

Work is continued on #332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request type system
Projects
None yet
Development

No branches or pull requests

1 participant