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

refactor(expr): decouple macro gen_binary_expr_atm from temporal operator signatures #1985

Merged
merged 4 commits into from
Apr 20, 2022

Conversation

xiangjinwu
Copy link
Contributor

@xiangjinwu xiangjinwu commented Apr 20, 2022

What's changed and what's your intention?

The macro gen_binary_expr_atm currently list certain combinations of temporal types, e.g. timestamp_timestamp_f, timestamp_interval_f. This makes it harder to add more temporal operators as their signatures are not that regular compared to numbers. It makes less sense to reuse them across add/sub/mul/div. For details, check the pg operator table below.

This PR allows gen_binary_expr_atm to pass thru a list to gen_atm_impl directly, so that different operators (add/sub/mul/div) can add their own implementations without touching the definition of gen_binary_expr_atm any more.

     lhs     | oprname |     rhs     | ?column? |     ret     |         oprcode         
-------------+---------+-------------+----------+-------------+-------------------------
 float8      | *       | interval    | =        | interval    | mul_d_interval
 interval    | *       | float8      | =        | interval    | interval_mul
 date        | +       | int4        | =        | date        | date_pli
 int4        | +       | date        | =        | date        | integer_pl_date
 interval    | +       | interval    | =        | interval    | interval_pl
 interval    | +       | time        | =        | time        | interval_pl_time
 time        | +       | interval    | =        | time        | time_pl_interval
 date        | +       | interval    | =        | timestamp   | date_pl_interval
 date        | +       | time        | =        | timestamp   | datetime_pl
 interval    | +       | date        | =        | timestamp   | interval_pl_date
 interval    | +       | timestamp   | =        | timestamp   | interval_pl_timestamp
 time        | +       | date        | =        | timestamp   | timedate_pl
 timestamp   | +       | interval    | =        | timestamp   | timestamp_pl_interval
 interval    | +       | timestamptz | =        | timestamptz | interval_pl_timestamptz
 timestamptz | +       | interval    | =        | timestamptz | timestamptz_pl_interval
 date        | -       | int4        | =        | date        | date_mii
 date        | -       | date        | =        | int4        | date_mi
 interval    | -       | interval    | =        | interval    | interval_mi
 time        | -       | time        | =        | interval    | time_mi_time
 timestamp   | -       | timestamp   | =        | interval    | timestamp_mi
 timestamptz | -       | timestamptz | =        | interval    | timestamptz_mi
 time        | -       | interval    | =        | time        | time_mi_interval
 date        | -       | interval    | =        | timestamp   | date_mi_interval
 timestamp   | -       | interval    | =        | timestamp   | timestamp_mi_interval
 timestamptz | -       | interval    | =        | timestamptz | timestamptz_mi_interval
 interval    | /       | float8      | =        | interval    | interval_div
(26 rows)

Query:

with min_types as (
    select * from pg_type
    where typname in (
        'bool', 'int2', 'int4', 'int8', 'float4', 'float8', 'numeric',
        'text', 'date', 'time', 'timestamp', 'timestamptz', 'interval'
    )
) select
    type_l.typname as lhs,
    oprname,
    type_r.typname as rhs,
    '=',
    type_o.typname as ret,
    oprcode
from pg_operator
    join min_types as type_l on pg_operator.oprleft = type_l.oid
    join min_types as type_r on pg_operator.oprright = type_r.oid
    join min_types as type_o on pg_operator.oprresult = type_o.oid
where oprname in ('+', '-', '*', '/')
and (
    type_l.typname in ('date', 'timestamp', 'timestamptz', 'time', 'interval')
    or type_r.typname in ('date', 'timestamp', 'timestamptz', 'time', 'interval')
)
order by oprname, ret, lhs, rhs

Checklist

  • I have written necessary docs and comments
    - [ ] I have added necessary unit tests and integration tests (Refactor does not break existing tests.)

Refer to a related PR or issue link (optional)

@codecov
Copy link

codecov bot commented Apr 20, 2022

Codecov Report

Merging #1985 (ca67afe) into main (06e0f62) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1985      +/-   ##
==========================================
- Coverage   70.95%   70.93%   -0.02%     
==========================================
  Files         625      625              
  Lines       80587    80656      +69     
==========================================
+ Hits        57177    57211      +34     
- Misses      23410    23445      +35     
Flag Coverage Δ
rust 70.93% <ø> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
src/expr/src/expr/expr_binary_nonnull.rs 83.57% <ø> (ø)
src/meta/src/stream/stream_manager.rs 69.82% <0.00%> (-2.68%) ⬇️
.../stream/src/executor/managed_state/flush_status.rs 93.87% <0.00%> (-1.96%) ⬇️
src/meta/src/stream/fragmenter.rs 84.26% <0.00%> (-1.64%) ⬇️
src/meta/src/stream/graph/stream_graph.rs 60.50% <0.00%> (-1.44%) ⬇️
src/connector/src/filesystem/file_common.rs 80.44% <0.00%> (-0.45%) ⬇️
...ecutor/managed_state/top_n/top_n_bottom_n_state.rs 79.25% <0.00%> (-0.28%) ⬇️
...am/src/executor/managed_state/top_n/top_n_state.rs 92.65% <0.00%> (-0.11%) ⬇️
src/meta/src/stream/test_fragmenter.rs 99.62% <0.00%> (ø)
src/meta/src/rpc/service/ddl_service.rs 0.00% <0.00%> (ø)
... and 7 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@xiangjinwu xiangjinwu marked this pull request as ready for review April 20, 2022 09:28
Copy link
Contributor

@skyzh skyzh 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/expr/expr_binary_nonnull.rs Outdated Show resolved Hide resolved
@xiangjinwu xiangjinwu enabled auto-merge (squash) April 20, 2022 09:46
@xiangjinwu xiangjinwu merged commit d12cba8 into main Apr 20, 2022
@xiangjinwu xiangjinwu deleted the rust-expr-atm-macro-decouple-temporal branch April 20, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants