Skip to content

Conversation

@cht42
Copy link
Contributor

@cht42 cht42 commented Jan 20, 2026

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) spark 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
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
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

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

Labels

spark 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