diff options
author | Meng-Ying Yang <garfield@dexon.org> | 2019-05-09 16:10:57 +0800 |
---|---|---|
committer | Meng-Ying Yang <garfield@dexon.org> | 2019-05-09 16:10:57 +0800 |
commit | 154b726b1aa6fa6f17305f7b8b2f9b7aa7a76510 (patch) | |
tree | 894e774758b785c9e7c4306b15dc6eed65705950 | |
parent | 376628842e0200b80a4726b6beffb6ff57c9911d (diff) | |
download | dexon-wip/gy-sqlvm-runtime-p5.tar dexon-wip/gy-sqlvm-runtime-p5.tar.gz dexon-wip/gy-sqlvm-runtime-p5.tar.bz2 dexon-wip/gy-sqlvm-runtime-p5.tar.lz dexon-wip/gy-sqlvm-runtime-p5.tar.xz dexon-wip/gy-sqlvm-runtime-p5.tar.zst dexon-wip/gy-sqlvm-runtime-p5.zip |
fixup! core: vm: sqlvm: add built-in function SUBSTRING()wip/gy-sqlvm-runtime-p5
-rw-r--r-- | core/vm/sqlvm/runtime/functions.go | 15 | ||||
-rw-r--r-- | core/vm/sqlvm/runtime/instructions_op_test.go | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/core/vm/sqlvm/runtime/functions.go b/core/vm/sqlvm/runtime/functions.go index a885c92b8..d84517a76 100644 --- a/core/vm/sqlvm/runtime/functions.go +++ b/core/vm/sqlvm/runtime/functions.go @@ -456,7 +456,7 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op result = &Operand{ Meta: make([]ast.DataType, len(op.Meta)), - Data: make([]Tuple, len(op.Data)), + Data: make([]Tuple, length), } dynBytesType := ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0) @@ -466,9 +466,14 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op starts, ends := ops[1], ops[2] - var start, end uint64 + var start, end, t uint64 for i := uint64(0); i < length; i++ { - result.Data[i] = make(Tuple, len(op.Data[i])) + t = i + if op.IsImmediate { + t = 0 + } + + result.Data[i] = make(Tuple, len(op.Data[t])) if starts.IsImmediate { start, err = ast.DecimalToUint64(starts.Data[0][0].Value) @@ -490,8 +495,8 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op return } - for j := 0; j < len(op.Data[i]); j++ { - result.Data[i][j] = &Raw{Bytes: op.Data[i][j].Bytes[start : start+end]} + for j := 0; j < len(op.Data[t]); j++ { + result.Data[i][j] = &Raw{Bytes: op.Data[t][j].Bytes[start : start+end]} } } return diff --git a/core/vm/sqlvm/runtime/instructions_op_test.go b/core/vm/sqlvm/runtime/instructions_op_test.go index 0ff93a482..52b44e1f4 100644 --- a/core/vm/sqlvm/runtime/instructions_op_test.go +++ b/core/vm/sqlvm/runtime/instructions_op_test.go @@ -3999,7 +3999,7 @@ func (s *instructionSuite) TestOpFuncSubString() { ast.ComposeDataType(ast.DataTypeMajorUint, 0), }, []Tuple{ - {&Raw{Value: decimal.NewFromFloat(2)}}, + {&Raw{Value: decimal.NewFromFloat(1)}}, }, ), makeOperand( |