Skip to content
Snippets Groups Projects
Unverified Commit 7eafae13 authored by iamlinjunhong's avatar iamlinjunhong Committed by GitHub
Browse files

fix bvt error about substring and lpad (#4462)

parent bad5e0b1
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"math"
)
const (
......@@ -40,7 +41,7 @@ func Lpad(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error)
sourceStr := vector.MustBytesCols(vecs[ParameterSourceString]) //Get the first arg
//characters length not bytes length
lengthsOfChars := vector.MustTCols[int64](vecs[ParameterLengths])
lengthsOfChars := getLensForLpad(vecs[ParameterLengths].Col)
//pad string
padStr := vector.MustBytesCols(vecs[ParameterPadString])
......@@ -84,6 +85,36 @@ func Lpad(vecs []*vector.Vector, proc *process.Process) (*vector.Vector, error)
return resultVec, nil
}
func getLensForLpad(col interface{}) []int64 {
switch vs := col.(type) {
case []int64:
return vs
case []float64:
res := make([]int64, 0, len(vs))
for _, v := range vs {
if v > float64(math.MaxInt64) {
res = append(res, math.MaxInt64)
} else if v < float64(math.MinInt64) {
res = append(res, math.MinInt64)
} else {
res = append(res, int64(v))
}
}
return res
case []uint64:
res := make([]int64, 0, len(vs))
for _, v := range vs {
if v > uint64(math.MaxInt64) {
res = append(res, math.MaxInt64)
} else {
res = append(res, int64(v))
}
}
return res
}
panic("unexpected parameter types were received")
}
func getSpaceLengthOfLpad(sourceStr *types.Bytes, lengths []int64, padStr *types.Bytes, rowCount int, constVectors []bool, inputNulls []*nulls.Nulls) int64 {
neededSpace := int64(0)
for i := 0; i < rowCount; i++ {
......
......@@ -259,6 +259,15 @@ func castConstAsint64(srcColumn interface{}, columnType types.T, idx int) int64
dstValue = int64(srcColumn.([]int32)[idx])
case types.T_int64:
dstValue = srcColumn.([]int64)[idx]
case types.T_float64:
fval := srcColumn.([]float64)[idx]
if fval > float64(math.MaxInt64) {
dstValue = math.MaxInt64
} else if fval < float64(math.MinInt64) {
dstValue = math.MinInt64
} else {
dstValue = int64(fval)
}
default:
dstValue = int64(0)
}
......
......@@ -756,6 +756,20 @@ var builtins = map[int]Functions{
Args: []types.T{types.T_varchar, types.T_int64, types.T_varchar},
ReturnTyp: types.T_varchar, Fn: multi.Lpad,
},
{
Index: 1,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_float64, types.T_varchar},
ReturnTyp: types.T_varchar, Fn: multi.Lpad,
},
{
Index: 2,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_uint64, types.T_varchar},
ReturnTyp: types.T_varchar, Fn: multi.Lpad,
},
},
},
PI: {
......@@ -1256,12 +1270,60 @@ var builtins = map[int]Functions{
Index: 4,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_char, types.T_float64},
ReturnTyp: types.T_char,
Fn: multi.Substring,
},
{
Index: 5,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_float64, types.T_int64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 6,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_float64, types.T_uint64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 7,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_int64, types.T_float64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 8,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_uint64, types.T_float64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 9,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_float64, types.T_float64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 10,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_int64, types.T_int64},
ReturnTyp: types.T_varchar,
Fn: multi.Substring,
},
{
Index: 5,
Index: 11,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_int64, types.T_uint64},
......@@ -1269,7 +1331,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 6,
Index: 12,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_uint64, types.T_int64},
......@@ -1277,7 +1339,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 7,
Index: 13,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_varchar, types.T_uint64, types.T_uint64},
......@@ -1285,7 +1347,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 8,
Index: 14,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_char, types.T_int64, types.T_int64},
......@@ -1293,7 +1355,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 9,
Index: 15,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_char, types.T_int64, types.T_uint64},
......@@ -1301,7 +1363,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 10,
Index: 16,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_char, types.T_uint64, types.T_int64},
......@@ -1309,7 +1371,7 @@ var builtins = map[int]Functions{
Fn: multi.Substring,
},
{
Index: 11,
Index: 17,
Flag: plan.Function_STRICT,
Layout: STANDARD_FUNCTION,
Args: []types.T{types.T_char, types.T_uint64, types.T_uint64},
......
......@@ -16,6 +16,7 @@ package substring
import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"math"
)
/*
......@@ -206,6 +207,15 @@ func substringDynamicOffsetUnbounded(src *types.Bytes, res *types.Bytes, startCo
startValue = int64(startColumn.([]int32)[idx])
case types.T_int64:
startValue = startColumn.([]int64)[idx]
case types.T_float64:
fval := startColumn.([]float64)[idx]
if fval > float64(math.MaxInt64) {
startValue = math.MaxInt64
} else if fval < float64(math.MinInt64) {
startValue = math.MinInt64
} else {
startValue = int64(fval)
}
default:
startValue = int64(1)
}
......@@ -386,6 +396,15 @@ func getColumnValue(srcColumn interface{}, columnType types.T, idx int, isConstt
dstValue = int64(srcColumn.([]int32)[idx])
case types.T_int64:
dstValue = srcColumn.([]int64)[idx]
case types.T_float64:
fval := srcColumn.([]float64)[idx]
if fval > float64(math.MaxInt64) {
dstValue = math.MaxInt64
} else if fval < float64(math.MinInt64) {
dstValue = math.MinInt64
} else {
dstValue = int64(fval)
}
default:
dstValue = int64(1)
}
......
......@@ -27,16 +27,12 @@ select rpad('hello', 4294967296, '1');
select rpad('hello', -4294967297, '1');
select rpad('hello', 4294967297, '1');
-- @bvt:issue#3738
-- @bvt:issue#3249
select rpad('hello', -18446744073709551615, '1');
select rpad('hello', 18446744073709551615, '1');
select rpad('hello', -18446744073709551616, '1');
select rpad('hello', 18446744073709551616, '1');
select rpad('hello', -18446744073709551617, '1');
select rpad('hello', 18446744073709551617, '1');
-- @bvt:issue
-- @bvt:issue
select lpad('hello', -1, '1');
select lpad('hello', -4294967295, '1');
......@@ -46,16 +42,12 @@ select lpad('hello', 4294967296, '1');
select lpad('hello', -4294967297, '1');
select lpad('hello', 4294967297, '1');
-- @bvt:issue#3738
-- @bvt:issue#3249
select lpad('hello', -18446744073709551615, '1');
select lpad('hello', 18446744073709551615, '1');
select lpad('hello', -18446744073709551616, '1');
select lpad('hello', 18446744073709551616, '1');
select lpad('hello', -18446744073709551617, '1');
select lpad('hello', 18446744073709551617, '1');
-- @bvt:issue
-- @bvt:issue
SELECT RPAD('hi', year(FROM_UNIXTIME(-1)),'?');
SELECT LPAD('hi', year(FROM_UNIXTIME(-1)),'?');
......
......@@ -32,12 +32,10 @@ select substring('hello', -18446744073709551615, 1);
-- @bvt:issue
select substring('hello', 18446744073709551615, 1);
-- @bvt:issue#3249
select substring('hello', -18446744073709551616, 1);
select substring('hello', 18446744073709551616, 1);
select substring('hello', -18446744073709551617, 1);
select substring('hello', 18446744073709551617, 1);
-- @bvt:issue
select substring('hello', 1, -1);
......@@ -65,14 +63,12 @@ select substring('hello', 4294967296, 4294967296);
select substring('hello', -4294967297, -4294967297);
select substring('hello', 4294967297, 4294967297);
-- @bvt:issue#3249
select substring('hello', -18446744073709551615, -18446744073709551615);
select substring('hello', 18446744073709551615, 18446744073709551615);
select substring('hello', -18446744073709551616, -18446744073709551616);
select substring('hello', 18446744073709551616, 18446744073709551616);
select substring('hello', -18446744073709551617, -18446744073709551617);
select substring('hello', 18446744073709551617, 18446744073709551617);
-- @bvt:issue
SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
SELECT SUBSTRING('foobarbar' FROM 4);
......
......@@ -100,17 +100,23 @@ select lpad('hello', 4294967297, '1');
lpad('hello', 4294967297, '1')
null
select lpad('hello', -18446744073709551615, '1');
Operator 'cast' with parameters [DECIMAL128 BIGINT] will be implemented in future version.
lpad(hello, -18446744073709551615, 1)
null
select lpad('hello', 18446744073709551615, '1');
Can't cast '18446744073709551615' from BIGINT UNSIGNED type to BIGINT type. Reason: overflow
lpad(hello, 18446744073709551615, 1)
null
select lpad('hello', -18446744073709551616, '1');
Operator 'cast' with parameters [DECIMAL128 BIGINT] will be implemented in future version.
lpad(hello, -18446744073709551616, 1)
null
select lpad('hello', 18446744073709551616, '1');
Operator 'cast' with parameters [DECIMAL128 BIGINT] will be implemented in future version.
lpad(hello, 18446744073709551616, 1)
null
select lpad('hello', -18446744073709551617, '1');
Operator 'cast' with parameters [DECIMAL128 BIGINT] will be implemented in future version.
lpad(hello, -18446744073709551617, 1)
null
select lpad('hello', 18446744073709551617, '1');
Operator 'cast' with parameters [DECIMAL128 BIGINT] will be implemented in future version.
lpad(hello, 18446744073709551617, 1)
null
SELECT RPAD('hi', year(FROM_UNIXTIME(-1)),'?');
RPAD('hi', year(FROM_UNIXTIME(-1)),'?')
null
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment