databend
databend copied to clipboard
Improve API of view catalog object
So far, if we want to get the query text of an exists view, we have to:
- Get a
Table
object fromCatalog
withCatalog::get_table
- Check if it is a view object by validating
Table::engine() == "VIEW"
(even case-sensitive) - If it is a view object, then there is a deterministic key-value pair in
Table::options()
, which is"query" -> query_text
. Thus we need to get the query text withTable::options().get("query").unwrap()
.
IMO, it's an anti-intuitive API design. Since view object is a very common data source object in database, it deserve a well-typed structure.
I propose to introduce a data source API like:
struct View {
pub view_name: Vec<String>,
pub query_text: String,
}
pub enum DataSource {
Table(Arc<dyn Table>),
TableFunction(Arc<dyn TableFunction>),
View(View),
}
fn main() {
let catalog = Catalog::new(); // whatever, just give a Catalog object
let data_source = catalog.get_datasource(... /* Qualified table reference name */)?;
match data_source {
DataSource::Table(table) => // do sth with Table
DataSource::TableFunction(table_func) => // do sth with TableFunction
DataSource::View(view) => // do sth with View
}
}
And also, it's better to make Engine
a well-typed structure as well:
enum TableEngine {
Fuse, // "FUSE"
Github, // "GITHUB"
Memory, // "MEMORY"
Hive, // "HIVE"
... // Other static engine types
Dynamic(String)
}
impl Display for TableEngine {...}