From 5b860878da9f9698edd57adaa9bb5f6b747d5e0d Mon Sep 17 00:00:00 2001 From: Rafael Fernandez Date: Sat, 28 Mar 2026 19:20:03 +0100 Subject: [PATCH] [SPARK-53316] Add DayTimeInterval literal type --- crates/connect/src/expressions.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/connect/src/expressions.rs b/crates/connect/src/expressions.rs index 488227a..5e4e11c 100644 --- a/crates/connect/src/expressions.rs +++ b/crates/connect/src/expressions.rs @@ -249,6 +249,22 @@ where } } +/// Represents a Spark DayTimeInterval literal value. +/// +/// Stores the interval as a total number of microseconds. +#[derive(Clone, Debug)] +pub struct DayTimeIntervalLiteral(pub i64); + +impl From for spark::expression::Literal { + fn from(value: DayTimeIntervalLiteral) -> Self { + spark::expression::Literal { + literal_type: Some(spark::expression::literal::LiteralType::DayTimeInterval( + value.0, + )), + } + } +} + impl From<&str> for spark::expression::cast::CastToType { fn from(value: &str) -> Self { spark::expression::cast::CastToType::TypeStr(value.to_string()) @@ -266,3 +282,21 @@ impl From for spark::expression::cast::CastToType { spark::expression::cast::CastToType::Type(value.into()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_day_time_interval_literal() { + // 1 day in microseconds + let interval = DayTimeIntervalLiteral(86_400_000_000); + let literal: spark::expression::Literal = interval.into(); + assert_eq!( + literal.literal_type, + Some(spark::expression::literal::LiteralType::DayTimeInterval( + 86_400_000_000 + )) + ); + } +}