Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VTab: filter_pushdown support #401

Open
joewalnes opened this issue Nov 16, 2024 · 0 comments
Open

VTab: filter_pushdown support #401

joewalnes opened this issue Nov 16, 2024 · 0 comments

Comments

@joewalnes
Copy link

Request to include filter pushdown support for vtab extensions in Rust bindings.

This would allow things like the postgres extension (C++) to be built in Rust - allowing WHERE clause parameters to be propagated. I have a similar need, and would love to use Rust for this.

I'm happy to contribute this, if project is happy with the idea.

Straw-person API proposal

Enabling

impl TableFunction {
    ...
    pub fn supports_filter_pushdown(&self, supports: bool) -> &Self { ... }
    ...
}

pub trait VTab: Sized {
    ...
    fn supports_filter_pushdown() -> bool { false }
    ...
}

(Later: consider renaming the existing supports_pushdown() to supports_projection_pushdown(). In the C++ API it's named more explicitly to avoid confusion.)

Accessing

impl InitInfo {
    ...
    pub fn get_filters(&self) -> [(idx_t, TableFilter)] { ... }
    ...
}

Data model

This is roughly equivalent to C++ API, but far more concise with Rust's algebraic data-types

#[derive(Debug)]
pub enum TableFilter {
    Constant {
        expression_type: ExpressionType,
        value: Value,
    },
    IsNull,
    IsNotNull,
    Or(Vec<TableFilter>),
    And(Vec<TableFilter>),
    StructExtract {
        child_name: String,
        child_filter: Box<TableFilter>,
    },
    Optional(Box<TableFilter>),
}

impl TableFilter {
    pub fn evaluate(&self, value: &Value) -> bool { ... }
}

#[derive(Debug)]
pub enum ExpressionType {
    Equal,
    NotEqual,
    LessThan,
    GreaterThan,
    LessThanOrEqual,
    GreaterThanOrEqual,
}

Note: There are many many more ExpressionTypes in the C++ API, but those 6 are the most practical. eg. see postgres_scanner usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant