Skip to content

Commit 648c185

Browse files
committed
feat: add into_view method to register DataFrame as a view
1 parent 9d589a2 commit 648c185

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

python/datafusion/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def from_pylist(
636636

637637
def from_pydict(
638638
self, data: dict[str, list[Any]], name: str | None = None
639-
) -> DataFrame:
639+
) -> DataFramee
640640
"""Create a :py:class:`~datafusion.dataframe.DataFrame` from a dictionary.
641641
642642
Args:

python/datafusion/dataframe.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def __init__(self, df: DataFrameInternal) -> None:
121121
"""
122122
self.df = df
123123

124+
def into_view(self) -> pa.Table:
125+
"""Register this DataFrame as a view in the current session.
126+
127+
"""
128+
return self.df.into_view()
129+
124130
def __getitem__(self, key: str | List[str]) -> DataFrame:
125131
"""Return a new :py:class`DataFrame` with the specified column or columns.
126132

python/tests/test_view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_register_filtered_dataframe():
2222

2323
# Filter the DataFrame (for example, keep rows where a > 2)
2424
df_filtered = df.filter(col("a") > literal(2))
25+
df_filtered = df_filtered.into_view()
2526

2627
# Register the filtered DataFrame as a table called "view1"
2728
ctx.register_table("view1", df_filtered)

src/dataframe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use datafusion::dataframe::{DataFrame, DataFrameWriteOptions};
3333
use datafusion::execution::SendableRecordBatchStream;
3434
use datafusion::parquet::basic::{BrotliLevel, Compression, GzipLevel, ZstdLevel};
3535
use datafusion::prelude::*;
36+
use datafusion::sql::sqlparser::ast::Table;
3637
use pyo3::exceptions::PyValueError;
3738
use pyo3::prelude::*;
3839
use pyo3::pybacked::PyBackedStr;

0 commit comments

Comments
 (0)