diff --git a/datafusion/context.py b/datafusion/context.py index a36462123..6292177f7 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 @@ def show_schemas(self, **kwargs) -> Dict[str, SqlSchema]: """ 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 304319369..a003d0ca1 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