Skip to content

feat(spark): add unix date and timestamp functions - #19892

Merged
Jefffrey merged 4 commits into
apache:mainfrom
cht42:spark-unix
Jan 27, 2026
Merged

Jefffrey merged 4 commits into
apache:mainfrom
cht42:spark-unix

Conversation

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) spark Changes to datafusion-spark crate labels Jan 20, 2026
/// Returns the number of microseconds since epoch (1970-01-01 00:00:00 UTC) for the given timestamp.
/// <https://spark.apache.org/docs/latest/api/sql/index.html#unix_micros>
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct SparkUnixMicros {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can consider making these (micros, millis, seconds) a unified struct with an inner enum field to differentiate the behaviour, like so:

#[derive(Debug, Hash, Copy, Clone, Eq, PartialEq)]
enum BitShiftType {
Left,
Right,
RightUnsigned,
}
#[derive(Debug, Hash, Eq, PartialEq)]
pub struct SparkBitShift {
signature: Signature,
name: &'static str,
bit_shift_type: BitShiftType,
}

We'd then have different constructors:

pub fn left() -> Self {
Self::new("shiftleft", BitShiftType::Left)
}
pub fn right() -> Self {
Self::new("shiftright", BitShiftType::Right)
}
pub fn right_unsigned() -> Self {
Self::new("shiftrightunsigned", BitShiftType::RightUnsigned)
}

Which can be used like so:

make_udf_function!(
bit_shift::SparkBitShift,
shiftleft,
bit_shift::SparkBitShift::left
);
make_udf_function!(
bit_shift::SparkBitShift,
shiftright,
bit_shift::SparkBitShift::right
);
make_udf_function!(
bit_shift::SparkBitShift,
shiftrightunsigned,
bit_shift::SparkBitShift::right_unsigned
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds good, updated

@Jefffrey

Copy link
Copy Markdown
Contributor

Once CI passes we should be good to merge this

@Jefffrey
Jefffrey added this pull request to the merge queue Jan 27, 2026
Merged via the queue into apache:main with commit aca7169 Jan 27, 2026
28 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

Thanks @cht42

de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Closes apache#19891
- Part of #15914 

## Rationale for this change

Add spark unix date and timestamp functions.

## What changes are included in this PR?

New spark functions:
- https://spark.apache.org/docs/latest/api/sql/index.html#unix_date
- https://spark.apache.org/docs/latest/api/sql/index.html#unix_seconds
- https://spark.apache.org/docs/latest/api/sql/index.html#unix_millis
- https://spark.apache.org/docs/latest/api/sql/index.html#unix_micros

## Are these changes tested?

yes in slt

## Are there any user-facing changes?

yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spark Changes to datafusion-spark crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[datafusion-spark] add unix_date/micros/millis/seconds functions

2 participants