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

API to get all Column references in an Expr without cloning Columns #10505

Closed
alamb opened this issue May 14, 2024 · 1 comment · Fixed by #11115
Closed

API to get all Column references in an Expr without cloning Columns #10505

alamb opened this issue May 14, 2024 · 1 comment · Fixed by #11115
Labels
enhancement New feature or request

Comments

@alamb
Copy link
Contributor

alamb commented May 14, 2024

Is your feature request related to a problem or challenge?

This API is used in several optimizer passes to recursively find all column references in an expression

pub fn Expr::to_columns(&self) -> Result<HashSet<Column>, DataFusionError>

However, it requires clone() ing all Columns (which requires allocating and copying a string) even if the caller only needs to check if there is a reference. This is inefficient and leads to a slower optimizer

Describe the solution you'd like

I would like an API that does not require copying

Describe alternatives you've considered

One version might be this (returned hasset has &Expr not `Expr)

impl Expr {
  /// Return all referenced  `Column`s  anywhere in this `Expr` 
  ///
  /// For example 
  /// * `a+b` would return `{a,b}`
  /// * `a + 1 + a` would return `{a}`
  fn column_refs(&self) -> HashSet<&Expr>  { 
  ...
  }

Additional context

No response

@alamb
Copy link
Contributor Author

alamb commented Jun 17, 2024

Here is a first PR: #10948

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

Successfully merging a pull request may close this issue.

1 participant