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(query): add date_diff function #16560

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chagelo
Copy link

@chagelo chagelo commented Oct 2, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

related to #16534

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Oct 2, 2024
@chagelo chagelo marked this pull request as draft October 2, 2024 05:58
@chagelo chagelo marked this pull request as ready for review October 3, 2024 17:57
@sundy-li sundy-li requested a review from TCeason October 8, 2024 04:04
optimized expr : 0_i64
output type : Int64
output domain : {0..=0}
output : 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

select date_diff(year, to_timestamp('2020-02-29 23:59:59.165575'), to_timestamp('2019-02-28 23:59:59.423179'))

expect -1

optimized expr : -3_i64
output type : Int64
output domain : {-3..=-3}
output : -3
Copy link
Collaborator

Choose a reason for hiding this comment

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

I test in snowflake , select datediff(quarter, to_timestamp('2020-02-29 23:59:59.165575'), to_timestamp('2019-02-28 23:59:59.423179')) expect -4

optimized expr : 1_i64
output type : Int64
output domain : {1..=1}
output : 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

select datediff(year, to_timestamp('2023-11-12 09:38:18.165575'), to_timestamp('2025-03-27 21:01:35.423179')) expect 2.

query T
SELECT DATE_DIFF(YEAR, to_date('2012-02-29'), to_date('2013-02-28'))
----
1
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider test select DATE_DIFF(YEAR, TO_TIMESTAMP('2023-12-31 09:38:18.165575'), TO_TIMESTAMP('2024-01-01 21:01:35.423179')) the result should be 1.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also need to add some tests where the sign is negative

@chagelo
Copy link
Author

chagelo commented Oct 8, 2024

Sorry, I got you. But, what's the result of select date_diff(year, to_date('2023-12-31'), to_date('2024-01-01'))?

@TCeason
Copy link
Collaborator

TCeason commented Oct 8, 2024

Sorry, I got you. But, what's the result of select date_diff(year, to_date('2023-12-31'), to_date('2024-01-01'))?

Oh, I just mean add a logic test case:

query T
SELECT DATE_DIFF(YEAR, to_date('2023-12-31'), to_date('2024-01-01'))
----
1

@chagelo
Copy link
Author

chagelo commented Oct 8, 2024

So what should I do is to fix it to be compatible with Snowflake and add more tests?

@TCeason
Copy link
Collaborator

TCeason commented Oct 8, 2024

So what should I do is to fix it to be compatible with Snowflake and add more tests?

Date diff about year just need to evaluate year sub. E.g.

2023-12-31 2024-01-01 just need to calc year sub.

@chagelo
Copy link
Author

chagelo commented Oct 8, 2024 via email

@chagelo chagelo marked this pull request as draft October 8, 2024 15:56
@chagelo chagelo force-pushed the feat-add-date-diff branch 2 times, most recently from e0d0aaa to b9e9566 Compare October 9, 2024 06:24
* support date and timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants