Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions datafusion/common/src/types/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

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

Current callers require a LogicalTypeRef, so this getter still seems to be needed.

Arc::clone($name.get_or_init(|| Arc::new(NativeType::$ty)))
Arc::clone(&$name)
}
};
}
Expand Down
12 changes: 6 additions & 6 deletions datafusion/expr/src/logical_plan/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down