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

Initial SQL support #918

Merged
merged 15 commits into from
Jun 19, 2024
Merged

Initial SQL support #918

merged 15 commits into from
Jun 19, 2024

Conversation

billylanchantin
Copy link
Member

@billylanchantin billylanchantin commented Jun 2, 2024

Description

This PR experiments with initial SQL support by adding Explorer.DataFrame.sql/3 for making SQL queries against dataframes.

Example

iex> df = DF.new(a: [1, 2, 3], b: ["x", "y", "y"])
iex> DF.sql(df, "select a, b from df group by b order by b")
# #Explorer.DataFrame<
#   Polars[2 x 2]
#   a list[s64] [[1], [2, 3]]
#   b string ["x", "y"]
# >

Limitations

  • Single table only for the moment, though Polars has multi-table functionality.
  • No expressions.

@billylanchantin billylanchantin marked this pull request as ready for review June 17, 2024 15:10
@billylanchantin billylanchantin changed the title [WIP] Initial SQL support Initial SQL support Jun 17, 2024
Copy link

@philss philss left a comment

Choose a reason for hiding this comment

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

Awesome job! 🚀

I added some minor points :)

lib/explorer/data_frame.ex Show resolved Hide resolved
lib/explorer/polars_backend/lazy_frame.ex Outdated Show resolved Hide resolved
lib/explorer/query/sql.ex Outdated Show resolved Hide resolved
native/explorer/src/lazyframe.rs Outdated Show resolved Hide resolved
billylanchantin and others added 3 commits June 17, 2024 11:50
Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

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

@billylanchantin this is looking great! Is my understanding correct that we have two features in this pull request? One is to write SQL at the root level and another is to embed SQL inside mutate? Can I propose for us to add only the first one for now and then evolve it from there?

@billylanchantin
Copy link
Member Author

@josevalim I'm good with that! DF.sql is more powerful and has actual documentation :)

Any particular hesitation with the embedded SQL part? Or are you just favoring smaller changes since this is experimental?

let's see if we can get this right in one go...
@josevalim
Copy link
Member

Just favoring something smaller for now. It is always easier to add stuff than to remove them. :)

@billylanchantin billylanchantin merged commit dda9234 into main Jun 19, 2024
4 checks passed
@billylanchantin billylanchantin deleted the bl-initial-sql branch June 19, 2024 13:44
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.

3 participants