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

coprocessor: RPN function UnaryNot #4808

Merged
merged 4 commits into from Jun 3, 2019
Merged
Changes from 3 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -54,6 +54,21 @@ impl RpnFnLogicalOr {
}
}

#[derive(Debug, Clone, Copy, RpnFunction)]
#[rpn_function(args = 1)]
pub struct RpnFnUnaryNot;

impl RpnFnUnaryNot {
#[inline]
fn call(
_ctx: &mut EvalContext,
_payload: RpnFnCallPayload<'_>,
arg: &Option<i64>,
This conversation was marked as resolved by kennytm

This comment has been minimized.

Copy link
@kennytm

kennytm May 30, 2019

Contributor

TiDB currently is incompatible with MySQL 8 when decimal and floating point numbers is involved. If this function requires an i64 input it is still easy for TiDB to fix the compatibility bug?

MySQL 8:

mysql> select not -0.01, not -0.0, not 0.0, not 0.01;
+-----------+----------+---------+----------+
| not -0.01 | not -0.0 | not 0.0 | not 0.01 |
+-----------+----------+---------+----------+
|         0 |        1 |       1 |        0 |
+-----------+----------+---------+----------+
1 row in set (0.01 sec)

On TiDB:

mysql> select not -0.01, not -0.0, not 0.0, not 0.01;
+-----------+----------+---------+----------+
| not -0.01 | not -0.0 | not 0.0 | not 0.01 |
+-----------+----------+---------+----------+
|         1 |        1 |       1 |        1 |
+-----------+----------+---------+----------+
1 row in set (0.00 sec)

This comment has been minimized.

Copy link
@breeswish

breeswish May 30, 2019

Author Member

To handle this, maybe TiDB can introduce a new function called UnaryNotReal?

) -> Result<Option<i64>> {
Ok(arg.map(|v| (v == 0) as i64))
}
}

#[derive(Clone, Debug, RpnFunction)]
#[rpn_function(args = 1)]
pub struct RpnFnIsNull<T: Evaluable> {
@@ -218,6 +233,24 @@ mod tests {
}
}

#[test]
fn test_unary_not() {
let test_cases = vec![
(Some(0), Some(1)),
(Some(1), Some(0)),
(Some(2), Some(0)),
(Some(-1), Some(0)),
(None, None),
];
for (arg, expect_output) in test_cases {
let output = RpnFnScalarEvaluator::new()
.push_param(arg)
.evaluate(ScalarFuncSig::UnaryNot)
.unwrap();
assert_eq!(output, expect_output);
}
}

#[test]
fn test_is_null() {
let test_cases = vec![
@@ -151,6 +151,7 @@ fn map_pb_sig_to_rpn_func(value: ScalarFuncSig, children: &[Expr]) -> Result<Box
ScalarFuncSig::DecimalIsFalse => Box::new(RpnFnDecimalIsFalse),
ScalarFuncSig::LogicalAnd => Box::new(RpnFnLogicalAnd),
ScalarFuncSig::LogicalOr => Box::new(RpnFnLogicalOr),
ScalarFuncSig::UnaryNot => Box::new(RpnFnUnaryNot),
ScalarFuncSig::PlusInt => map_int_sig(value, children, plus_mapper)?,
ScalarFuncSig::PlusReal => Box::new(RpnFnArithmetic::<RealPlus>::new()),
ScalarFuncSig::PlusDecimal => Box::new(RpnFnArithmetic::<DecimalPlus>::new()),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.