1515// specific language governing permissions and limitations
1616// under the License.
1717
18+ use crate :: logical_plan:: producer:: to_substrait_precision;
1819use crate :: logical_plan:: producer:: utils:: flatten_names;
1920use crate :: variation_const:: {
2021 DATE_32_TYPE_VARIATION_REF , DATE_64_TYPE_VARIATION_REF ,
2122 DECIMAL_128_TYPE_VARIATION_REF , DECIMAL_256_TYPE_VARIATION_REF ,
2223 DEFAULT_CONTAINER_TYPE_VARIATION_REF , DEFAULT_INTERVAL_DAY_TYPE_VARIATION_REF ,
2324 DEFAULT_TYPE_VARIATION_REF , DURATION_INTERVAL_DAY_TYPE_VARIATION_REF ,
24- LARGE_CONTAINER_TYPE_VARIATION_REF , UNSIGNED_INTEGER_TYPE_VARIATION_REF ,
25+ LARGE_CONTAINER_TYPE_VARIATION_REF , TIME_32_TYPE_VARIATION_REF ,
26+ TIME_64_TYPE_VARIATION_REF , UNSIGNED_INTEGER_TYPE_VARIATION_REF ,
2527 VIEW_CONTAINER_TYPE_VARIATION_REF ,
2628} ;
27- use datafusion:: arrow:: datatypes:: { DataType , IntervalUnit , TimeUnit } ;
29+ use datafusion:: arrow:: datatypes:: { DataType , IntervalUnit } ;
2830use datafusion:: common:: { internal_err, not_impl_err, plan_err, DFSchemaRef } ;
2931use substrait:: proto:: { r#type, NamedStruct } ;
3032
@@ -107,12 +109,7 @@ pub(crate) fn to_substrait_type(
107109 } ) ) ,
108110 } ) ,
109111 DataType :: Timestamp ( unit, tz) => {
110- let precision = match unit {
111- TimeUnit :: Second => 0 ,
112- TimeUnit :: Millisecond => 3 ,
113- TimeUnit :: Microsecond => 6 ,
114- TimeUnit :: Nanosecond => 9 ,
115- } ;
112+ let precision = to_substrait_precision ( unit) ;
116113 let kind = match tz {
117114 None => r#type:: Kind :: PrecisionTimestamp ( r#type:: PrecisionTimestamp {
118115 type_variation_reference : DEFAULT_TYPE_VARIATION_REF ,
@@ -132,6 +129,26 @@ pub(crate) fn to_substrait_type(
132129 } ;
133130 Ok ( substrait:: proto:: Type { kind : Some ( kind) } )
134131 }
132+ DataType :: Time32 ( unit) => {
133+ let precision = to_substrait_precision ( unit) ;
134+ Ok ( substrait:: proto:: Type {
135+ kind : Some ( r#type:: Kind :: PrecisionTime ( r#type:: PrecisionTime {
136+ precision,
137+ type_variation_reference : TIME_32_TYPE_VARIATION_REF ,
138+ nullability,
139+ } ) ) ,
140+ } )
141+ }
142+ DataType :: Time64 ( unit) => {
143+ let precision = to_substrait_precision ( unit) ;
144+ Ok ( substrait:: proto:: Type {
145+ kind : Some ( r#type:: Kind :: PrecisionTime ( r#type:: PrecisionTime {
146+ precision,
147+ type_variation_reference : TIME_64_TYPE_VARIATION_REF ,
148+ nullability,
149+ } ) ) ,
150+ } )
151+ }
135152 DataType :: Date32 => Ok ( substrait:: proto:: Type {
136153 kind : Some ( r#type:: Kind :: Date ( r#type:: Date {
137154 type_variation_reference : DATE_32_TYPE_VARIATION_REF ,
@@ -173,12 +190,7 @@ pub(crate) fn to_substrait_type(
173190 }
174191 }
175192 DataType :: Duration ( duration_unit) => {
176- let precision = match duration_unit {
177- TimeUnit :: Second => 0 ,
178- TimeUnit :: Millisecond => 3 ,
179- TimeUnit :: Microsecond => 6 ,
180- TimeUnit :: Nanosecond => 9 ,
181- } ;
193+ let precision = to_substrait_precision ( duration_unit) ;
182194 Ok ( substrait:: proto:: Type {
183195 kind : Some ( r#type:: Kind :: IntervalDay ( r#type:: IntervalDay {
184196 type_variation_reference : DURATION_INTERVAL_DAY_TYPE_VARIATION_REF ,
@@ -335,7 +347,7 @@ mod tests {
335347 use crate :: logical_plan:: consumer:: {
336348 from_substrait_named_struct, from_substrait_type_without_names,
337349 } ;
338- use datafusion:: arrow:: datatypes:: { Field , Fields , Schema } ;
350+ use datafusion:: arrow:: datatypes:: { Field , Fields , Schema , TimeUnit } ;
339351 use datafusion:: common:: { DFSchema , Result } ;
340352 use std:: sync:: Arc ;
341353
@@ -360,6 +372,10 @@ mod tests {
360372 round_trip_type ( DataType :: Timestamp ( TimeUnit :: Nanosecond , tz) ) ?;
361373 }
362374
375+ round_trip_type ( DataType :: Time32 ( TimeUnit :: Second ) ) ?;
376+ round_trip_type ( DataType :: Time32 ( TimeUnit :: Millisecond ) ) ?;
377+ round_trip_type ( DataType :: Time64 ( TimeUnit :: Microsecond ) ) ?;
378+ round_trip_type ( DataType :: Time64 ( TimeUnit :: Nanosecond ) ) ?;
363379 round_trip_type ( DataType :: Date32 ) ?;
364380 round_trip_type ( DataType :: Date64 ) ?;
365381 round_trip_type ( DataType :: Binary ) ?;
0 commit comments