Skip to content

Improve API of view catalog object #5670

Open
@leiysky

Description

@leiysky

So far, if we want to get the query text of an exists view, we have to:

  • Get a Table object from Catalog with Catalog::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 with Table::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 {...}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-improvementCategory: improvementstaleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions