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

evalEngine: Implement ELT and FIELD #15249

Merged
merged 9 commits into from
Apr 1, 2024
Merged
24 changes: 24 additions & 0 deletions go/vt/vtgate/evalengine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 121 additions & 0 deletions go/vt/vtgate/evalengine/compiler_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,127 @@ func (asm *assembler) Fn_BIT_LENGTH() {
}, "FN BIT_LENGTH VARCHAR(SP-1)")
}

func (asm *assembler) Fn_FIELD_i(args int) {
asm.adjustStack(-args + 1)
asm.emit(func(env *ExpressionEnv) int {
if env.vm.stack[env.vm.sp-args] == nil {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}

tar := env.vm.stack[env.vm.sp-args].(*evalInt64)

for i := range args - 1 {
if env.vm.stack[env.vm.sp-args+i+1] == nil {
continue
}

arg := env.vm.stack[env.vm.sp-args+i+1].(*evalInt64)

if tar.i == arg.i {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(int64(i + 1))
env.vm.sp -= args - 1
return 1
}
}

env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}, "FN FIELD INT64(SP-%d)...INT64(SP-1)", args)
}

func (asm *assembler) Fn_FIELD_b(args int) {
asm.adjustStack(-args + 1)
asm.emit(func(env *ExpressionEnv) int {
if env.vm.stack[env.vm.sp-args] == nil {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}

tar := env.vm.stack[env.vm.sp-args].(*evalBytes)

for i := range args - 1 {
if env.vm.stack[env.vm.sp-args+i+1] == nil {
continue
}

str := env.vm.stack[env.vm.sp-args+i+1].(*evalBytes)

// Compare target and current string
if len(tar.bytes) == len(str.bytes) {
beingnoble03 marked this conversation as resolved.
Show resolved Hide resolved
eq := true
for i, b := range tar.bytes {
if str.bytes[i] != b {
eq = false
break
}
}

if eq {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(int64(i + 1))
env.vm.sp -= args - 1
return 1
}
}
}

env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}, "FN FIELD VARCHAR(SP-%d)...VARCHAR(SP-1)", args)
dbussink marked this conversation as resolved.
Show resolved Hide resolved
}

func (asm *assembler) Fn_FIELD_f(args int) {
asm.adjustStack(-args + 1)
asm.emit(func(env *ExpressionEnv) int {
if env.vm.stack[env.vm.sp-args] == nil {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}

tar := env.vm.stack[env.vm.sp-args].(*evalFloat)

for i := range args - 1 {
if env.vm.stack[env.vm.sp-args+i+1] == nil {
continue
}

arg := env.vm.stack[env.vm.sp-args+i+1].(*evalFloat)

if tar.f == arg.f {
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(int64(i + 1))
env.vm.sp -= args - 1
return 1
}
}

env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalInt64(0)
env.vm.sp -= args - 1
return 1
}, "FN FIELD VARCHAR(SP-%d)...VARCHAR(SP-1)", args)
}

func (asm *assembler) Fn_ELT(args int, tt sqltypes.Type, tc collations.TypedCollation) {
asm.adjustStack(-args + 1)
asm.emit(func(env *ExpressionEnv) int {
i := env.vm.stack[env.vm.sp-args].(*evalInt64)

if i.i < 1 || int(i.i) >= args || env.vm.stack[env.vm.sp-args+int(i.i)] == nil {
env.vm.stack[env.vm.sp-args] = nil
} else {
b := env.vm.stack[env.vm.sp-args+int(i.i)].(*evalBytes)
env.vm.stack[env.vm.sp-args] = env.vm.arena.newEvalRaw(b.bytes, tt, tc)
}

env.vm.sp -= args - 1
return 1
}, "FN ELT INT64(SP-%d) VARCHAR(SP-%d)...VARCHAR(SP-1)", args, args-1)
}

func (asm *assembler) Fn_INSERT(col collations.TypedCollation) {
asm.adjustStack(-3)

Expand Down
Loading
Loading