Skip to content

Add another method to collect referenced columns from an expression #4152

@ygf11

Description

@ygf11

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Currently we use expr_to_columns to collect referenced columns from an expression. The usage is like:

  let mut using_columns = HashSet::new();
  expr_to_columns(expr, &mut using_columns)?;

It is not convenient to use, because we need create a new HashSet everytime we invoke it. And the most usages of it is to collect from an single expression.

Describe the solution you'd like
Add a new method to Expr for collecting columns, like:

   pub fn to_columns(&self) -> Result<HashSet<Column>> {
        let mut using_columns = HashSet::new();
        expr_to_columns(self, &mut using_columns)?;

        Ok(using_columns)
    }

The usage will be like:

  let using_columns = expr.to_columns()?;
  ...

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions