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
tidb_query: refactor utility functions of rpn_expr::impl_cast::tests
module
#6060
Conversation
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
fn make_ctx_about_overflow_truncate_should_clip_to_zero( | ||
/// Rust has no overload, so we has `make_ctx_1`, `make_ctx_2`, etc.. | ||
/// Please call one of these functions according to the param list. | ||
fn make_ctx_1( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding structure
struct Ctx1Options {
overflow_as_warning: bool,
truncate_as_warning: bool,
should_clip_to_zero: bool,
}
It is more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in rust, this way is best.
pub struct ConfigFlag {
overflow_as_warning: bool,
truncate_as_warning: bool,
should_clip_to_zero: bool,
in_insert_stmt: bool,
in_select_stmt: bool,
}
impl Default for ConfigFlag {
fn default() -> Self {
ConfigFlag {
overflow_as_warning: false,
truncate_as_warning: false,
should_clip_to_zero: false,
in_insert_stmt: false,
in_select_stmt: false,
}
}
}
impl From<ConfigFlag> for EvalConfig {
fn from(c: ConfigFlag) -> Self {
let flag = Flag::empty();
flag |= Flag::OVERFLOW_AS_WARNING * c.overflow_as_warning as u64;
flag |= Flag::OVERFLOW_AS_WARNING * c.truncate_as_warning as u64;
flag |= Flag::OVERFLOW_AS_WARNING * c.should_clip_to_zero as u64;
flag |= Flag::OVERFLOW_AS_WARNING * c.in_insert_stmt as u64;
flag |= Flag::OVERFLOW_AS_WARNING * c.in_select_stmt as u64;
EvalConfig { flag, max_warning_cnt: 1024 }
}
}
#[test]
fn test_1() {
let ctx = EvalContext {
cfg: Arc::new(EvalConfig::from(ConfigFlag {
overflow_as_warning: true,
..ConfigFlag::default()
})),
..EvalContext::default()
};
// test code
}
However, if refactoring all unit tests using this way, the work is not small.
BTW, if in other language that has no ..Xx::default()
, we has only two ways
- One
#[test] fn test_2() { let mut flag: Flag = Flag::empty(); flag |= Flag::OVERFLOW_AS_WARNING; let cfg = Arc::new(EvalConfig::from_flag(flag)); let ctx = EvalContext::new(cfg); // test code }
- Two
fn make_ctx_1(overflow_as_warning: bool) -> EvalContext { let mut flag: Flag = Flag::empty(); flag |= Flag::OVERFLOW_AS_WARNING; let cfg = Arc::new(EvalConfig::from_flag(flag)); EvalContext::new(cfg) } #[test] fn test_3() { let ctx = make_ctx_1(true); // test code }
The second way is better, because the first one will repeat the same code in many unit test functions, it is very easy to make mistake if repeating code.
However, how to name the make_ctx_x
? If in Java, we can call all of them make_ctx
. And in rust, we can simulate overload
using make_ctx_1
, make_ctx_2
, etc., the caller need to call it according to funcName + paramList
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For languages that support named parameters, I think using named parameters is the best. The solution I posted here is a simulation for the named parameter.
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
make_ctx
and make_ret_field_type
in rpn_expr::impl_cast::tests to named param style
PTAL @lonng |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
make_ctx
and make_ret_field_type
in rpn_expr::impl_cast::tests to named param stylerpn_expr::impl_cast::tests
module
/tests |
@@ -1275,7 +1271,11 @@ mod tests { | |||
(i64::MAX, i64::MAX as u64, false), | |||
]; | |||
for (input, expect, in_union) in cs { | |||
let rtf = make_ret_field_type_1(true); | |||
let rtf = RetFieldTypeConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rtf
-> rft
?
Rest LGTM |
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this PR. However I would like to see some utilities extract to somewhere else (in future) since they are not bounded to the cast module.
/merge |
/run-all-tests |
…` module (tikv#6060) Signed-off-by: H-ZeX <hzx20112012@gmail.com>
commit 9fcc672 Merge: 43ecfab 55909d0 Author: 魂锁典狱长 <t888y@qq.com> Date: Tue Dec 3 18:07:02 2019 +0800 Merge branch 'master' into month_name Signed-off-by: tw <t888y@qq.com> commit 55909d0 Author: Wenxuan <breezewish@pingcap.com> Date: Tue Dec 3 15:02:42 2019 +0800 Switch to use static metrics for Coprocessor Runner (tikv#6134) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 1674fd0 Author: Nick Cameron <nrc@ncameron.org> Date: Tue Dec 3 18:04:56 2019 +1300 Refactoring txn: restrict the API of storage (tikv#5964) Signed-off-by: Nick Cameron <nrc@ncameron.org> commit 43ecfab Merge: c05eb8a 95ad796 Author: tw <t888y@qq.com> Date: Mon Dec 2 16:26:47 2019 +0800 Merge remote-tracking branch 'upstream/master' into month_name # Conflicts: # components/tidb_query/src/rpn_expr/impl_time.rs commit c05eb8a Author: tw <t888y@qq.com> Date: Mon Dec 2 16:21:21 2019 +0800 add MonthExtension Signed-off-by: tw <t888y@qq.com> commit 95ad796 Author: Lei Zhao <zlwgx1023@gmail.com> Date: Mon Dec 2 14:06:54 2019 +0800 deadlock: only observe valid region (tikv#6125) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> commit dfd6a80 Author: Wenxuan <breezewish@pingcap.com> Date: Mon Dec 2 13:53:29 2019 +0800 Support StartTs in Coprocessor.Request (tikv#6127) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 8e9aa21 Author: Iosmanthus Teng <MyOsmanthusTree@gmail.com> Date: Mon Dec 2 13:27:19 2019 +0800 Copr: add cast_*_as_time (tikv#6057) Signed-off-by: Iosmanthus Teng <myosmanthustree@gmail.com> commit 983c626 Author: Wenxuan <breezewish@pingcap.com> Date: Mon Dec 2 11:22:02 2019 +0800 Always collect execution summary for BatchExecutor (tikv#6112) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 9b3509f Author: Zhongyang Wu <zhongyang.wu@outlook.com> Date: Sun Dec 1 22:05:23 2019 -0500 copr: vectorize is_ipv4_mapped (tikv#6025) Signed-off-by: zhongyang.wu <zhongyang.wu@outlook.com> commit b23731b Author: Zhu Zihao <all_but_last@163.com> Date: Mon Dec 2 10:33:53 2019 +0800 copr: Vectorize `uncompressed_length`. (tikv#6109) Signed-off-by: Zhu Zihao <all_but_last@163.com> commit 15f9af9 Author: Qinxuan Chen <koushiro.cqx@gmail.com> Date: Sat Nov 30 12:14:23 2019 +0800 copr: vectorize md5 (tikv#6091) Signed-off-by: koushiro <koushiro.cqx@gmail.com> commit e862ba3 Author: FateTHarlaown <623239185@qq.com> Date: Sat Nov 30 11:49:23 2019 +0800 copr: Add vectorize day_of_month (tikv#6103) Signed-off-by: FateTHarlaown <623239185@qq.com> commit 5e279c5 Author: Weizhen Wang <hawking.rei@gmail.com> Date: Sat Nov 30 09:50:54 2019 +0800 copr/mysql/json: support json_depth (tikv#5924) Signed-off-by: Wangweizhen <hawking.rei@gmail.com> commit 2138acd Author: Ana Hobden <operator@hoverbear.org> Date: Fri Nov 29 10:24:52 2019 -0800 Simplify the Dockerfile (tikv#6081) Signed-off-by: Ana Hobden <operator@hoverbear.org> commit dd63b75 Merge: 694061c 30649d7 Author: tw <t888y@qq.com> Date: Fri Nov 29 20:56:08 2019 +0800 Merge branch 'month_name' of https://github.com/tw666/tikv into month_name commit 694061c Author: tw <t888y@qq.com> Date: Fri Nov 29 20:55:32 2019 +0800 remove format Signed-off-by: tw <t888y@qq.com> commit cd87848 Author: 庄天翼 <zty0826@gmail.com> Date: Fri Nov 29 13:01:24 2019 +0800 copr: add more assert in compare_in test (tikv#6098) Signed-off-by: TennyZhuang <zty0826@gmail.com> commit 30649d7 Author: 魂锁典狱长 <t888y@qq.com> Date: Fri Nov 29 12:00:10 2019 +0800 Update components/tidb_query/src/rpn_expr/impl_time.rs Co-Authored-By: disksing <i@disksing.com> commit f6869af Author: pingcap-github-bot <sre-bot@pingcap.com> Date: Fri Nov 29 11:06:25 2019 +0800 rust-rocksdb: Fix clippy warnings etc. (tikv#6080) Signed-off-by: sre-bot <sre-bot@pingcap.com> commit 157f672 Author: TY <t1997y@vip.qq.com> Date: Fri Nov 29 10:52:25 2019 +0800 copr: Add vectorize FieldInt/FieldReal/FieldString (tikv#6086) Signed-off-by: taoyu <t1997y@vip.qq.com> commit b10c87a Merge: 276d543 35b5038 Author: tw <t888y@qq.com> Date: Fri Nov 29 10:23:48 2019 +0800 Merge branch 'month_name' of https://github.com/tw666/tikv into month_name commit 276d543 Author: tw <t888y@qq.com> Date: Fri Nov 29 10:22:59 2019 +0800 case for SqlMode::NO_ZERO_DATE Signed-off-by: tw <t888y@qq.com> commit 48c17fb Author: niedhui <niedhui@gmail.com> Date: Fri Nov 29 10:08:23 2019 +0800 fix cargo build (tikv#6100) Signed-off-by: niedhui <niedhui@gmail.com> commit 926a227 Author: Nick Cameron <nrc@ncameron.org> Date: Fri Nov 29 14:43:40 2019 +1300 Fix a failing test due to recursion limit (tikv#6102) Signed-off-by: Nick Cameron <nrc@ncameron.org> commit e9e578f Author: Wenxuan <breezewish@pingcap.com> Date: Thu Nov 28 20:02:52 2019 +0800 Fix the bug that IN() optimization is not taking effect (tikv#6093) Signed-off-by: Breezewish <breezewish@pingcap.com> commit bdc0ccf Author: Wenxuan <breezewish@pingcap.com> Date: Thu Nov 28 19:19:24 2019 +0800 Support skip cached Coprocessor request (tikv#6076) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 0609915 Author: Huang Zexin <hzx20112012@gmail.com> Date: Thu Nov 28 17:00:54 2019 +0800 tidb_query: refactor utility functions of `rpn_expr::impl_cast::tests` module (tikv#6060) Signed-off-by: H-ZeX <hzx20112012@gmail.com> commit 61af99d Author: Shenghui Wu <793703860@qq.com> Date: Thu Nov 28 16:19:55 2019 +0800 expression: add missing scalar function signature (tikv#6082) Signed-off-by: wshwsh12 <793703860@qq.com> commit dc758d6 Author: 3pointer <luancheng@pingcap.com> Date: Thu Nov 28 16:07:54 2019 +0800 backup: put startKey into backup_file_name to make it unique (tikv#6071) Signed-off-by: luancheng <luancheng@pingcap.com> commit d03a6a7 Author: Weizhen Wang <hawking.rei@gmail.com> Date: Thu Nov 28 15:14:55 2019 +0800 copr/mysql/json: support json_keys (tikv#5931) Signed-off-by: Wangweizhen <hawking.rei@gmail.com> commit 35b5038 Merge: 597cc15 982f144 Author: Nick Cameron <nrc@ncameron.org> Date: Thu Nov 28 19:06:12 2019 +1300 Merge branch 'master' into month_name commit 597cc15 Author: tw <t888y@qq.com> Date: Thu Nov 28 12:33:13 2019 +0800 copr: Add vectorize month_name Signed-off-by: tw <t888y@qq.com> Signed-off-by: tw <t888y@qq.com>
commit 9fcc672 Merge: 43ecfab 55909d0 Author: 魂锁典狱长 <t888y@qq.com> Date: Tue Dec 3 18:07:02 2019 +0800 Merge branch 'master' into month_name Signed-off-by: tw <t888y@qq.com> commit 55909d0 Author: Wenxuan <breezewish@pingcap.com> Date: Tue Dec 3 15:02:42 2019 +0800 Switch to use static metrics for Coprocessor Runner (tikv#6134) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 1674fd0 Author: Nick Cameron <nrc@ncameron.org> Date: Tue Dec 3 18:04:56 2019 +1300 Refactoring txn: restrict the API of storage (tikv#5964) Signed-off-by: Nick Cameron <nrc@ncameron.org> commit 43ecfab Merge: c05eb8a 95ad796 Author: tw <t888y@qq.com> Date: Mon Dec 2 16:26:47 2019 +0800 Merge remote-tracking branch 'upstream/master' into month_name # Conflicts: # components/tidb_query/src/rpn_expr/impl_time.rs commit c05eb8a Author: tw <t888y@qq.com> Date: Mon Dec 2 16:21:21 2019 +0800 add MonthExtension Signed-off-by: tw <t888y@qq.com> commit 95ad796 Author: Lei Zhao <zlwgx1023@gmail.com> Date: Mon Dec 2 14:06:54 2019 +0800 deadlock: only observe valid region (tikv#6125) Signed-off-by: youjiali1995 <zlwgx1023@gmail.com> commit dfd6a80 Author: Wenxuan <breezewish@pingcap.com> Date: Mon Dec 2 13:53:29 2019 +0800 Support StartTs in Coprocessor.Request (tikv#6127) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 8e9aa21 Author: Iosmanthus Teng <MyOsmanthusTree@gmail.com> Date: Mon Dec 2 13:27:19 2019 +0800 Copr: add cast_*_as_time (tikv#6057) Signed-off-by: Iosmanthus Teng <myosmanthustree@gmail.com> commit 983c626 Author: Wenxuan <breezewish@pingcap.com> Date: Mon Dec 2 11:22:02 2019 +0800 Always collect execution summary for BatchExecutor (tikv#6112) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 9b3509f Author: Zhongyang Wu <zhongyang.wu@outlook.com> Date: Sun Dec 1 22:05:23 2019 -0500 copr: vectorize is_ipv4_mapped (tikv#6025) Signed-off-by: zhongyang.wu <zhongyang.wu@outlook.com> commit b23731b Author: Zhu Zihao <all_but_last@163.com> Date: Mon Dec 2 10:33:53 2019 +0800 copr: Vectorize `uncompressed_length`. (tikv#6109) Signed-off-by: Zhu Zihao <all_but_last@163.com> commit 15f9af9 Author: Qinxuan Chen <koushiro.cqx@gmail.com> Date: Sat Nov 30 12:14:23 2019 +0800 copr: vectorize md5 (tikv#6091) Signed-off-by: koushiro <koushiro.cqx@gmail.com> commit e862ba3 Author: FateTHarlaown <623239185@qq.com> Date: Sat Nov 30 11:49:23 2019 +0800 copr: Add vectorize day_of_month (tikv#6103) Signed-off-by: FateTHarlaown <623239185@qq.com> commit 5e279c5 Author: Weizhen Wang <hawking.rei@gmail.com> Date: Sat Nov 30 09:50:54 2019 +0800 copr/mysql/json: support json_depth (tikv#5924) Signed-off-by: Wangweizhen <hawking.rei@gmail.com> commit 2138acd Author: Ana Hobden <operator@hoverbear.org> Date: Fri Nov 29 10:24:52 2019 -0800 Simplify the Dockerfile (tikv#6081) Signed-off-by: Ana Hobden <operator@hoverbear.org> commit dd63b75 Merge: 694061c 30649d7 Author: tw <t888y@qq.com> Date: Fri Nov 29 20:56:08 2019 +0800 Merge branch 'month_name' of https://github.com/tw666/tikv into month_name commit 694061c Author: tw <t888y@qq.com> Date: Fri Nov 29 20:55:32 2019 +0800 remove format Signed-off-by: tw <t888y@qq.com> commit cd87848 Author: 庄天翼 <zty0826@gmail.com> Date: Fri Nov 29 13:01:24 2019 +0800 copr: add more assert in compare_in test (tikv#6098) Signed-off-by: TennyZhuang <zty0826@gmail.com> commit 30649d7 Author: 魂锁典狱长 <t888y@qq.com> Date: Fri Nov 29 12:00:10 2019 +0800 Update components/tidb_query/src/rpn_expr/impl_time.rs Co-Authored-By: disksing <i@disksing.com> commit f6869af Author: pingcap-github-bot <sre-bot@pingcap.com> Date: Fri Nov 29 11:06:25 2019 +0800 rust-rocksdb: Fix clippy warnings etc. (tikv#6080) Signed-off-by: sre-bot <sre-bot@pingcap.com> commit 157f672 Author: TY <t1997y@vip.qq.com> Date: Fri Nov 29 10:52:25 2019 +0800 copr: Add vectorize FieldInt/FieldReal/FieldString (tikv#6086) Signed-off-by: taoyu <t1997y@vip.qq.com> commit b10c87a Merge: 276d543 35b5038 Author: tw <t888y@qq.com> Date: Fri Nov 29 10:23:48 2019 +0800 Merge branch 'month_name' of https://github.com/tw666/tikv into month_name commit 276d543 Author: tw <t888y@qq.com> Date: Fri Nov 29 10:22:59 2019 +0800 case for SqlMode::NO_ZERO_DATE Signed-off-by: tw <t888y@qq.com> commit 48c17fb Author: niedhui <niedhui@gmail.com> Date: Fri Nov 29 10:08:23 2019 +0800 fix cargo build (tikv#6100) Signed-off-by: niedhui <niedhui@gmail.com> commit 926a227 Author: Nick Cameron <nrc@ncameron.org> Date: Fri Nov 29 14:43:40 2019 +1300 Fix a failing test due to recursion limit (tikv#6102) Signed-off-by: Nick Cameron <nrc@ncameron.org> commit e9e578f Author: Wenxuan <breezewish@pingcap.com> Date: Thu Nov 28 20:02:52 2019 +0800 Fix the bug that IN() optimization is not taking effect (tikv#6093) Signed-off-by: Breezewish <breezewish@pingcap.com> commit bdc0ccf Author: Wenxuan <breezewish@pingcap.com> Date: Thu Nov 28 19:19:24 2019 +0800 Support skip cached Coprocessor request (tikv#6076) Signed-off-by: Breezewish <breezewish@pingcap.com> commit 0609915 Author: Huang Zexin <hzx20112012@gmail.com> Date: Thu Nov 28 17:00:54 2019 +0800 tidb_query: refactor utility functions of `rpn_expr::impl_cast::tests` module (tikv#6060) Signed-off-by: H-ZeX <hzx20112012@gmail.com> commit 61af99d Author: Shenghui Wu <793703860@qq.com> Date: Thu Nov 28 16:19:55 2019 +0800 expression: add missing scalar function signature (tikv#6082) Signed-off-by: wshwsh12 <793703860@qq.com> commit dc758d6 Author: 3pointer <luancheng@pingcap.com> Date: Thu Nov 28 16:07:54 2019 +0800 backup: put startKey into backup_file_name to make it unique (tikv#6071) Signed-off-by: luancheng <luancheng@pingcap.com> commit d03a6a7 Author: Weizhen Wang <hawking.rei@gmail.com> Date: Thu Nov 28 15:14:55 2019 +0800 copr/mysql/json: support json_keys (tikv#5931) Signed-off-by: Wangweizhen <hawking.rei@gmail.com> commit 35b5038 Merge: 597cc15 982f144 Author: Nick Cameron <nrc@ncameron.org> Date: Thu Nov 28 19:06:12 2019 +1300 Merge branch 'master' into month_name commit 597cc15 Author: tw <t888y@qq.com> Date: Thu Nov 28 12:33:13 2019 +0800 copr: Add vectorize month_name Signed-off-by: tw <t888y@qq.com> Signed-off-by: tw <t888y@qq.com>
…` module (tikv#6060) Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX hzx20112012@gmail.com
What have you changed?
The origin ways to
make_ctx
andmake_ret_field_type
inrpn_expr::impl_cast::tests
are not grace. According to @breeswish 's suggestion, I change them to other ways which are like named parameters.What is the type of the changes?
How is the PR tested?
Does this PR affect documentation (docs) or should it be mentioned in the release notes?
Does this PR affect
tidb-ansible
?