@@ -32,24 +32,18 @@ use arrow_array::{
3232
3333use arrow_schema:: TimeUnit ;
3434
35- use crate :: errors :: ExpressionError ;
35+ use crate :: SparkError ;
3636
3737// Copied from arrow_arith/temporal.rs
3838macro_rules! return_compute_error_with {
3939 ( $msg: expr, $param: expr) => {
40- return {
41- Err ( ExpressionError :: ArrowError ( format!(
42- "{}: {:?}" ,
43- $msg, $param
44- ) ) )
45- }
40+ return { Err ( SparkError :: Internal ( format!( "{}: {:?}" , $msg, $param) ) ) }
4641 } ;
4742}
4843
4944// The number of days between the beginning of the proleptic gregorian calendar (0001-01-01)
5045// and the beginning of the Unix Epoch (1970-01-01)
5146const DAYS_TO_UNIX_EPOCH : i32 = 719_163 ;
52- const MICROS_TO_UNIX_EPOCH : i64 = 62_167_132_800 * 1_000_000 ;
5347
5448// Copied from arrow_arith/temporal.rs with modification to the output datatype
5549// Transforms a array of NaiveDate to an array of Date32 after applying an operation
@@ -102,7 +96,7 @@ fn as_timestamp_tz_with_op<A: ArrayAccessor<Item = T::Native>, T: ArrowTemporalT
10296 mut builder : PrimitiveBuilder < TimestampMicrosecondType > ,
10397 tz : & str ,
10498 op : F ,
105- ) -> Result < TimestampMicrosecondArray , ExpressionError >
99+ ) -> Result < TimestampMicrosecondArray , SparkError >
106100where
107101 F : Fn ( DateTime < Tz > ) -> i64 ,
108102 i64 : From < T :: Native > ,
@@ -113,7 +107,7 @@ where
113107 Some ( value) => match as_datetime_with_timezone :: < T > ( value. into ( ) , tz) {
114108 Some ( time) => builder. append_value ( op ( time) ) ,
115109 _ => {
116- return Err ( ExpressionError :: ArrowError (
110+ return Err ( SparkError :: Internal (
117111 "Unable to read value as datetime" . to_string ( ) ,
118112 ) ) ;
119113 }
@@ -129,7 +123,7 @@ fn as_timestamp_tz_with_op_single<T: ArrowTemporalType, F>(
129123 builder : & mut PrimitiveBuilder < TimestampMicrosecondType > ,
130124 tz : & Tz ,
131125 op : F ,
132- ) -> Result < ( ) , ExpressionError >
126+ ) -> Result < ( ) , SparkError >
133127where
134128 F : Fn ( DateTime < Tz > ) -> i64 ,
135129 i64 : From < T :: Native > ,
@@ -138,7 +132,7 @@ where
138132 Some ( value) => match as_datetime_with_timezone :: < T > ( value. into ( ) , * tz) {
139133 Some ( time) => builder. append_value ( op ( time) ) ,
140134 _ => {
141- return Err ( ExpressionError :: ArrowError (
135+ return Err ( SparkError :: Internal (
142136 "Unable to read value as datetime" . to_string ( ) ,
143137 ) ) ;
144138 }
@@ -256,7 +250,7 @@ fn trunc_date_to_microsec<T: Timelike>(dt: T) -> Option<T> {
256250/// array is an array of Date32 values. The array may be a dictionary array.
257251///
258252/// format is a scalar string specifying the format to apply to the timestamp value.
259- pub fn date_trunc_dyn ( array : & dyn Array , format : String ) -> Result < ArrayRef , ExpressionError > {
253+ pub ( crate ) fn date_trunc_dyn ( array : & dyn Array , format : String ) -> Result < ArrayRef , SparkError > {
260254 match array. data_type ( ) . clone ( ) {
261255 DataType :: Dictionary ( _, _) => {
262256 downcast_dictionary_array ! (
@@ -279,10 +273,10 @@ pub fn date_trunc_dyn(array: &dyn Array, format: String) -> Result<ArrayRef, Exp
279273 }
280274}
281275
282- pub fn date_trunc < T > (
276+ pub ( crate ) fn date_trunc < T > (
283277 array : & PrimitiveArray < T > ,
284278 format : String ,
285- ) -> Result < Date32Array , ExpressionError >
279+ ) -> Result < Date32Array , SparkError >
286280where
287281 T : ArrowTemporalType + ArrowNumericType ,
288282 i64 : From < T :: Native > ,
@@ -311,7 +305,7 @@ where
311305 builder,
312306 |dt| as_days_from_unix_epoch ( trunc_date_to_week ( dt) ) ,
313307 ) ) ,
314- _ => Err ( ExpressionError :: ArrowError ( format ! (
308+ _ => Err ( SparkError :: Internal ( format ! (
315309 "Unsupported format: {:?} for function 'date_trunc'" ,
316310 format
317311 ) ) ) ,
@@ -331,10 +325,10 @@ where
331325///
332326/// format is an array of strings specifying the format to apply to the corresponding date value.
333327/// The array may be a dictionary array.
334- pub fn date_trunc_array_fmt_dyn (
328+ pub ( crate ) fn date_trunc_array_fmt_dyn (
335329 array : & dyn Array ,
336330 formats : & dyn Array ,
337- ) -> Result < ArrayRef , ExpressionError > {
331+ ) -> Result < ArrayRef , SparkError > {
338332 match ( array. data_type ( ) . clone ( ) , formats. data_type ( ) . clone ( ) ) {
339333 ( DataType :: Dictionary ( _, v) , DataType :: Dictionary ( _, f) ) => {
340334 if !matches ! ( * v, DataType :: Date32 ) {
@@ -403,7 +397,7 @@ pub fn date_trunc_array_fmt_dyn(
403397 . expect ( "Unexpected value type in formats" ) ,
404398 )
405399 . map ( |a| Arc :: new ( a) as ArrayRef ) ,
406- ( dt, fmt) => Err ( ExpressionError :: ArrowError ( format ! (
400+ ( dt, fmt) => Err ( SparkError :: Internal ( format ! (
407401 "Unsupported datatype: {:}, format: {:?} for function 'date_trunc'" ,
408402 dt, fmt
409403 ) ) ) ,
@@ -434,7 +428,7 @@ macro_rules! date_trunc_array_fmt_helper {
434428 "WEEK" => Ok ( as_datetime_with_op_single( val, & mut builder, |dt| {
435429 as_days_from_unix_epoch( trunc_date_to_week( dt) )
436430 } ) ) ,
437- _ => Err ( ExpressionError :: ArrowError ( format!(
431+ _ => Err ( SparkError :: Internal ( format!(
438432 "Unsupported format: {:?} for function 'date_trunc'" ,
439433 $formats. value( index)
440434 ) ) ) ,
@@ -454,7 +448,7 @@ macro_rules! date_trunc_array_fmt_helper {
454448fn date_trunc_array_fmt_plain_plain (
455449 array : & Date32Array ,
456450 formats : & StringArray ,
457- ) -> Result < Date32Array , ExpressionError >
451+ ) -> Result < Date32Array , SparkError >
458452where
459453{
460454 let data_type = array. data_type ( ) ;
@@ -464,7 +458,7 @@ where
464458fn date_trunc_array_fmt_plain_dict < K > (
465459 array : & Date32Array ,
466460 formats : & TypedDictionaryArray < K , StringArray > ,
467- ) -> Result < Date32Array , ExpressionError >
461+ ) -> Result < Date32Array , SparkError >
468462where
469463 K : ArrowDictionaryKeyType ,
470464{
@@ -475,7 +469,7 @@ where
475469fn date_trunc_array_fmt_dict_plain < K > (
476470 array : & TypedDictionaryArray < K , Date32Array > ,
477471 formats : & StringArray ,
478- ) -> Result < Date32Array , ExpressionError >
472+ ) -> Result < Date32Array , SparkError >
479473where
480474 K : ArrowDictionaryKeyType ,
481475{
@@ -486,7 +480,7 @@ where
486480fn date_trunc_array_fmt_dict_dict < K , F > (
487481 array : & TypedDictionaryArray < K , Date32Array > ,
488482 formats : & TypedDictionaryArray < F , StringArray > ,
489- ) -> Result < Date32Array , ExpressionError >
483+ ) -> Result < Date32Array , SparkError >
490484where
491485 K : ArrowDictionaryKeyType ,
492486 F : ArrowDictionaryKeyType ,
@@ -503,7 +497,10 @@ where
503497/// timezone or no timezone. The array may be a dictionary array.
504498///
505499/// format is a scalar string specifying the format to apply to the timestamp value.
506- pub fn timestamp_trunc_dyn ( array : & dyn Array , format : String ) -> Result < ArrayRef , ExpressionError > {
500+ pub ( crate ) fn timestamp_trunc_dyn (
501+ array : & dyn Array ,
502+ format : String ,
503+ ) -> Result < ArrayRef , SparkError > {
507504 match array. data_type ( ) . clone ( ) {
508505 DataType :: Dictionary ( _, _) => {
509506 downcast_dictionary_array ! (
@@ -526,10 +523,10 @@ pub fn timestamp_trunc_dyn(array: &dyn Array, format: String) -> Result<ArrayRef
526523 }
527524}
528525
529- pub fn timestamp_trunc < T > (
526+ pub ( crate ) fn timestamp_trunc < T > (
530527 array : & PrimitiveArray < T > ,
531528 format : String ,
532- ) -> Result < TimestampMicrosecondArray , ExpressionError >
529+ ) -> Result < TimestampMicrosecondArray , SparkError >
533530where
534531 T : ArrowTemporalType + ArrowNumericType ,
535532 i64 : From < T :: Native > ,
@@ -589,7 +586,7 @@ where
589586 as_micros_from_unix_epoch_utc ( trunc_date_to_microsec ( dt) )
590587 } )
591588 }
592- _ => Err ( ExpressionError :: ArrowError ( format ! (
589+ _ => Err ( SparkError :: Internal ( format ! (
593590 "Unsupported format: {:?} for function 'timestamp_trunc'" ,
594591 format
595592 ) ) ) ,
@@ -611,10 +608,10 @@ where
611608///
612609/// format is an array of strings specifying the format to apply to the corresponding timestamp
613610/// value. The array may be a dictionary array.
614- pub fn timestamp_trunc_array_fmt_dyn (
611+ pub ( crate ) fn timestamp_trunc_array_fmt_dyn (
615612 array : & dyn Array ,
616613 formats : & dyn Array ,
617- ) -> Result < ArrayRef , ExpressionError > {
614+ ) -> Result < ArrayRef , SparkError > {
618615 match ( array. data_type ( ) . clone ( ) , formats. data_type ( ) . clone ( ) ) {
619616 ( DataType :: Dictionary ( _, _) , DataType :: Dictionary ( _, _) ) => {
620617 downcast_dictionary_array ! (
@@ -669,7 +666,7 @@ pub fn timestamp_trunc_array_fmt_dyn(
669666 dt => return_compute_error_with!( "timestamp_trunc does not support" , dt) ,
670667 )
671668 }
672- ( dt, fmt) => Err ( ExpressionError :: ArrowError ( format ! (
669+ ( dt, fmt) => Err ( SparkError :: Internal ( format ! (
673670 "Unsupported datatype: {:}, format: {:?} for function 'timestamp_trunc'" ,
674671 dt, fmt
675672 ) ) ) ,
@@ -740,7 +737,7 @@ macro_rules! timestamp_trunc_array_fmt_helper {
740737 as_micros_from_unix_epoch_utc( trunc_date_to_microsec( dt) )
741738 } )
742739 }
743- _ => Err ( ExpressionError :: ArrowError ( format!(
740+ _ => Err ( SparkError :: Internal ( format!(
744741 "Unsupported format: {:?} for function 'timestamp_trunc'" ,
745742 $formats. value( index)
746743 ) ) ) ,
@@ -762,7 +759,7 @@ macro_rules! timestamp_trunc_array_fmt_helper {
762759fn timestamp_trunc_array_fmt_plain_plain < T > (
763760 array : & PrimitiveArray < T > ,
764761 formats : & StringArray ,
765- ) -> Result < TimestampMicrosecondArray , ExpressionError >
762+ ) -> Result < TimestampMicrosecondArray , SparkError >
766763where
767764 T : ArrowTemporalType + ArrowNumericType ,
768765 i64 : From < T :: Native > ,
@@ -773,7 +770,7 @@ where
773770fn timestamp_trunc_array_fmt_plain_dict < T , K > (
774771 array : & PrimitiveArray < T > ,
775772 formats : & TypedDictionaryArray < K , StringArray > ,
776- ) -> Result < TimestampMicrosecondArray , ExpressionError >
773+ ) -> Result < TimestampMicrosecondArray , SparkError >
777774where
778775 T : ArrowTemporalType + ArrowNumericType ,
779776 i64 : From < T :: Native > ,
@@ -786,7 +783,7 @@ where
786783fn timestamp_trunc_array_fmt_dict_plain < T , K > (
787784 array : & TypedDictionaryArray < K , PrimitiveArray < T > > ,
788785 formats : & StringArray ,
789- ) -> Result < TimestampMicrosecondArray , ExpressionError >
786+ ) -> Result < TimestampMicrosecondArray , SparkError >
790787where
791788 T : ArrowTemporalType + ArrowNumericType ,
792789 i64 : From < T :: Native > ,
@@ -799,7 +796,7 @@ where
799796fn timestamp_trunc_array_fmt_dict_dict < T , K , F > (
800797 array : & TypedDictionaryArray < K , PrimitiveArray < T > > ,
801798 formats : & TypedDictionaryArray < F , StringArray > ,
802- ) -> Result < TimestampMicrosecondArray , ExpressionError >
799+ ) -> Result < TimestampMicrosecondArray , SparkError >
803800where
804801 T : ArrowTemporalType + ArrowNumericType ,
805802 i64 : From < T :: Native > ,
@@ -812,7 +809,7 @@ where
812809
813810#[ cfg( test) ]
814811mod tests {
815- use crate :: execution :: kernels:: temporal:: {
812+ use crate :: kernels:: temporal:: {
816813 date_trunc, date_trunc_array_fmt_dyn, timestamp_trunc, timestamp_trunc_array_fmt_dyn,
817814 } ;
818815 use arrow_array:: {
0 commit comments