Skip to content

Subtraction operation implementation#5140

Merged
sougou merged 14 commits intovitessio:masterfrom
planetscale:rk-newminus
Sep 12, 2019
Merged

Subtraction operation implementation#5140
sougou merged 14 commits intovitessio:masterfrom
planetscale:rk-newminus

Conversation

@rasikakale
Copy link

@rasikakale rasikakale commented Aug 27, 2019

partial fix for #5098

  • Implemented Subtract() to return a Value or an error. The output of this function represents the same output when two values are subtracted from each other in MySQL. The following functions were added to achieve this:
    • subtractNumericWithError() - operates the same way as addNumericWithError(), and returns a numeric or an error

    • intMinusIntWithError() - operates the same way as intPlusIntWithError(), except both values are subtracted.

      • Checks whether the first value is greater than 0 or less than or equal to the minimum Int64 value, and whether the second value is greater than the maximum Int64 value or greater than 0, and vice versa. Returns a BIGINT error if value is out or range.
    • uintMinusIntWithError() - Checks whether first value if less than second value. If so, then returns a BIGINT UNSIGNED error.

    • uintMinusUintWithError() - Returns the difference of two uint64 values as a uint64 value. Returns the uint64 value as a numeric.

    • floatMinusAny() - Returns a numeric float64 value after subtracting a float and non-float value

Rasika Kale added 5 commits August 26, 2019 16:34
Signed-off-by: Rasika Kale <rasika@planetscale.com>

Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
- Added more tests in arithmetic_test.go to fix code coverage
- Added error checking into arithmetic.go
- Implemented function floatMinusAny() for subtraction expression

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
@rasikakale rasikakale requested a review from sougou as a code owner August 27, 2019 20:03
Rasika Kale added 5 commits August 30, 2019 11:22
- Added intMinusUintWithError() in arithmetic.go
- Fixed error checking in arithmetic.go for intMinusIntWithError()

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
- Added test for method in arithmetic_test.go to maximize code coverage

Signed-off-by: Rasika Kale <rasika@planetscale.com>
- Fixed tests in TestAdd() in arithmetic_test.go

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

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

A few more corner cases to handle.

Rasika Kale added 4 commits September 10, 2019 09:51
- checked if v1 < 0 in  intMinusUintWithError()
- checked if v2 is greater that v1 and greater than 0 in uintMinusIntWithError()_
- within uintMinusIntWithError() checked if v2 < 0, then returned uintPlusIntWithError(v1, -v2)
- checked if v2 > v1 in uintMinusUintWithError()
- Added function floatMinusAny() in subtractNumericWithError() to account for float - value expressions

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
@sougou
Copy link
Contributor

sougou commented Sep 12, 2019

Nice work!

@sougou sougou merged commit 0b9bcb8 into vitessio:master Sep 12, 2019
@deepthi deepthi changed the title WIP: Subtraction operation implementation Subtraction operation implementation Sep 12, 2019
@sougou sougou deleted the rk-newminus branch December 14, 2019 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants