Skip to content

Commit

Permalink
evalengine: Implement integer division and modulo (#12656)
Browse files Browse the repository at this point in the history
* evalengine: Implement integer division and modulo

Signed-off-by: Dirkjan Bussink <[email protected]>

* evalengine: Implement NOT and logical operations

This adds the NOT and generic logical operations to the compiler and
fixes a number of existing bugs in the evalengine. Specifically NOT is
currently broken as we don't translate it properly.

Some main issues are that we need to ensure lazy evaluation for the
logical operations but also needing it for arithmetic as well.

All cases where we've been pushing the boolean singleton value need to
be fixed as well in the compiler, because we inline update things in
arithmetic operations and we'd update the singleton value before.

It also needs to split parsing into JSON from using an argument as a
partial JSON value. This specifically is needed for CAST() with an input
string where it should parse it. Additionally, convering a JSON boolean
to numeric needs to create a floating point value, not an integer one.

Signed-off-by: Dirkjan Bussink <[email protected]>

* Fix tests

Signed-off-by: Dirkjan Bussink <[email protected]>

* evalengine/compiler: Use helpers where appropriate

Signed-off-by: Dirkjan Bussink <[email protected]>

---------

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Mar 21, 2023
1 parent 61b73b6 commit 7eb4f35
Show file tree
Hide file tree
Showing 24 changed files with 1,376 additions and 236 deletions.
7 changes: 7 additions & 0 deletions go/vt/vtgate/evalengine/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func (a *Arena) newEvalDecimal(dec decimal.Decimal, m, d int32) *evalDecimal {
return a.newEvalDecimalWithPrec(dec.Clamp(m-d, d), d)
}

func (a *Arena) newEvalBool(b bool) *evalInt64 {
if b {
return a.newEvalInt64(1)
}
return a.newEvalInt64(0)
}

func (a *Arena) newEvalInt64(i int64) *evalInt64 {
if cap(a.aInt64) > len(a.aInt64) {
a.aInt64 = a.aInt64[:len(a.aInt64)+1]
Expand Down
Loading

0 comments on commit 7eb4f35

Please sign in to comment.