This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion-python.git
The following commit(s) were added to refs/heads/main by this push:
new 51158bd CRUD Table support for `BaseSessionContext` (#394)
51158bd is described below
commit 51158bd495d215d2260c091af7c0109dbe3b9432
Author: Jeremy Dyer <[email protected]>
AuthorDate: Tue May 30 18:21:22 2023 -0400
CRUD Table support for `BaseSessionContext` (#394)
* checkpoint commit
* Introduce BaseSessionContext abstract class
* Introduce abstract methods for CRUD schema operations
* Clean up schema.rs file
* Introduce CRUD methods for table instances
* Add function to drop_table
* Add schema_name to drop_table function
* remove unused parameter in SqlTable new
* Update function to allow for modifying existing tables
---
datafusion/context.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
src/common/schema.rs | 5 ++++-
2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/datafusion/context.py b/datafusion/context.py
index a364621..6292177 100644
--- a/datafusion/context.py
+++ b/datafusion/context.py
@@ -16,9 +16,9 @@
# under the License.
from abc import ABC, abstractmethod
-from typing import Dict
+from typing import Dict, List
-from datafusion.common import SqlSchema
+from datafusion.common import SqlSchema, SqlTable
class BaseSessionContext(ABC):
@@ -76,6 +76,50 @@ class BaseSessionContext(ABC):
"""
pass
+ @abstractmethod
+ def create_table(
+ self,
+ table_name: str,
+ schema_name: str = None,
+ **kwargs,
+ ):
+ """
+ Creates/Registers a table in the specied schema instance
+ """
+ pass
+
+ @abstractmethod
+ def update_table(
+ self,
+ schema_name: str,
+ table_name: str,
+ new_table: SqlTable,
+ **kwargs,
+ ):
+ """
+ Updates an existing table in the SessionContext
+ """
+ pass
+
+ @abstractmethod
+ def drop_table(
+ self,
+ schema_name: str,
+ table_name: str,
+ **kwargs,
+ ):
+ """
+ Drops the specified table, based on name, from the current context
+ """
+ pass
+
+ @abstractmethod
+ def show_tables(self, **kwargs) -> List[SqlTable]:
+ """
+ Return all tables in the current SessionContext impl.
+ """
+ pass
+
@abstractmethod
def register_table(
self,
diff --git a/src/common/schema.rs b/src/common/schema.rs
index 3043193..a003d0c 100644
--- a/src/common/schema.rs
+++ b/src/common/schema.rs
@@ -63,7 +63,6 @@ pub struct SqlTable {
impl SqlTable {
#[new]
pub fn new(
- _schema_name: String,
table_name: String,
columns: Vec<(String, DataTypeMap)>,
row_count: f64,
@@ -115,6 +114,10 @@ impl SqlSchema {
pub fn add_table(&mut self, table: SqlTable) {
self.tables.push(table);
}
+
+ pub fn drop_table(&mut self, table_name: String) {
+ self.tables.retain(|x| !x.name.eq(&table_name));
+ }
}
/// SqlTable wrapper that is compatible with DataFusion logical query plans