@@ -40,6 +40,7 @@ use crate::variation_const::{
4040 LARGE_CONTAINER_TYPE_VARIATION_REF , UNSIGNED_INTEGER_TYPE_VARIATION_REF ,
4141 VIEW_CONTAINER_TYPE_VARIATION_REF ,
4242} ;
43+ use crate :: variation_const:: TIMESTAMP_NANO_TYPE_VARIATION_REF ;
4344use datafusion:: arrow:: array:: { Array , GenericListArray , OffsetSizeTrait } ;
4445use datafusion:: arrow:: temporal_conversions:: NANOSECONDS ;
4546use datafusion:: common:: {
@@ -1848,31 +1849,16 @@ fn to_substrait_type(dt: &DataType, nullable: bool) -> Result<substrait::proto::
18481849 nullability,
18491850 } ) ) ,
18501851 } ) ,
1851- DataType :: Timestamp ( unit, tz) => {
1852- let precision = match unit {
1853- TimeUnit :: Second => 0 ,
1854- TimeUnit :: Millisecond => 3 ,
1855- TimeUnit :: Microsecond => 6 ,
1856- TimeUnit :: Nanosecond => 9 ,
1857- } ;
1858- let kind = match tz {
1859- None => r#type:: Kind :: PrecisionTimestamp ( r#type:: PrecisionTimestamp {
1860- type_variation_reference : DEFAULT_TYPE_VARIATION_REF ,
1852+ DataType :: Timestamp ( _unit, _) => {
1853+ // TODO: DataDog-specific workaround, don't commit upstream
1854+ #[ allow( deprecated) ]
1855+ let type_variation_reference = TIMESTAMP_NANO_TYPE_VARIATION_REF ;
1856+ Ok ( substrait:: proto:: Type {
1857+ kind : Some ( r#type:: Kind :: Timestamp ( r#type:: Timestamp {
1858+ type_variation_reference,
18611859 nullability,
1862- precision,
1863- } ) ,
1864- Some ( _) => {
1865- // If timezone is present, no matter what the actual tz value is, it indicates the
1866- // value of the timestamp is tied to UTC epoch. That's all that Substrait cares about.
1867- // As the timezone is lost, this conversion may be lossy for downstream use of the value.
1868- r#type:: Kind :: PrecisionTimestampTz ( r#type:: PrecisionTimestampTz {
1869- type_variation_reference : DEFAULT_TYPE_VARIATION_REF ,
1870- nullability,
1871- precision,
1872- } )
1873- }
1874- } ;
1875- Ok ( substrait:: proto:: Type { kind : Some ( kind) } )
1860+ } ) ) ,
1861+ } )
18761862 }
18771863 DataType :: Date32 => Ok ( substrait:: proto:: Type {
18781864 kind : Some ( r#type:: Kind :: Date ( r#type:: Date {
@@ -2027,6 +2013,8 @@ fn to_substrait_type(dt: &DataType, nullable: bool) -> Result<substrait::proto::
20272013 precision : * p as i32 ,
20282014 } ) ) ,
20292015 } ) ,
2016+ // TODO: DataDog-specific workaround, don't commit upstream
2017+ DataType :: Dictionary ( _, dt) => to_substrait_type ( dt, nullable) ,
20302018 _ => not_impl_err ! ( "Unsupported cast type: {dt:?}" ) ,
20312019 }
20322020}
@@ -2419,6 +2407,8 @@ fn to_substrait_literal(
24192407 } ) ,
24202408 DEFAULT_TYPE_VARIATION_REF ,
24212409 ) ,
2410+ // TODO: DataDog-specific workaround, don't commit upstream
2411+ ScalarValue :: Dictionary ( _, value) => return to_substrait_literal ( producer, value) ,
24222412 _ => (
24232413 not_impl_err ! ( "Unsupported literal: {value:?}" ) ?,
24242414 DEFAULT_TYPE_VARIATION_REF ,
@@ -2621,17 +2611,18 @@ mod test {
26212611 round_trip_literal ( ScalarValue :: UInt64 ( Some ( u64:: MIN ) ) ) ?;
26222612 round_trip_literal ( ScalarValue :: UInt64 ( Some ( u64:: MAX ) ) ) ?;
26232613
2624- for ( ts, tz) in [
2625- ( Some ( 12345 ) , None ) ,
2626- ( None , None ) ,
2627- ( Some ( 12345 ) , Some ( "UTC" . into ( ) ) ) ,
2628- ( None , Some ( "UTC" . into ( ) ) ) ,
2629- ] {
2630- round_trip_literal ( ScalarValue :: TimestampSecond ( ts, tz. clone ( ) ) ) ?;
2631- round_trip_literal ( ScalarValue :: TimestampMillisecond ( ts, tz. clone ( ) ) ) ?;
2632- round_trip_literal ( ScalarValue :: TimestampMicrosecond ( ts, tz. clone ( ) ) ) ?;
2633- round_trip_literal ( ScalarValue :: TimestampNanosecond ( ts, tz) ) ?;
2634- }
2614+ // TODO: DataDog-specific workaround, don't commit upstream
2615+ // for (ts, tz) in [
2616+ // (Some(12345), None),
2617+ // (None, None),
2618+ // (Some(12345), Some("UTC".into())),
2619+ // (None, Some("UTC".into())),
2620+ // ] {
2621+ // round_trip_literal(ScalarValue::TimestampSecond(ts, tz.clone()))?;
2622+ // round_trip_literal(ScalarValue::TimestampMillisecond(ts, tz.clone()))?;
2623+ // round_trip_literal(ScalarValue::TimestampMicrosecond(ts, tz.clone()))?;
2624+ // round_trip_literal(ScalarValue::TimestampNanosecond(ts, tz))?;
2625+ // }
26352626
26362627 round_trip_literal ( ScalarValue :: List ( ScalarValue :: new_list_nullable (
26372628 & [ ScalarValue :: Float32 ( Some ( 1.0 ) ) ] ,
@@ -2730,12 +2721,13 @@ mod test {
27302721 round_trip_type ( DataType :: Float32 ) ?;
27312722 round_trip_type ( DataType :: Float64 ) ?;
27322723
2733- for tz in [ None , Some ( "UTC" . into ( ) ) ] {
2734- round_trip_type ( DataType :: Timestamp ( TimeUnit :: Second , tz. clone ( ) ) ) ?;
2735- round_trip_type ( DataType :: Timestamp ( TimeUnit :: Millisecond , tz. clone ( ) ) ) ?;
2736- round_trip_type ( DataType :: Timestamp ( TimeUnit :: Microsecond , tz. clone ( ) ) ) ?;
2737- round_trip_type ( DataType :: Timestamp ( TimeUnit :: Nanosecond , tz) ) ?;
2738- }
2724+ // TODO: DataDog-specific workaround, don't commit upstream
2725+ // for tz in [None, Some("UTC".into())] {
2726+ // round_trip_type(DataType::Timestamp(TimeUnit::Second, tz.clone()))?;
2727+ // round_trip_type(DataType::Timestamp(TimeUnit::Millisecond, tz.clone()))?;
2728+ // round_trip_type(DataType::Timestamp(TimeUnit::Microsecond, tz.clone()))?;
2729+ // round_trip_type(DataType::Timestamp(TimeUnit::Nanosecond, tz))?;
2730+ // }
27392731
27402732 round_trip_type ( DataType :: Date32 ) ?;
27412733 round_trip_type ( DataType :: Date64 ) ?;
0 commit comments