Skip to content

refactor: replace unwrap_or with unwrap_or_else for improved lazy… #15841

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

NevroHelios
Copy link

… evaluation

Which issue does this PR close?

Eliminate the function call in xxx_or (e.g. unwrap_or("".to_string()) #15802

Rationale for this change

As per the issue explained I updated the function call unwrap_or with unwrap_or_else

Are these changes tested?

I build and tested the code locally with cargo build --workspace -j1 and cargo test --workspace -j1

@xudong963

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates optimizer Optimizer rules core Core DataFusion crate common Related to common crate functions Changes to functions implementation datasource Changes to the datasource crate labels Apr 24, 2025
Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

Thank you @NevroHelios , I triggered the CI, will review after ci passes

@NevroHelios
Copy link
Author

Thanks for your update @xudong963. I noticed a few checks have failed. I will look into the issues and push the updates shortly.
If there are any specific clippy or formatting issues I might have overlooked, feel free to point them out - any pointer will be helpful and thanks again for the CI trigger!

@NevroHelios
Copy link
Author

Hi @xudong963
I made the changes and pushed the updates. Could you please initiate the CI workflows when you get a chance?

@alamb alamb marked this pull request as draft April 29, 2025 01:35
@alamb
Copy link
Contributor

alamb commented Apr 29, 2025

This PR seems to have some CI failures

Please mark it as ready for review when it is ready for another look

@alamb
Copy link
Contributor

alamb commented Apr 29, 2025

Thank you for this PR @NevroHelios

@NevroHelios NevroHelios marked this pull request as ready for review April 30, 2025 21:52
@NevroHelios
Copy link
Author

Hi @alamb, apologies for the delay, I had exams recently. I've run the tests locally and everything looks good now. When you get a chance, could you please re-trigger the CI? Thanks!

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @NevroHelios -- this looks like a good set of changes. Thank you -- let's see how the CI goes.

I had one question about one of the changes, but otherwise this looks good to me

pub fn update_config(&self, config: SessionConfig) -> SessionConfig {
let mut config = config
.with_target_partitions(
self.partitions.unwrap_or_else(get_available_parallelism),
Copy link
Contributor

Choose a reason for hiding this comment

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

the original code didn't call get_available_parallelism -- this doesn't look equivalent ot me

I also think the original version of this code was easier to understad -- what is the rationale to change it?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing that out! I had originally added get_available_parallelism to fix the clippy and compiler errors. After updating the branch, now it works with the restored default configs.

@@ -130,8 +130,8 @@ impl Column {
/// where `"foo.BAR"` would be parsed to a reference to column named `foo.BAR`
pub fn from_qualified_name(flat_name: impl Into<String>) -> Self {
let flat_name = flat_name.into();
Self::from_idents(parse_identifiers_normalized(&flat_name, false)).unwrap_or(
Self {
Self::from_idents(parse_identifiers_normalized(&flat_name, false)).unwrap_or_else(
Copy link
Contributor

Choose a reason for hiding this comment

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

this makes sense to me

Copy link
Author

Choose a reason for hiding this comment

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

thanks!

@NevroHelios
Copy link
Author

I pushed the updates. Could you please run the ci again? @alamb

@NevroHelios NevroHelios requested review from alamb and xudong963 May 1, 2025 16:33
Comment on lines 82 to 84
if let Some(sort_spill_reservation_bytes) = self.sort_spill_reservation_bytes {
config =
config.with_sort_spill_reservation_bytes(sort_spill_reservation_bytes);
Copy link
Member

Choose a reason for hiding this comment

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

Why was the part removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it looks like a mistake

Copy link
Author

Choose a reason for hiding this comment

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

During the copiler errors I updated this config but later I restored most parts but I believe I mistakenly overlooked these lines during the process. Thanks for points that out. I will push the updates shortly.

@NevroHelios NevroHelios requested a review from xudong963 May 2, 2025 14:47
@NevroHelios
Copy link
Author

Hi. I pushed the updates. Could you please re run the CI? @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate core Core DataFusion crate datasource Changes to the datasource crate functions Changes to functions implementation logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Changes to the physical-expr crates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eliminate the function call in xxx_or (e.g. unwrap_or("".to_string())
3 participants