This is an automated email from the ASF dual-hosted git repository.

comphead pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fbd87ff03 refactor: replace `OnceLock` with `LazyLock` (#13641)
9fbd87ff03 is described below

commit 9fbd87ff03537c21e1860bfd6fa84eeb2a70d851
Author: Jonah Gao <[email protected]>
AuthorDate: Thu Dec 5 00:54:14 2024 +0800

    refactor: replace `OnceLock` with `LazyLock` (#13641)
    
    * refactor: Replace OnceLock with LazyLock
    
    * Fix typo
---
 datafusion/common/src/types/builtin.rs        |  8 ++++----
 datafusion/expr/src/logical_plan/statement.rs | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/datafusion/common/src/types/builtin.rs 
b/datafusion/common/src/types/builtin.rs
index c6105d37c3..ec69db7903 100644
--- a/datafusion/common/src/types/builtin.rs
+++ b/datafusion/common/src/types/builtin.rs
@@ -16,17 +16,17 @@
 // under the License.
 
 use crate::types::{LogicalTypeRef, NativeType};
-use std::sync::{Arc, OnceLock};
+use std::sync::{Arc, LazyLock};
 
 macro_rules! singleton {
     ($name:ident, $getter:ident, $ty:ident) => {
-        // TODO: Use LazyLock instead of getter function when MSRV gets bumped
-        static $name: OnceLock<LogicalTypeRef> = OnceLock::new();
+        static $name: LazyLock<LogicalTypeRef> =
+            LazyLock::new(|| Arc::new(NativeType::$ty));
 
         #[doc = "Getter for singleton instance of a logical type representing"]
         #[doc = concat!("[`NativeType::", stringify!($ty), "`].")]
         pub fn $getter() -> LogicalTypeRef {
-            Arc::clone($name.get_or_init(|| Arc::new(NativeType::$ty)))
+            Arc::clone(&$name)
         }
     };
 }
diff --git a/datafusion/expr/src/logical_plan/statement.rs 
b/datafusion/expr/src/logical_plan/statement.rs
index a8b53e8a1f..93be04c275 100644
--- a/datafusion/expr/src/logical_plan/statement.rs
+++ b/datafusion/expr/src/logical_plan/statement.rs
@@ -18,14 +18,10 @@
 use arrow::datatypes::DataType;
 use datafusion_common::{DFSchema, DFSchemaRef};
 use std::fmt::{self, Display};
-use std::sync::{Arc, OnceLock};
+use std::sync::{Arc, LazyLock};
 
 use crate::{expr_vec_fmt, Expr, LogicalPlan};
 
-/// Statements have a unchanging empty schema.
-/// TODO: Use `LazyLock` when MSRV is 1.80.0
-static STATEMENT_EMPTY_SCHEMA: OnceLock<DFSchemaRef> = OnceLock::new();
-
 /// Various types of Statements.
 ///
 /// # Transactions:
@@ -54,7 +50,11 @@ pub enum Statement {
 impl Statement {
     /// Get a reference to the logical plan's schema
     pub fn schema(&self) -> &DFSchemaRef {
-        STATEMENT_EMPTY_SCHEMA.get_or_init(|| Arc::new(DFSchema::empty()))
+        // Statements have an unchanging empty schema.
+        static STATEMENT_EMPTY_SCHEMA: LazyLock<DFSchemaRef> =
+            LazyLock::new(|| Arc::new(DFSchema::empty()));
+
+        &STATEMENT_EMPTY_SCHEMA
     }
 
     /// Return a descriptive string describing the type of this


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to