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

Fix behaviour of DATEDIFF() and DATEDIFF_BIG() functions for week and quarter dateparts #3364

Merged

Conversation

Anikait143
Copy link
Contributor

Description

1. Issues

  • DATEDIFF() and DATEDIFF_BIG() functions return incorrect results when using 'week' and 'quarter' as datepart unit.
  • DATEDIFF_BIG() function gives wrong error message in case of overflow.

2. Changes made to fix the issues

  • Fix calculation logic for considering a week if a Saturday-Sunday boundaries crossed.
  • Fix calculation logic for considering a quarter if a quarter boundary crossed.
    1. March-April
    2. June-July
    3. September-October
    4. December-January
  • Fix error message for DATEDIFF_BIG() function in case of overflow.
# Input
1> declare @runForDate datetime = '01/22/2012';
2> declare @evaluationDate datetime = DATEADD(DAY,-1,@runForDate);
3> select DATEDIFF(wk,7,@evaluationDate)
4> go
# previous output (wrong output)               
datediff   
-----------
       5846
# current output (correct output)
datediff   
-----------
       5845                                                                                                                                                                                                                                                      

(1 rows affected)
# previous output (wrong output)
1> select DATEDIFF(quarter, '1999-12-31', '2000-01-01') AS Quarters
2> go
Quarters   
-----------
          0  
# current output (correct output)
1> select DATEDIFF(quarter, '1999-12-31', '2000-01-01') AS Quarters
2> go
Quarters   
-----------
          1
  • Added Test Cases for these issues

cherry-picked: #3357
Task: BABEL- 5461, BABEL-5503
Authored-by: Anikait Agrawal [email protected]
Signed-off-by: Anikait Agrawal [email protected]

Test Scenarios Covered

  • Use case based - YES

  • Boundary conditions - YES

  • Arbitrary inputs - YES

  • Negative test cases - YES

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Memory tests -

  • Client tests -

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@Anikait143 Anikait143 requested a review from rohit01010 January 6, 2025 19:34
@coveralls
Copy link
Collaborator

coveralls commented Jan 6, 2025

Pull Request Test Coverage Report for Build 12639642907

Details

  • 43 of 43 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 73.817%

Totals Coverage Status
Change from base Build 12635754607: 0.01%
Covered Lines: 43202
Relevant Lines: 58526

💛 - Coveralls

Copy link
Contributor

@jsudrik jsudrik left a comment

Choose a reason for hiding this comment

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

Approved.

@jsudrik jsudrik merged commit 1c03544 into babelfish-for-postgresql:BABEL_3_X_DEV Jan 7, 2025
43 checks passed
@Anikait143 Anikait143 deleted the babel-5461-3x branch January 7, 2025 05: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.

4 participants