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

Subtraction operation implementation #5140

Merged
merged 14 commits into from
Sep 12, 2019
Merged

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 <[email protected]>

Signed-off-by: Sugu Sougoumarane <[email protected]>
- 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 <[email protected]>
Signed-off-by: Rasika Kale <[email protected]>
@rasikakale rasikakale requested a review from sougou as a code owner August 27, 2019 20:03
go/sqltypes/arithmetic.go Outdated Show resolved Hide resolved
go/sqltypes/arithmetic.go Outdated Show resolved Hide resolved
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 <[email protected]>
- Added test for method in arithmetic_test.go to maximize code coverage

Signed-off-by: Rasika Kale <[email protected]>
- Fixed tests in TestAdd() in arithmetic_test.go

Signed-off-by: Rasika Kale <[email protected]>
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.

go/sqltypes/arithmetic.go Show resolved Hide resolved
go/sqltypes/arithmetic.go Show resolved Hide resolved
go/sqltypes/arithmetic.go Outdated Show resolved Hide resolved
go/sqltypes/arithmetic.go Show resolved Hide resolved
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 <[email protected]>
Signed-off-by: Rasika Kale <[email protected]>
@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