@@ -19,7 +19,6 @@ use itertools::Itertools;
19
19
use std:: ops:: Deref ;
20
20
use std:: sync:: Arc ;
21
21
22
- use arrow_buffer:: ToByteSlice ;
23
22
use datafusion:: arrow:: datatypes:: IntervalUnit ;
24
23
use datafusion:: logical_expr:: {
25
24
CrossJoin , Distinct , Like , Partitioning , WindowFrameUnits ,
@@ -37,8 +36,7 @@ use crate::variation_const::{
37
36
DATE_32_TYPE_VARIATION_REF , DATE_64_TYPE_VARIATION_REF ,
38
37
DECIMAL_128_TYPE_VARIATION_REF , DECIMAL_256_TYPE_VARIATION_REF ,
39
38
DEFAULT_CONTAINER_TYPE_VARIATION_REF , DEFAULT_TYPE_VARIATION_REF ,
40
- INTERVAL_MONTH_DAY_NANO_TYPE_NAME , LARGE_CONTAINER_TYPE_VARIATION_REF ,
41
- UNSIGNED_INTEGER_TYPE_VARIATION_REF ,
39
+ LARGE_CONTAINER_TYPE_VARIATION_REF , UNSIGNED_INTEGER_TYPE_VARIATION_REF ,
42
40
} ;
43
41
use datafusion:: arrow:: array:: { Array , GenericListArray , OffsetSizeTrait } ;
44
42
use datafusion:: common:: {
@@ -56,8 +54,8 @@ use substrait::proto::exchange_rel::{ExchangeKind, RoundRobin, ScatterFields};
56
54
use substrait:: proto:: expression:: literal:: interval_day_to_second:: PrecisionMode ;
57
55
use substrait:: proto:: expression:: literal:: map:: KeyValue ;
58
56
use substrait:: proto:: expression:: literal:: {
59
- user_defined , IntervalDayToSecond , IntervalYearToMonth , List , Map ,
60
- PrecisionTimestamp , Struct , UserDefined ,
57
+ IntervalCompound , IntervalDayToSecond , IntervalYearToMonth , List , Map ,
58
+ PrecisionTimestamp , Struct ,
61
59
} ;
62
60
use substrait:: proto:: expression:: subquery:: InPredicate ;
63
61
use substrait:: proto:: expression:: window_function:: BoundsType ;
@@ -1429,16 +1427,14 @@ fn to_substrait_type(
1429
1427
} ) ) ,
1430
1428
} ) ,
1431
1429
IntervalUnit :: MonthDayNano => {
1432
- // Substrait doesn't currently support this type, so we represent it as a UDT
1433
1430
Ok ( substrait:: proto:: Type {
1434
- kind : Some ( r#type:: Kind :: UserDefined ( r#type:: UserDefined {
1435
- type_reference : extensions. register_type (
1436
- INTERVAL_MONTH_DAY_NANO_TYPE_NAME . to_string ( ) ,
1437
- ) ,
1438
- type_variation_reference : DEFAULT_TYPE_VARIATION_REF ,
1439
- nullability,
1440
- type_parameters : vec ! [ ] ,
1441
- } ) ) ,
1431
+ kind : Some ( r#type:: Kind :: IntervalCompound (
1432
+ r#type:: IntervalCompound {
1433
+ type_variation_reference : DEFAULT_TYPE_VARIATION_REF ,
1434
+ nullability,
1435
+ precision : 9 , // nanos
1436
+ } ,
1437
+ ) ) ,
1442
1438
} )
1443
1439
}
1444
1440
}
@@ -1880,23 +1876,21 @@ fn to_substrait_literal(
1880
1876
} ) ,
1881
1877
DEFAULT_TYPE_VARIATION_REF ,
1882
1878
) ,
1883
- ScalarValue :: IntervalMonthDayNano ( Some ( i) ) => {
1884
- // IntervalMonthDayNano is internally represented as a 128-bit integer, containing
1885
- // months (32bit), days (32bit), and nanoseconds (64bit)
1886
- let bytes = i. to_byte_slice ( ) ;
1887
- (
1888
- LiteralType :: UserDefined ( UserDefined {
1889
- type_reference : extensions
1890
- . register_type ( INTERVAL_MONTH_DAY_NANO_TYPE_NAME . to_string ( ) ) ,
1891
- type_parameters : vec ! [ ] ,
1892
- val : Some ( user_defined:: Val :: Value ( ProtoAny {
1893
- type_url : INTERVAL_MONTH_DAY_NANO_TYPE_NAME . to_string ( ) ,
1894
- value : bytes. to_vec ( ) . into ( ) ,
1895
- } ) ) ,
1879
+ ScalarValue :: IntervalMonthDayNano ( Some ( i) ) => (
1880
+ LiteralType :: IntervalCompound ( IntervalCompound {
1881
+ interval_year_to_month : Some ( IntervalYearToMonth {
1882
+ years : 0 ,
1883
+ months : i. months ,
1896
1884
} ) ,
1897
- DEFAULT_TYPE_VARIATION_REF ,
1898
- )
1899
- }
1885
+ interval_day_to_second : Some ( IntervalDayToSecond {
1886
+ days : i. days ,
1887
+ seconds : 0 ,
1888
+ subseconds : i. nanoseconds ,
1889
+ precision_mode : Some ( PrecisionMode :: Precision ( 9 ) ) , // nanoseconds
1890
+ } ) ,
1891
+ } ) ,
1892
+ DEFAULT_TYPE_VARIATION_REF ,
1893
+ ) ,
1900
1894
ScalarValue :: IntervalDayTime ( Some ( i) ) => (
1901
1895
LiteralType :: IntervalDayToSecond ( IntervalDayToSecond {
1902
1896
days : i. days ,
@@ -2161,7 +2155,6 @@ mod test {
2161
2155
} ;
2162
2156
use datafusion:: arrow:: datatypes:: Field ;
2163
2157
use datafusion:: common:: scalar:: ScalarStructBuilder ;
2164
- use std:: collections:: HashMap ;
2165
2158
2166
2159
#[ test]
2167
2160
fn round_trip_literals ( ) -> Result < ( ) > {
@@ -2292,39 +2285,6 @@ mod test {
2292
2285
Ok ( ( ) )
2293
2286
}
2294
2287
2295
- #[ test]
2296
- fn custom_type_literal_extensions ( ) -> Result < ( ) > {
2297
- let mut extensions = Extensions :: default ( ) ;
2298
- // IntervalMonthDayNano is represented as a custom type in Substrait
2299
- let scalar = ScalarValue :: IntervalMonthDayNano ( Some ( IntervalMonthDayNano :: new (
2300
- 17 , 25 , 1234567890 ,
2301
- ) ) ) ;
2302
- let substrait_literal = to_substrait_literal ( & scalar, & mut extensions) ?;
2303
- let roundtrip_scalar =
2304
- from_substrait_literal_without_names ( & substrait_literal, & extensions) ?;
2305
- assert_eq ! ( scalar, roundtrip_scalar) ;
2306
-
2307
- assert_eq ! (
2308
- extensions,
2309
- Extensions {
2310
- functions: HashMap :: new( ) ,
2311
- types: HashMap :: from( [ (
2312
- 0 ,
2313
- INTERVAL_MONTH_DAY_NANO_TYPE_NAME . to_string( )
2314
- ) ] ) ,
2315
- type_variations: HashMap :: new( ) ,
2316
- }
2317
- ) ;
2318
-
2319
- // Check we fail if we don't propagate extensions
2320
- assert ! ( from_substrait_literal_without_names(
2321
- & substrait_literal,
2322
- & Extensions :: default ( )
2323
- )
2324
- . is_err( ) ) ;
2325
- Ok ( ( ) )
2326
- }
2327
-
2328
2288
#[ test]
2329
2289
fn round_trip_types ( ) -> Result < ( ) > {
2330
2290
round_trip_type ( DataType :: Boolean ) ?;
@@ -2403,35 +2363,4 @@ mod test {
2403
2363
assert_eq ! ( dt, roundtrip_dt) ;
2404
2364
Ok ( ( ) )
2405
2365
}
2406
-
2407
- #[ test]
2408
- fn custom_type_extensions ( ) -> Result < ( ) > {
2409
- let mut extensions = Extensions :: default ( ) ;
2410
- // IntervalMonthDayNano is represented as a custom type in Substrait
2411
- let dt = DataType :: Interval ( IntervalUnit :: MonthDayNano ) ;
2412
-
2413
- let substrait = to_substrait_type ( & dt, true , & mut extensions) ?;
2414
- let roundtrip_dt = from_substrait_type_without_names ( & substrait, & extensions) ?;
2415
- assert_eq ! ( dt, roundtrip_dt) ;
2416
-
2417
- assert_eq ! (
2418
- extensions,
2419
- Extensions {
2420
- functions: HashMap :: new( ) ,
2421
- types: HashMap :: from( [ (
2422
- 0 ,
2423
- INTERVAL_MONTH_DAY_NANO_TYPE_NAME . to_string( )
2424
- ) ] ) ,
2425
- type_variations: HashMap :: new( ) ,
2426
- }
2427
- ) ;
2428
-
2429
- // Check we fail if we don't propagate extensions
2430
- assert ! (
2431
- from_substrait_type_without_names( & substrait, & Extensions :: default ( ) )
2432
- . is_err( )
2433
- ) ;
2434
-
2435
- Ok ( ( ) )
2436
- }
2437
2366
}
0 commit comments