Skip to content

Commit

Permalink
Merge branch 'main' into chore/fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
roeap authored Feb 5, 2025
2 parents 78439ff + e2378a5 commit 24d3a06
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
33 changes: 24 additions & 9 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@ repository.workspace = true
readme.workspace = true
version.workspace = true
# exclude golden tests + golden test data since they push us over 10MB crate size limit
exclude = ["tests/golden_tables.rs", "tests/golden_data/" ]
exclude = ["tests/golden_tables.rs", "tests/golden_data/"]
rust-version.workspace = true

[package.metadata.docs.rs]
all-features = true

[package.metadata.release]
pre-release-replacements = [
{file="../README.md", search="delta_kernel = \"[a-z0-9\\.-]+\"", replace="delta_kernel = \"{{version}}\""},
{file="../README.md", search="version = \"[a-z0-9\\.-]+\"", replace="version = \"{{version}}\""},
{ file = "../README.md", search = "delta_kernel = \"[a-z0-9\\.-]+\"", replace = "delta_kernel = \"{{version}}\"" },
{ file = "../README.md", search = "version = \"[a-z0-9\\.-]+\"", replace = "version = \"{{version}}\"" },
]
pre-release-hook = [
"git",
"cliff",
"--repository",
"../",
"--config",
"../cliff.toml",
"--unreleased",
"--prepend",
"../CHANGELOG.md",
"--tag",
"{{version}}",
]
pre-release-hook = ["git", "cliff", "--repository", "../", "--config", "../cliff.toml", "--unreleased", "--prepend", "../CHANGELOG.md", "--tag", "{{version}}" ]

[dependencies]
bytes = "1.7"
Expand Down Expand Up @@ -74,7 +86,13 @@ walkdir = { workspace = true, optional = true }

[features]
arrow-conversion = ["arrow-schema"]
arrow-expression = ["arrow-arith", "arrow-array", "arrow-buffer", "arrow-ord", "arrow-schema"]
arrow-expression = [
"arrow-arith",
"arrow-array",
"arrow-buffer",
"arrow-ord",
"arrow-schema",
]
cloud = [
"object_store/aws",
"object_store/azure",
Expand Down Expand Up @@ -106,10 +124,7 @@ default-engine-base = [

# the default-engine use the reqwest crate with default features which uses native-tls. if you want
# to instead use rustls, use 'default-engine-rustls' which has no native-tls dependency
default-engine = [
"default-engine-base",
"reqwest/default",
]
default-engine = ["default-engine-base", "reqwest/default"]

default-engine-rustls = [
"default-engine-base",
Expand Down
56 changes: 50 additions & 6 deletions kernel/src/expressions/scalars.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use chrono::{DateTime, NaiveDate, NaiveDateTime, TimeZone, Utc};
use std::cmp::Ordering;
use std::fmt::{Display, Formatter};

use chrono::{DateTime, NaiveDate, NaiveDateTime, TimeZone, Utc};

use crate::schema::{ArrayType, DataType, PrimitiveType, StructField};
use crate::utils::require;
use crate::{DeltaResult, Error};
Expand Down Expand Up @@ -89,7 +90,7 @@ impl StructData {

/// A single value, which can be null. Used for representing literal values
/// in [Expressions][crate::expressions::Expression].
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone)]
pub enum Scalar {
/// 32bit integer
Integer(i32),
Expand Down Expand Up @@ -224,6 +225,12 @@ impl Display for Scalar {
}
}

impl PartialEq for Scalar {
fn eq(&self, other: &Scalar) -> bool {
self.partial_cmp(other) == Some(Ordering::Equal)
}
}

impl PartialOrd for Scalar {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
use Scalar::*;
Expand Down Expand Up @@ -254,10 +261,13 @@ impl PartialOrd for Scalar {
(Date(_), _) => None,
(Binary(a), Binary(b)) => a.partial_cmp(b),
(Binary(_), _) => None,
(Decimal(_, _, _), _) => None, // TODO: Support Decimal
(Null(_), _) => None, // NOTE: NULL values are incomparable by definition
(Struct(_), _) => None, // TODO: Support Struct?
(Array(_), _) => None, // TODO: Support Array?
(Decimal(v1, p1, s1), Decimal(v2, p2, s2)) => (s1.eq(s2) && p1.eq(p2))
.then(|| v1.partial_cmp(v2))
.flatten(),
(Decimal(_, _, _), _) => None,
(Null(_), _) => None, // NOTE: NULL values are incomparable by definition
(Struct(_), _) => None, // TODO: Support Struct?
(Array(_), _) => None, // TODO: Support Array?
}
}
}
Expand Down Expand Up @@ -585,6 +595,7 @@ mod tests {
assert_eq!(&format!("{}", column_op), "3.1415927 IN Column(item)");
assert_eq!(&format!("{}", column_not_op), "'Cool' NOT IN Column(item)");
}

#[test]
fn test_timestamp_parse() {
let assert_timestamp_eq = |scalar_string, micros| {
Expand All @@ -599,6 +610,7 @@ mod tests {
assert_timestamp_eq("2011-01-11 13:06:07.123456", 1294751167123456);
assert_timestamp_eq("1970-01-01 00:00:00", 0);
}

#[test]
fn test_timestamp_ntz_parse() {
let assert_timestamp_eq = |scalar_string, micros| {
Expand Down Expand Up @@ -627,4 +639,36 @@ mod tests {
let p_type = PrimitiveType::Timestamp;
assert_timestamp_fails(&p_type, "1971-07-22");
}

#[test]
fn test_partial_cmp() {
let a = Scalar::Integer(1);
let b = Scalar::Integer(2);
let c = Scalar::Null(DataType::INTEGER);
assert_eq!(a.partial_cmp(&b), Some(Ordering::Less));
assert_eq!(b.partial_cmp(&a), Some(Ordering::Greater));
assert_eq!(a.partial_cmp(&a), Some(Ordering::Equal));
assert_eq!(b.partial_cmp(&b), Some(Ordering::Equal));
assert_eq!(a.partial_cmp(&c), None);
assert_eq!(c.partial_cmp(&a), None);

// assert that NULL values are incomparable
let null = Scalar::Null(DataType::INTEGER);
assert_eq!(null.partial_cmp(&null), None);
}

#[test]
fn test_partial_eq() {
let a = Scalar::Integer(1);
let b = Scalar::Integer(2);
let c = Scalar::Null(DataType::INTEGER);
assert!(!a.eq(&b));
assert!(a.eq(&a));
assert!(!a.eq(&c));
assert!(!c.eq(&a));

// assert that NULL values are incomparable
let null = Scalar::Null(DataType::INTEGER);
assert!(!null.eq(&null));
}
}
2 changes: 1 addition & 1 deletion kernel/src/predicates/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn test_default_partial_cmp_scalars() {
}

let expect_if_comparable_type = |s: &_, expect| match s {
Null(_) | Decimal(..) | Struct(_) | Array(_) => None,
Null(_) | Struct(_) | Array(_) => None,
_ => Some(expect),
};

Expand Down

0 comments on commit 24d3a06

Please sign in to comment.