Skip to content

Timestamp Subtraction #5411

@berkaysynnada

Description

@berkaysynnada

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
The timestamp variants (TimestampSecond, TimestampMillisecond ...) in ScalarValue cannot be subtracted from the same timestamp variant. I think we can subtract the timestamp within each variant and get some interval data variants (IntervalYearMonth, IntervalDayTime).

Describe the solution you'd like
There is a function in scalar.rs:

fn do_date_math<D>(prior: D, scalar: &ScalarValue, sign: i32) -> Result<D>
where
    D: Datelike + Add<Duration, Output = D>,
{
    Ok(match scalar {
        ScalarValue::IntervalDayTime(Some(i)) => add_day_time(prior, *i, sign),
        ScalarValue::IntervalYearMonth(Some(i)) => shift_months(prior, *i * sign),
        ScalarValue::IntervalMonthDayNano(Some(i)) => add_m_d_nano(prior, *i, sign),
        other => Err(DataFusionError::Execution(format!(
            "DateIntervalExpr does not support non-interval type {other:?}"
        )))?,
    })
}

This function can be extended to handle the subtraction of timestamps and can return an interval variant.

Describe alternatives you've considered
Before entering do_date_math function, these cases can be handled with an alternative function in impl_op macro.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions