weimingdiit commented on code in PR #2131:
URL: https://github.com/apache/auron/pull/2131#discussion_r3026638174
##########
native-engine/datafusion-ext-functions/src/spark_dates.rs:
##########
@@ -72,6 +72,77 @@ pub fn spark_dayofweek(args: &[ColumnarValue]) ->
Result<ColumnarValue> {
Ok(ColumnarValue::Array(Arc::new(dayofweek)))
}
+/// `spark_weekofyear(date/timestamp/compatible-string[, timezone])`
+///
+/// Matches Spark's `weekofyear()` semantics:
+/// ISO week numbering, with Monday as the first day of the week,
+/// and week 1 defined as the first week with more than 3 days.
+///
+/// For `Timestamp` inputs, this function interprets epoch milliseconds in the
+/// provided timezone (if any) before deriving the calendar date and ISO week.
+/// If no timezone is provided, `UTC` is used by default. For `Date` and
+/// compatible string inputs, the behavior is unchanged: the value is cast to
+/// `Date32` and the ISO week is computed from the resulting date.
+pub fn spark_weekofyear(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+ // First argument as an Arrow array (date/timestamp/string, etc.)
+ let array = args[0].clone().into_array(1)?;
+
+ // Determine timezone (for timestamp inputs). Default to UTC to match
+ // existing behavior when no timezone is provided.
+ let default_tz = chrono_tz::UTC;
+ let tz: Tz = if args.len() > 1 {
+ match &args[1] {
+ ColumnarValue::Scalar(ScalarValue::Utf8(Some(s)))
+ | ColumnarValue::Scalar(ScalarValue::LargeUtf8(Some(s))) => {
+ s.parse::<Tz>().unwrap_or(default_tz)
Review Comment:
Done, just updated the code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]