Skip to content

Commit

Permalink
chore: remove lazy_static dep in favor of LazyLock
Browse files Browse the repository at this point in the history
LazyLock has been available since 1.80 which is less than MSRV
  • Loading branch information
nyurik committed Jan 20, 2025
1 parent a73d646 commit b1accc7
Show file tree
Hide file tree
Showing 25 changed files with 301 additions and 310 deletions.
1 change: 0 additions & 1 deletion crates/aws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ aws-credential-types = { version="1.2", features = ["hardcoded-credentials"]}
aws-config = { version = "1.5", default-features = false, features = ["behavior-version-latest","rt-tokio", "credentials-process", "sso"] }
aws-sdk-dynamodb = {version = "1.45", default-features = false, features = ["behavior-version-latest", "rt-tokio"] }
aws-sdk-sts = {version = "1.42", default-features = false, features = ["behavior-version-latest", "rt-tokio"] }
lazy_static = "1"
maplit = "1"

# workspace dependencies
Expand Down
18 changes: 9 additions & 9 deletions crates/aws/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! delta-rs
//!
use lazy_static::lazy_static;
use std::sync::LazyLock;
use std::time::Duration;

/// Custom S3 endpoint.
Expand Down Expand Up @@ -150,15 +150,15 @@ pub const STRING_TYPE: &str = "S";
pub const KEY_TYPE_HASH: &str = "HASH";
pub const KEY_TYPE_RANGE: &str = "RANGE";

lazy_static! {
pub static ref CONDITION_EXPR_CREATE: String = format!(
"attribute_not_exists({ATTR_TABLE_PATH}) and attribute_not_exists({ATTR_FILE_NAME})"
);
pub static CONDITION_EXPR_CREATE: LazyLock<String> = LazyLock::new(|| {
format!("attribute_not_exists({ATTR_TABLE_PATH}) and attribute_not_exists({ATTR_FILE_NAME})")
});

pub static ref CONDITION_DELETE_INCOMPLETE: String = format!(
"(complete = :f) or (attribute_not_exists({ATTR_TABLE_PATH}) and attribute_not_exists({ATTR_FILE_NAME}))"
);
}
pub static CONDITION_DELETE_INCOMPLETE: LazyLock<String> = LazyLock::new(|| {
format!(
"(complete = :f) or (attribute_not_exists({ATTR_TABLE_PATH}) and attribute_not_exists({ATTR_FILE_NAME}))"
)
});

pub const CONDITION_UPDATE_INCOMPLETE: &str = "complete = :f";
pub const DEFAULT_COMMIT_ENTRY_EXPIRATION_DELAY: Duration = Duration::from_secs(86_400);
9 changes: 4 additions & 5 deletions crates/aws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use deltalake_core::storage::object_store::aws::AmazonS3ConfigKey;
use deltalake_core::storage::{factories, url_prefix_handler, ObjectStoreRef, StorageOptions};
use deltalake_core::{DeltaResult, Path};
use errors::{DynamoDbConfigError, LockClientError};
use lazy_static::lazy_static;
use regex::Regex;
use std::sync::LazyLock;
use std::{
collections::HashMap,
str::FromStr,
Expand Down Expand Up @@ -703,10 +703,9 @@ fn num_attr<T: ToString>(n: T) -> AttributeValue {
AttributeValue::N(n.to_string())
}

lazy_static! {
static ref DELTA_LOG_PATH: Path = Path::from("_delta_log");
static ref DELTA_LOG_REGEX: Regex = Regex::new(r"(\d{20})\.(json|checkpoint).*$").unwrap();
}
static DELTA_LOG_PATH: LazyLock<Path> = LazyLock::new(|| Path::from("_delta_log"));
static DELTA_LOG_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(\d{20})\.(json|checkpoint).*$").unwrap());

/// Extract version from a file name in the delta log
fn extract_version_from_filename(name: &str) -> Option<i64> {
Expand Down
13 changes: 7 additions & 6 deletions crates/aws/tests/integration_s3_dynamodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![cfg(feature = "integration_test")]

use std::collections::HashMap;
use std::sync::LazyLock;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use aws_sdk_dynamodb::types::BillingMode;
Expand All @@ -19,7 +20,6 @@ use deltalake_core::storage::StorageOptions;
use deltalake_core::table::builder::ensure_table_uri;
use deltalake_core::{DeltaOps, DeltaTable, DeltaTableBuilder, ObjectStoreError};
use deltalake_test::utils::*;
use lazy_static::lazy_static;
use object_store::path::Path;
use serde_json::Value;
use serial_test::serial;
Expand All @@ -35,12 +35,13 @@ use common::*;

pub type TestResult<T> = Result<T, Box<dyn std::error::Error + 'static>>;

lazy_static! {
static ref OPTIONS: HashMap<String, String> = maplit::hashmap! {
static OPTIONS: LazyLock<HashMap<String, String>> = LazyLock::new(|| {
hashmap! {
"allow_http".to_owned() => "true".to_owned(),
};
static ref S3_OPTIONS: S3StorageOptions = S3StorageOptions::from_map(&OPTIONS).unwrap();
}
}
});
static S3_OPTIONS: LazyLock<S3StorageOptions> =
LazyLock::new(|| S3StorageOptions::from_map(&OPTIONS).unwrap());

fn make_client() -> TestResult<DynamoDbLockClient> {
let options: S3StorageOptions = S3StorageOptions::try_default().unwrap();
Expand Down
1 change: 0 additions & 1 deletion crates/azure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rust-version.workspace = true
deltalake-core = { version = "0.24.0", path = "../core", features = [
"datafusion",
]}
lazy_static = "1"

# workspace depenndecies
async-trait = { workspace = true }
Expand Down
13 changes: 6 additions & 7 deletions crates/azure/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
//! provide credentials for a service principal. Some of this configutaion may
//! partially be specified in the environment. This module establishes a structured
//! way how we discover valid credentials and some heuristics on how they are prioritized.
use std::collections::{hash_map::Entry, HashMap};
use std::str::FromStr;

use object_store::azure::AzureConfigKey;
use object_store::Error as ObjectStoreError;
use std::collections::{hash_map::Entry, HashMap};
use std::str::FromStr;
use std::sync::LazyLock;

use crate::error::Result;

lazy_static::lazy_static! {
static ref CREDENTIAL_KEYS: Vec<AzureConfigKey> =
static CREDENTIAL_KEYS: LazyLock<Vec<AzureConfigKey>> = LazyLock::new(|| {
Vec::from_iter([
AzureConfigKey::ClientId,
AzureConfigKey::ClientSecret,
Expand All @@ -23,8 +22,8 @@ lazy_static::lazy_static! {
AzureConfigKey::MsiEndpoint,
AzureConfigKey::ObjectId,
AzureConfigKey::MsiResourceId,
]);
}
])
});

/// Credential
enum AzureCredential {
Expand Down
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ either = "1.8"
fix-hidden-lifetime-bug = "0.2"
indexmap = "2.2.1"
itertools = "0.14"
lazy_static = "1"
libc = ">=0.2.90, <1"
num-bigint = "0.4"
num-traits = "0.2.15"
Expand Down
22 changes: 12 additions & 10 deletions crates/core/src/delta_datafusion/cdf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Logical operators and physical executions for CDF
use std::collections::HashMap;
use std::sync::LazyLock;

use arrow_schema::{DataType, Field, TimeUnit};
use lazy_static::lazy_static;

pub(crate) use self::scan::*;
pub(crate) use self::scan_utils::*;
Expand All @@ -19,25 +19,27 @@ pub const COMMIT_VERSION_COL: &str = "_commit_version";
/// Commit Timestamp column name
pub const COMMIT_TIMESTAMP_COL: &str = "_commit_timestamp";

lazy_static! {
pub(crate) static ref CDC_PARTITION_SCHEMA: Vec<Field> = vec![
pub(crate) static CDC_PARTITION_SCHEMA: LazyLock<Vec<Field>> = LazyLock::new(|| {
vec![
Field::new(COMMIT_VERSION_COL, DataType::Int64, true),
Field::new(
COMMIT_TIMESTAMP_COL,
DataType::Timestamp(TimeUnit::Millisecond, None),
true
)
];
pub(crate) static ref ADD_PARTITION_SCHEMA: Vec<Field> = vec![
true,
),
]
});
pub(crate) static ADD_PARTITION_SCHEMA: LazyLock<Vec<Field>> = LazyLock::new(|| {
vec![
Field::new(CHANGE_TYPE_COL, DataType::Utf8, true),
Field::new(COMMIT_VERSION_COL, DataType::Int64, true),
Field::new(
COMMIT_TIMESTAMP_COL,
DataType::Timestamp(TimeUnit::Millisecond, None),
true
true,
),
];
}
]
});

#[derive(Debug)]
pub(crate) struct CdcDataSpec<F: FileAction> {
Expand Down
27 changes: 15 additions & 12 deletions crates/core/src/kernel/arrow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! Conversions between Delta and Arrow data types
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use arrow_schema::{
DataType as ArrowDataType, Field as ArrowField, FieldRef as ArrowFieldRef,
Schema as ArrowSchema, SchemaRef as ArrowSchemaRef,
};
use lazy_static::lazy_static;

pub(crate) mod extract;
pub(crate) mod json;
Expand Down Expand Up @@ -184,8 +183,8 @@ pub(crate) fn delta_log_schema_for_table(
partition_columns: &[String],
use_extended_remove_schema: bool,
) -> ArrowSchemaRef {
lazy_static! {
static ref SCHEMA_FIELDS: Vec<ArrowField> = arrow_defs![
static SCHEMA_FIELDS: LazyLock<Vec<ArrowField>> = LazyLock::new(|| {
arrow_defs![
metaData[
id:Utf8,
name:Utf8,
Expand All @@ -206,8 +205,10 @@ pub(crate) fn delta_log_schema_for_table(
appId:Utf8,
version:Int64
]
];
static ref ADD_FIELDS: Vec<ArrowField> = arrow_defs![
]
});
static ADD_FIELDS: LazyLock<Vec<ArrowField>> = LazyLock::new(|| {
arrow_defs![
path:Utf8,
size:Int64,
modificationTime:Int64,
Expand All @@ -222,16 +223,18 @@ pub(crate) fn delta_log_schema_for_table(
sizeInBytes:Int32 not_null,
cardinality:Int64 not_null
]
];
static ref REMOVE_FIELDS: Vec<ArrowField> = arrow_defs![
]
});
static REMOVE_FIELDS: LazyLock<Vec<ArrowField>> = LazyLock::new(|| {
arrow_defs![
path: Utf8,
deletionTimestamp: Int64,
dataChange: Boolean,
extendedFileMetadata: Boolean
];
static ref REMOVE_EXTENDED_FILE_METADATA_FIELDS: Vec<ArrowField> =
arrow_defs![size: Int64, partitionValues, tags];
};
]
});
static REMOVE_EXTENDED_FILE_METADATA_FIELDS: LazyLock<Vec<ArrowField>> =
LazyLock::new(|| arrow_defs![size: Int64, partitionValues, tags]);

// create add fields according to the specific data table schema
let (partition_fields, non_partition_fields): (Vec<ArrowFieldRef>, Vec<ArrowFieldRef>) =
Expand Down
7 changes: 4 additions & 3 deletions crates/core/src/kernel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Delta Kernel module
//!
//! The Kernel module contains all the logic for reading and processing the Delta Lake transaction log.
use delta_kernel::engine::arrow_expression::ArrowExpressionHandler;
use std::sync::LazyLock;

pub mod arrow;
pub mod error;
Expand All @@ -21,6 +23,5 @@ pub trait DataCheck {
fn get_expression(&self) -> &str;
}

lazy_static::lazy_static! {
static ref ARROW_HANDLER: ArrowExpressionHandler = ArrowExpressionHandler {};
}
static ARROW_HANDLER: LazyLock<ArrowExpressionHandler> =
LazyLock::new(|| ArrowExpressionHandler {});
Loading

0 comments on commit b1accc7

Please sign in to comment.