|
16 | 16 | // under the License. |
17 | 17 |
|
18 | 18 | use crate::logical_plan::producer::utils::flatten_names; |
| 19 | +#[allow(deprecated)] |
| 20 | +use crate::variation_const::TIMESTAMP_NANO_TYPE_VARIATION_REF; |
19 | 21 | use crate::variation_const::{ |
20 | 22 | DATE_32_TYPE_VARIATION_REF, DATE_64_TYPE_VARIATION_REF, |
21 | 23 | DECIMAL_128_TYPE_VARIATION_REF, DECIMAL_256_TYPE_VARIATION_REF, |
22 | 24 | DEFAULT_CONTAINER_TYPE_VARIATION_REF, DEFAULT_TYPE_VARIATION_REF, |
23 | 25 | LARGE_CONTAINER_TYPE_VARIATION_REF, UNSIGNED_INTEGER_TYPE_VARIATION_REF, |
24 | 26 | VIEW_CONTAINER_TYPE_VARIATION_REF, |
25 | 27 | }; |
26 | | -use datafusion::arrow::datatypes::{DataType, IntervalUnit, TimeUnit}; |
| 28 | +use datafusion::arrow::datatypes::{DataType, IntervalUnit}; |
27 | 29 | use datafusion::common::{internal_err, not_impl_err, plan_err, DFSchemaRef}; |
28 | 30 | use substrait::proto::{r#type, NamedStruct}; |
29 | 31 |
|
@@ -105,31 +107,16 @@ pub(crate) fn to_substrait_type( |
105 | 107 | nullability, |
106 | 108 | })), |
107 | 109 | }), |
108 | | - DataType::Timestamp(unit, tz) => { |
109 | | - let precision = match unit { |
110 | | - TimeUnit::Second => 0, |
111 | | - TimeUnit::Millisecond => 3, |
112 | | - TimeUnit::Microsecond => 6, |
113 | | - TimeUnit::Nanosecond => 9, |
114 | | - }; |
115 | | - let kind = match tz { |
116 | | - None => r#type::Kind::PrecisionTimestamp(r#type::PrecisionTimestamp { |
117 | | - type_variation_reference: DEFAULT_TYPE_VARIATION_REF, |
| 110 | + DataType::Timestamp(_unit, _) => { |
| 111 | + // TODO: DataDog-specific workaround, don't commit upstream |
| 112 | + #[allow(deprecated)] |
| 113 | + let type_variation_reference = TIMESTAMP_NANO_TYPE_VARIATION_REF; |
| 114 | + Ok(substrait::proto::Type { |
| 115 | + kind: Some(r#type::Kind::Timestamp(r#type::Timestamp { |
| 116 | + type_variation_reference, |
118 | 117 | nullability, |
119 | | - precision, |
120 | | - }), |
121 | | - Some(_) => { |
122 | | - // If timezone is present, no matter what the actual tz value is, it indicates the |
123 | | - // value of the timestamp is tied to UTC epoch. That's all that Substrait cares about. |
124 | | - // As the timezone is lost, this conversion may be lossy for downstream use of the value. |
125 | | - r#type::Kind::PrecisionTimestampTz(r#type::PrecisionTimestampTz { |
126 | | - type_variation_reference: DEFAULT_TYPE_VARIATION_REF, |
127 | | - nullability, |
128 | | - precision, |
129 | | - }) |
130 | | - } |
131 | | - }; |
132 | | - Ok(substrait::proto::Type { kind: Some(kind) }) |
| 118 | + })), |
| 119 | + }) |
133 | 120 | } |
134 | 121 | DataType::Date32 => Ok(substrait::proto::Type { |
135 | 122 | kind: Some(r#type::Kind::Date(r#type::Date { |
@@ -284,6 +271,8 @@ pub(crate) fn to_substrait_type( |
284 | 271 | precision: *p as i32, |
285 | 272 | })), |
286 | 273 | }), |
| 274 | + // TODO: DataDog-specific workaround, don't commit upstream |
| 275 | + DataType::Dictionary(_, dt) => to_substrait_type(dt, nullable), |
287 | 276 | _ => not_impl_err!("Unsupported cast type: {dt:?}"), |
288 | 277 | } |
289 | 278 | } |
@@ -337,12 +326,13 @@ mod tests { |
337 | 326 | round_trip_type(DataType::Float32)?; |
338 | 327 | round_trip_type(DataType::Float64)?; |
339 | 328 |
|
340 | | - for tz in [None, Some("UTC".into())] { |
341 | | - round_trip_type(DataType::Timestamp(TimeUnit::Second, tz.clone()))?; |
342 | | - round_trip_type(DataType::Timestamp(TimeUnit::Millisecond, tz.clone()))?; |
343 | | - round_trip_type(DataType::Timestamp(TimeUnit::Microsecond, tz.clone()))?; |
344 | | - round_trip_type(DataType::Timestamp(TimeUnit::Nanosecond, tz))?; |
345 | | - } |
| 329 | + // TODO: DataDog-specific workaround, don't commit upstream |
| 330 | + // for tz in [None, Some("UTC".into())] { |
| 331 | + // round_trip_type(DataType::Timestamp(TimeUnit::Second, tz.clone()))?; |
| 332 | + // round_trip_type(DataType::Timestamp(TimeUnit::Millisecond, tz.clone()))?; |
| 333 | + // round_trip_type(DataType::Timestamp(TimeUnit::Microsecond, tz.clone()))?; |
| 334 | + // round_trip_type(DataType::Timestamp(TimeUnit::Nanosecond, tz))?; |
| 335 | + // } |
346 | 336 |
|
347 | 337 | round_trip_type(DataType::Date32)?; |
348 | 338 | round_trip_type(DataType::Date64)?; |
|
0 commit comments