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

feat(cubestore): Introduce support for DATE_ADD #3085

Merged
merged 4 commits into from
Jul 12, 2021

Conversation

ovr
Copy link
Member

@ovr ovr commented Jul 9, 2021

Hello!

Thanks

@ovr ovr force-pushed the cubestore-date-add-date-sub branch 2 times, most recently from 75c0141 to 0d9ffb1 Compare July 11, 2021 13:59
@ovr ovr force-pushed the cubestore-date-add-date-sub branch from 0d9ffb1 to 2a9395f Compare July 11, 2021 16:45
@ovr ovr marked this pull request as ready for review July 11, 2021 16:46
@ovr ovr requested a review from a team as a code owner July 11, 2021 16:46
@ovr ovr requested a review from ilya-biryukov July 11, 2021 16:46
Copy link
Contributor

@ilya-biryukov ilya-biryukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Mostly LG, but let's ensure this covers corner cases

rust/cubestore/src/queryplanner/udfs.rs Outdated Show resolved Hide resolved
rust/cubestore/src/queryplanner/udfs.rs Outdated Show resolved Hide resolved
rust/cubestore/src/queryplanner/udfs.rs Outdated Show resolved Hide resolved
rust/cubestore/src/queryplanner/udfs.rs Outdated Show resolved Hide resolved
}

result_date = result_date.with_year(year).unwrap();
result_date = result_date.with_month(month).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't unwrap, return errors instead.

Copy link
Member Author

@ovr ovr Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option<T> doesnt support map_err and it's not possible to implement impl From to DFErrror (it requires modern rust with try_trait feature), it's why I wrote a small fn helper

fn datetime_safety_unwrap(opt: Option<DateTime<Utc>>) -> Result<DateTime<Utc>, DataFusionError> {
    if opt.is_some() {
        return Ok(opt.unwrap());
    }

    return Err(DataFusionError::Internal(
        "Unable to calculate operation between DateTime and Interval".to_string(),
    ));
}

let r = service
.exec_query(
"SELECT
DATE_ADD(CAST('2021-01-01T00:00:00Z' as TIMESTAMP), INTERVAL '1 second'),\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a few more tests?
At least these corner cases should be covered:

  • Add one day to Jun 30
  • Add one month to Dec
  • Add one day to Feb 28 on a leap year and non-leap year
  • add one year to Feb 29 on a leap year
  • add one minute to 23:59:00
  • add one month to Jan 30
  • add one month to Jan 29 on a non-leap year and a leap year

Is there a way to get negative values in the intervals?
If no, please add assertions.
If yes, please add tests.

@ovr ovr merged commit 071d7b4 into master Jul 12, 2021
@ovr ovr deleted the cubestore-date-add-date-sub branch July 12, 2021 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants