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

refactor: replace OnceLock with LazyLock (round 2) #13674

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

jonahgao
Copy link
Member

@jonahgao jonahgao commented Dec 6, 2024

Which issue does this PR close?

Part of #11687

Replaced the remaining OnceLocks except for function Documentation instances.

Rationale for this change

LazyLock provides a simpler way to define static variables.

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Physical Expressions core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) functions labels Dec 6, 2024
@@ -332,13 +330,13 @@ async fn evaluate_agg_test(expr: Expr, expected_lines: Vec<&str>) {
/// Converts the `Expr` to a `PhysicalExpr`, evaluates it against the provided
/// `RecordBatch` and compares the result to the expected result.
fn evaluate_expr_test(expr: Expr, expected_lines: Vec<&str>) {
let batch = test_batch();
let batch = &TEST_BATCH;
Copy link
Member Author

Choose a reason for hiding this comment

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

This change also avoids a clone.

[< STATIC_ $UDAF >]
.get_or_init(|| {
/// Singleton instance of [$UDAF], ensures the UDAF is only created once
static INSTANCE: std::sync::LazyLock<std::sync::Arc<crate::AggregateUDF>> =
Copy link
Member Author

Choose a reason for hiding this comment

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

Narrow the scope to inside the function, so we can use a simpler name.

})
.clone()
/// Singleton instance of the function
static $GNAME: std::sync::LazyLock<
Copy link
Member Author

Choose a reason for hiding this comment

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

$GNAME can be removed, maybe in a follow-up PR.

Copy link
Contributor

@crepererum crepererum 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

@crepererum crepererum merged commit ce330ec into apache:main Dec 6, 2024
25 checks passed
@jonahgao jonahgao deleted the lazylock branch December 6, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate functions logical-expr Logical plan and expressions physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants