Skip to content

Addition expression implementation #5072

Merged
sougou merged 16 commits intovitessio:masterfrom
planetscale:rk-add-expression
Aug 26, 2019
Merged

Addition expression implementation #5072
sougou merged 16 commits intovitessio:masterfrom
planetscale:rk-add-expression

Conversation

@rasikakale
Copy link
Copy Markdown

  • Changed NullSafeAdd() to only return a value, instead of returning a value or an error. To achieve, the following functions were changed:

    • addNumeric() - returns only a numeric, instead of returning a numeric or error
    • castFromNumeric() - returns only a Value, instead of returning a Value or an error
    • uintPlusInt() - returns only a numeric, instead of returning a numeric or an error
  • Implemented Addition() to return either Value or error. The output in this function presents the same output when two values are inputted into MySQL. The following functions were added to achieve this:

    • addNumericWithError() - operates the same way as addNumeric() except it returns a numeric or an error

    • intPlusIntWithError() - operates the same way as intPlusInt() except it returns a numeric or an error. A BIGINT error is returned if the sum returns a float

    • uintPlusIntWithError() - returns a numeric or an error.

      • Checks whether the first value is greater than or equal to the max value for int64 or uint64 and whether the second value is greater than 0, and vice versa. Returns a BIGINT or BIGINT UNSIGNED error accordingly.
    • uintPlusUintWithError() - operates the same way as uintPlusUint(), except it returns a numeric or a BIGINT UNSIGNED error

Rasika Kale added 4 commits July 29, 2019 15:26
… error

Changed tests TestAdd and TestCastFromNumeric_in arithmetic_test.go to return value output instead of error

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
…lar to mySQL

- Added possible tests for Addition function within arithmetic_test.go

Signed-off-by: Rasika Kale <rasika@planetscale.com>
- In the process of implenting subtraction and multiplication function (marked within comments)

Signed-off-by: Rasika Kale <rasika@planetscale.com>
@rasikakale rasikakale requested a review from sougou as a code owner August 9, 2019 21:55
@rasikakale rasikakale changed the title Addition expression implementation WIP: Addition expression implementation Aug 9, 2019
@morgo morgo self-requested a review August 9, 2019 21:59
@sougou
Copy link
Copy Markdown
Contributor

sougou commented Aug 13, 2019

Need to fix the build.

morgo
morgo previously requested changes Aug 13, 2019
Copy link
Copy Markdown
Contributor

@morgo morgo left a comment

Choose a reason for hiding this comment

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

Some initial feedback. I mainly came to look at the testcases, which make sense to me (but some are commented out). Please fix/remove commented out code and I'll take another look :-)

Rasika Kale added 3 commits August 13, 2019 13:09
- Deleted unnecessary comments
- Fixed whitespace

Signed-off-by: Rasika Kale <rasika@planetscale.com>
- Made rk-add-expression only for addition function

Signed-off-by: Rasika Kale <rasika@planetscale.com>
…e, rather than value or error

Signed-off-by: Rasika Kale <rasika@planetscale.com>
Copy link
Copy Markdown
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.

Nice work. I've nitpicked a few things.

Rasika Kale added 5 commits August 20, 2019 15:26
Signed-off-by: Rasika Kale <rasika@planetscale.com>
- Fixed TestOrderedAggregateMergeFail in  ordered_aggregate_test.go to return proper value for expressions such as "b + 1"

Signed-off-by: Rasika Kale <rasika@planetscale.com>
… avoid runtime errors

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

systay commented Aug 23, 2019

So, if I understand this correctly, this change set adds code for a few binary expressions to be used in the engine, but does not change the planner to actually produce these expressions, right? or am I missing something?

Signed-off-by: Rasika Kale <rasika@planetscale.com>
@rasikakale rasikakale changed the title WIP: Addition expression implementation Addition expression implementation Aug 23, 2019
Rasika Kale added 2 commits August 23, 2019 14:42
Signed-off-by: Rasika Kale <rasika@planetscale.com>
Signed-off-by: Rasika Kale <rasika@planetscale.com>
@morgo morgo self-requested a review August 25, 2019 16:33
Copy link
Copy Markdown
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.

Looking much better now. Few more comments.

Since you've added Subtract and Multiply to this PR, you'll need to write tests for those before we can merge this.

Also, we need to ensure 100% code coverage. I still see some code paths not being covered.

- Deleted Subtract() and Multiply() and other functions not related to Add()

Signed-off-by: Rasika Kale <rasika@planetscale.com>
@sougou sougou dismissed morgo’s stale review August 26, 2019 19:45

explained in comments

@sougou sougou merged commit 3355459 into vitessio:master Aug 26, 2019
return numeric{}, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "cannot add a negative number to an unsigned integer: %d, %d", v1, v2)
func intPlusIntWithError(v1, v2 int64) (numeric, error) {
result := v1 + v2
if (result > v1) != (v2 > 0) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

as a general practice, we should prefer clarify over compactness. A clearer way to write this if would have been:
if (v1 > 0 && v2 > 0 && result < 0) || (v1 < 0 && v2 < 0 && result > 0)

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.

5 participants