You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kosiew (via GitHub)" <gi...@apache.org> on 2025/02/07 01:33:40 UTC

Re: [PR] Enable Dataframe to be converted into views which can be used in register_table [datafusion-python]

kosiew commented on code in PR #1016:
URL: https://github.com/apache/datafusion-python/pull/1016#discussion_r1945827785


##########
python/tests/test_view.py:
##########
@@ -0,0 +1,34 @@
+from datafusion import SessionContext, col, literal
+
+
+def test_register_filtered_dataframe():
+    ctx = SessionContext()
+
+    data = {"a": [1, 2, 3, 4, 5], "b": [10, 20, 30, 40, 50]}
+
+    df = ctx.from_pydict(data, "my_table")
+
+    df_filtered = df.filter(col("a") > literal(2))
+    view = df_filtered.into_view()
+
+    assert view.kind == "view"
+
+    ctx.register_table("view1", view)

Review Comment:
   This is modelled after how into_view is used in [datafusion](https://github.com/apache/datafusion/blob/bab0f54daa99830339c0000a19c1b4e3489278ad/datafusion/core/tests/dataframe/mod.rs#L1670-L1677):
   
   ```
   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)?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org