Skip to content

Commit dc07708

Browse files
author
longshan.lu
committed
feat: Enhance interval parsing in SQL planner by dynamically setting parse unit based on interval field, improving accuracy for interval expressions
1 parent 2b0f71d commit dc07708

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

qurious/src/planner/sql.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,17 @@ impl<'a> SqlQueryPlanner<'a> {
11501150
// Important: keep `field` even when `expr` is a BinaryOperator (e.g. `INTERVAL '1' + '2' DAY`).
11511151
let value = self.fold_interval_quantity(expr)?;
11521152
let interval_val = format!("{} {}", value, field);
1153-
let config = IntervalParseConfig::new(IntervalUnit::Second);
1153+
// IMPORTANT: the parse unit must match the interval field being parsed.
1154+
// We store the result as IntervalMonthDayNano, but Arrow's parser still needs the
1155+
// correct base unit to interpret the textual interval accurately.
1156+
let config = IntervalParseConfig::new(match field {
1157+
IntervalFields::Year => IntervalUnit::Year,
1158+
IntervalFields::Month => IntervalUnit::Month,
1159+
IntervalFields::Day => IntervalUnit::Day,
1160+
IntervalFields::Hour => IntervalUnit::Hour,
1161+
IntervalFields::Minute => IntervalUnit::Minute,
1162+
IntervalFields::Second => IntervalUnit::Second,
1163+
});
11541164
let val = parse_interval_month_day_nano_config(&interval_val, config)?;
11551165

11561166
Ok(LogicalExpr::Literal(ScalarValue::IntervalMonthDayNano(Some(val))))

0 commit comments

Comments
 (0)