Skip to content
48 changes: 46 additions & 2 deletions datafusion/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/common/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down