Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp Subtraction #5411

Closed
Tracked by #3148
berkaysynnada opened this issue Feb 27, 2023 · 1 comment · Fixed by #5603
Closed
Tracked by #3148

Timestamp Subtraction #5411

berkaysynnada opened this issue Feb 27, 2023 · 1 comment · Fixed by #5603
Labels
enhancement New feature or request

Comments

@berkaysynnada
Copy link
Contributor

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

@berkaysynnada berkaysynnada added the enhancement New feature or request label Feb 27, 2023
@metesynnada
Copy link
Contributor

This is also important for supporting queries for interval arithmetics, i.e range calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants