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(expr): date_trunc, extract, date_part with implicit timezone #10480

Merged
merged 4 commits into from Jul 6, 2023

Conversation

xiangjinwu
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Support the following:

  • date_trunc(field_string, input_timestamptz) = timestamptz
  • extract(field_string, input_timestamptz) = decimal
  • date_part(field_string, input_timestamptz) = double precision

by rewriting into the following:

  • date_trunc(field_string, input_timestamptz, zone_string) = timestamptz
  • extract(field_string, input_timestamptz, zone_string) = decimal (not in PostgreSQL)
  • date_part(field_string, input_timestamptz, zone_string) = double precision (not in PostgreSQL)

Related: #10410

Breaking change: Due to the addition of date_trunc(field_string, input_timestamptz), it is chosen as the preferred overload when input is actually date. Old query plans continue working because the choice is recorded in the plan with a cast to timestamp. New plans will cast to timestamptz. Some old sqls (maybe saved as views) may fail to bind and requires type adjustments.

# After this PR, same as PostgreSQL
dev=> select date_trunc('month', date '2023-03-04');
        date_trunc         
---------------------------
 2023-03-01 00:00:00+00:00
(1 row)

# Before this PR
dev=> select date_trunc('month', date '2023-03-04');
        date_trunc         
---------------------------
 2023-03-01 00:00:00
(1 row)

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)

Documentation

  • My PR contains user-facing changes.

Types of user-facing changes

  • SQL commands, functions, and operators

Release note

Support the following:

  • date_trunc(field_string, input_timestamptz) = timestamptz
  • extract(field_string, input_timestamptz) = decimal
  • date_part(field_string, input_timestamptz) = double precision

@github-actions github-actions bot added type/feature user-facing-changes Contains changes that are visible to users breaking-change labels Jun 21, 2023
@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #10480 (c904fcf) into main (d4ffeda) will decrease coverage by 0.02%.
The diff coverage is 22.07%.

@@            Coverage Diff             @@
##             main   #10480      +/-   ##
==========================================
- Coverage   70.14%   70.12%   -0.02%     
==========================================
  Files        1296     1296              
  Lines      221698   221760      +62     
==========================================
+ Hits       155515   155517       +2     
- Misses      66183    66243      +60     
Flag Coverage Δ
rust 70.12% <22.07%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/expr/src/vector_op/extract.rs 78.70% <7.69%> (-11.17%) ⬇️
src/expr/src/vector_op/date_trunc.rs 6.25% <12.50%> (+0.98%) ⬆️
src/frontend/src/expr/session_timezone.rs 70.31% <13.33%> (-7.57%) ⬇️
src/expr/src/vector_op/timestamptz.rs 84.95% <55.55%> (-1.89%) ⬇️
src/common/src/types/timestamptz.rs 70.37% <100.00%> (+2.37%) ⬆️

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

LGTM!

src/expr/src/vector_op/timestamptz.rs Outdated Show resolved Hide resolved
@xiangjinwu xiangjinwu enabled auto-merge July 6, 2023 05:00
@xiangjinwu xiangjinwu added this pull request to the merge queue Jul 6, 2023
Merged via the queue into main with commit 33a97fb Jul 6, 2023
34 of 35 checks passed
@xiangjinwu xiangjinwu deleted the feat-expr-timestamptz-trunc-extract branch July 6, 2023 05:54
@emile-00 emile-00 added the 📖✓ Covered or will be covered in the user docs. label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change type/feature user-facing-changes Contains changes that are visible to users 📖✓ Covered or will be covered in the user docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants