Hi, `PyPushdowns` class has a useful function `fil...
# daft-dev
t
Hi,
PyPushdowns
class has a useful function
filter_required_column_names
but
Pushdowns
doesn't. Do you know any way to extract the required columns from
Pushdowns
?
Oh I figured it out, by implementing a custom
ExpressionVisitor
I can visit and keep track of the columns required in a filter expression
r
Yes! That was going to be my recommendation. I will open a PR to include this same method on Pushdowns.
@Tan Phan you can use this for now so you don't have to wait on a release.
Copy code
class _ColumnVisitor(ExpressionVisitor[set[str]]):
    """Visitor which returns a set of columns in the expression."""

    def visit_col(self, name: str) -> set[str]:
        return {name}

    def visit_lit(self, value: Any) -> set[str]:
        return set()

    def visit_alias(self, expr: Expression, alias: str) -> set[str]:
        return self.visit(expr)

    def visit_cast(self, expr: Expression, dtype: DataType) -> set[str]:
        return self.visit(expr)

    def visit_function(self, name: str, args: list[Expression]) -> set[str]:
        return set().union(*(self.visit(arg) for arg in args))
🙌 1
t
Yup. I implemented a similar class like that and it works very well. Thank you!
👏 1