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

Julia API: Add load! to add a DataFrame as a table #4743

Merged
merged 2 commits into from
Sep 18, 2022

Conversation

jfb-h
Copy link
Contributor

@jfb-h jfb-h commented Sep 18, 2022

as proposed in #4641, this PR adds a function load!(con, df, table) to add a DataFrame as a DuckDB table, mimicking the SQLite.jl API.

Compared to the existing appendDataFrame, I changed the INSERT INTO into the CREATE TABLE AS also proposed in the issue to match the semantics of load!. Also, for load! I put the connection as the first argument, as the ! convention usually indicates the first argument being mutated.

I wasn't quite sure where to put the function, so I put it where appendDataFrame was for now. Feel free to move things around!

as proposed in [duckdb#4641](duckdb#4641), this PR adds a function `load!(con, df, table)` to add a DataFrame as a DuckDB table, mimicking the SQLite.jl API.

Compared to the existing `appendDataFrame`, I changed the `INSERT INTO` into the  `CREATE TABLE AS` also proposed in the issue to match the semantics of `load!`. Also, for `load!` I put the connection as the first argument, as the `!` convention usually indicates the first argument being mutated.

I wasn't quite sure where to put the function, so I put it where `appendDataFrame` was for now. Feel free to move things around!
Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! LGTM. One minor comment:

function load!(con::Connection, input_df::DataFrame, table::AbstractString, schema::String = "main")
register_data_frame(con, input_df, "__append_df")
DBInterface.execute(con, "CREATE TABLE \"$schema\".\"$table\" AS SELECT * FROM __append_df")
return unregister_data_frame(con, "__append_df")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this supposed to be the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what append_data_frame had done before. As unregister_data_frame just returns nothing, I made that more explicit now.

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@Mytherin Mytherin merged commit 705fc18 into duckdb:master Sep 18, 2022
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.

None yet

2 participants