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

[BugFix] fix incorrect result of yearweek #51065

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rohitrs1983
Copy link
Contributor

Why I'm doing:

What I'm doing:

mysql> select yearweek('2023-12-31', 2), yearweek('2024-01-01', 2);
+---------------------------+---------------------------+
| yearweek('2023-12-31', 2) | yearweek('2024-01-01', 2) |
+---------------------------+---------------------------+
| 202353 | 202353 |
+---------------------------+---------------------------+

Fixes #51034

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@github-actions github-actions bot added the 3.3 label Sep 16, 2024
@rohitrs1983 rohitrs1983 reopened this Sep 16, 2024
@rohitrs1983 rohitrs1983 marked this pull request as ready for review September 16, 2024 09:02
@rohitrs1983 rohitrs1983 requested a review from a team as a code owner September 16, 2024 09:02
@dirtysalt
Copy link
Contributor

@rohitrs1983 thanks for fixing this. but I'd like maybe you can add more test cases, to make sure this function's behaviour is consistent with mysql's.

maybe you can refer to this PR's comment: https://github.com/StarRocks/starrocks/pull/47365/files#diff-fc27f5c55e94b69f881f2184c34d746a5495999f61b05c724b58e9259ca132e0R1457-R1463

  • you can run that sql in mysql, to generate outputs of mysql
  • and add these outputs into your test cases.

@dirtysalt
Copy link
Contributor

@rohitrs1983 you can use following mysql statement to generate output for your test cases

create temporary table D(day int);
create temporary table Y(delta int);
create temporary table M(mode int);

insert into D values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
insert into Y values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(36),(37),(38),(39),(40);
insert into M values (0),(1),(2),(3),(4),(5),(6),(7);


    with T as (
  select
   date_add(date_add('1900-01-01', interval Y.delta year), interval D.day day) as start_day,
   date_sub(date_add('1900-12-31', interval Y.delta year ), interval D.day day) as end_day,
   date_add(date_add('2000-01-01', interval Y.delta year), interval D.day day) as start_day2,
   date_sub(date_add('2000-12-31', interval Y.delta year), interval D.day day) as end_day2,
   M.mode
  from D join Y join M
 )
 select mode, start_day, yearweek(start_day, mode), end_day, yearweek(end_day, mode) ,
   start_day2, yearweek(start_day2, mode), end_day2, yearweek(end_day2, mode) from T;

@rohitrs1983
Copy link
Contributor Author

rohitrs1983 commented Sep 20, 2024

@rohitrs1983 you can use following mysql statement to generate output for your test cases

create temporary table D(day int);
create temporary table Y(delta int);
create temporary table M(mode int);

insert into D values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
insert into Y values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(36),(37),(38),(39),(40);
insert into M values (0),(1),(2),(3),(4),(5),(6),(7);


    with T as (
  select
   date_add(date_add('1900-01-01', interval Y.delta year), interval D.day day) as start_day,
   date_sub(date_add('1900-12-31', interval Y.delta year ), interval D.day day) as end_day,
   date_add(date_add('2000-01-01', interval Y.delta year), interval D.day day) as start_day2,
   date_sub(date_add('2000-12-31', interval Y.delta year), interval D.day day) as end_day2,
   M.mode
  from D join Y join M
 )
 select mode, start_day, yearweek(start_day, mode), end_day, yearweek(end_day, mode) ,
   start_day2, yearweek(start_day2, mode), end_day2, yearweek(end_day2, mode) from T;

@dirtysalt thanks for the comments. have added additional test cases. executed the above test on mysql and compared against SR output.

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

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

Successfully merging this pull request may close these issues.

yearweek function does not function right
2 participants