This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion-python.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a62721  [SessionContext] - Add table_exist funcation for session 
context (#48)
3a62721 is described below

commit 3a62721bc9f677dac815db50cb5d958fa34a3afa
Author: Francis Du <[email protected]>
AuthorDate: Thu Sep 8 21:33:45 2022 +0800

    [SessionContext] - Add table_exist funcation for session context (#48)
    
    * feat: add table_exist funcation for dataframe
    
    * fix: flake E712
---
 datafusion/tests/test_context.py | 11 +++++++++++
 src/context.rs                   |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/datafusion/tests/test_context.py b/datafusion/tests/test_context.py
index 0950077..d207d55 100644
--- a/datafusion/tests/test_context.py
+++ b/datafusion/tests/test_context.py
@@ -168,3 +168,14 @@ def test_dataset_filter_nested_data(ctx):
 
     assert result[0].column(0) == pa.array([9])
     assert result[0].column(1) == pa.array([-3])
+
+
+def test_table_exist(ctx):
+    batch = pa.RecordBatch.from_arrays(
+        [pa.array([1, 2, 3]), pa.array([4, 5, 6])],
+        names=["a", "b"],
+    )
+    dataset = ds.dataset([batch])
+    ctx.register_dataset("t", dataset)
+
+    assert ctx.table_exist("t") is True
diff --git a/src/context.rs b/src/context.rs
index 28b133f..25d08ef 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -253,6 +253,10 @@ impl PySessionContext {
         Ok(PyDataFrame::new(self.ctx.table(name)?))
     }
 
+    fn table_exist(&self, name: &str) -> PyResult<bool> {
+        Ok(self.ctx.table_exist(name)?)
+    }
+
     fn empty_table(&self) -> PyResult<PyDataFrame> {
         Ok(PyDataFrame::new(self.ctx.read_empty()?))
     }

Reply via email to