|
16 | 16 | // under the License. |
17 | 17 |
|
18 | 18 | use crate::planner::{ContextProvider, PlannerContext, SqlToRel}; |
19 | | -use arrow::compute::kernels::cast_utils::parse_interval_month_day_nano; |
| 19 | +use arrow::compute::kernels::cast_utils::{ |
| 20 | + parse_interval_month_day_nano_config, IntervalParseConfig, IntervalUnit, |
| 21 | +}; |
20 | 22 | use arrow::datatypes::DECIMAL128_MAX_PRECISION; |
21 | 23 | use arrow_schema::DataType; |
22 | 24 | use datafusion_common::{ |
@@ -232,27 +234,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { |
232 | 234 |
|
233 | 235 | let value = interval_literal(*interval.value, negative)?; |
234 | 236 |
|
235 | | - let value = if has_units(&value) { |
236 | | - // If the interval already contains a unit |
237 | | - // `INTERVAL '5 month' rather than `INTERVAL '5' month` |
238 | | - // skip the other unit |
239 | | - value |
240 | | - } else { |
241 | | - // leading_field really means the unit if specified |
242 | | - // for example, "month" in `INTERVAL '5' month` |
243 | | - match interval.leading_field.as_ref() { |
244 | | - Some(leading_field) => { |
245 | | - format!("{value} {leading_field}") |
246 | | - } |
247 | | - None => { |
248 | | - // default to seconds for the units |
249 | | - // `INTERVAL '5' is parsed as '5 seconds' |
250 | | - format!("{value} seconds") |
251 | | - } |
252 | | - } |
| 237 | + // leading_field really means the unit if specified |
| 238 | + // for example, "month" in `INTERVAL '5' month` |
| 239 | + let value = match interval.leading_field.as_ref() { |
| 240 | + Some(leading_field) => format!("{value} {leading_field}"), |
| 241 | + None => value, |
253 | 242 | }; |
254 | 243 |
|
255 | | - let val = parse_interval_month_day_nano(&value)?; |
| 244 | + let config = IntervalParseConfig::new(IntervalUnit::Second); |
| 245 | + let val = parse_interval_month_day_nano_config(&value, config)?; |
256 | 246 | Ok(lit(ScalarValue::IntervalMonthDayNano(Some(val)))) |
257 | 247 | } |
258 | 248 | } |
@@ -292,35 +282,6 @@ fn interval_literal(interval_value: SQLExpr, negative: bool) -> Result<String> { |
292 | 282 | } |
293 | 283 | } |
294 | 284 |
|
295 | | -// TODO make interval parsing better in arrow-rs / expose `IntervalType` |
296 | | -fn has_units(val: &str) -> bool { |
297 | | - let val = val.to_lowercase(); |
298 | | - val.ends_with("century") |
299 | | - || val.ends_with("centuries") |
300 | | - || val.ends_with("decade") |
301 | | - || val.ends_with("decades") |
302 | | - || val.ends_with("year") |
303 | | - || val.ends_with("years") |
304 | | - || val.ends_with("month") |
305 | | - || val.ends_with("months") |
306 | | - || val.ends_with("week") |
307 | | - || val.ends_with("weeks") |
308 | | - || val.ends_with("day") |
309 | | - || val.ends_with("days") |
310 | | - || val.ends_with("hour") |
311 | | - || val.ends_with("hours") |
312 | | - || val.ends_with("minute") |
313 | | - || val.ends_with("minutes") |
314 | | - || val.ends_with("second") |
315 | | - || val.ends_with("seconds") |
316 | | - || val.ends_with("millisecond") |
317 | | - || val.ends_with("milliseconds") |
318 | | - || val.ends_with("microsecond") |
319 | | - || val.ends_with("microseconds") |
320 | | - || val.ends_with("nanosecond") |
321 | | - || val.ends_with("nanoseconds") |
322 | | -} |
323 | | - |
324 | 285 | /// Try to decode bytes from hex literal string. |
325 | 286 | /// |
326 | 287 | /// None will be returned if the input literal is hex-invalid. |
|
0 commit comments