Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Nov 1, 2024

Which issue does this PR close?

Follow on ot

Rationale for this change

Implement @findepi 's suggestion in #13206 (comment)

#13206 (comment)

What changes are included in this PR?

Make the uses of exists with an infallable closure (aka never returns Err) clear

Are these changes tested?

By CI

Are there any user-facing changes?

No

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Nov 1, 2024
pub fn any_column_refs(&self) -> bool {
self.exists(|expr| Ok(matches!(expr, Expr::Column(_))))
.unwrap()
.expect("exists closure is infallible")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, but would it be possible to make .exists not return Result at all when closure doesn't return it?

would doing Try same way as iter.try_fold does work here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could rename exists to try_exists and then switch exists to not be fallable 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried to model this in a generic way with something like

F: Fn -> R
R: MaybeFallible<bool>
```

```
trait MaybeFallible<T> {
 fn is_falure(&self) -> bool;
 fn as_value(&self) -> Option<&T>;
```

It's sufficient to model the `exists` function signature generically, but i couldn't get exist and apply both working (perhaps didn't try long enough)

@alamb alamb added the documentation Improvements or additions to documentation label Nov 3, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 5, 2024
@jonahgao jonahgao merged commit ba094e7 into apache:main Nov 7, 2024
@alamb alamb deleted the alamb/clarify_infallable branch November 7, 2024 15:58
@alamb
Copy link
Contributor Author

alamb commented Nov 7, 2024

Thank you for the review @findepi and @jonahgao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants