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

Enable Dataframe to be converted into views which can be used in register_table #1016

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

kosiew
Copy link
Contributor

@kosiew kosiew commented Feb 6, 2025

Which issue does this PR close?

Closes #1004.

Rationale for this change

Currently, Datafusion supports views via ViewTable, allowing logical plans to be registered as tables. However, this feature is not exposed in the Python bindings. This PR addresses that gap by enabling Dataframes to be converted to view, enabling users to create views programmatically without relying on raw SQL strings.

What changes are included in this PR?

Adds DataFrame.into_view which can then be used in
register_table.

Are there any user-facing changes?

Yes, Python users will now be able to convert dataframes into view, then register_table with the view.

@kosiew kosiew changed the title View Enable Dataframe to be converted into views which can be used in register_table Feb 6, 2025
Comment on lines +12 to +16
view = df_filtered.into_view()

assert view.kind == "view"

ctx.register_table("view1", view)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is modelled after how into_view is used in datafusion:

async fn with_column_renamed_ambiguous() -> Result<()> {
    let df = test_table().await?.select_columns(&["c1", "c2", "c3"])?;
    let ctx = SessionContext::new();

    let table = df.into_view();
    ctx.register_table("t1", table.clone())?;
    ctx.register_table("t2", table)?;

@kosiew kosiew marked this pull request as ready for review February 7, 2025 01:50
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.

Support registering views
1 participant