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

Add ut tools for plan2.Function (#2843)

parent 4463f959
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -2,22 +2,14 @@ package operator ...@@ -2,22 +2,14 @@ package operator
import ( import (
"fmt" "fmt"
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types" "github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector" "github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/vm/mheap" "github.com/matrixorigin/matrixone/pkg/sql/testutil"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/guest"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/host"
"github.com/matrixorigin/matrixone/pkg/vm/process" "github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
) )
var (
bt = types.Type{Oid: types.T_bool}
i64 = types.Type{Oid: types.T_int64}
)
type arg struct { type arg struct {
info string info string
proc *process.Process proc *process.Process
...@@ -27,194 +19,155 @@ type arg struct { ...@@ -27,194 +19,155 @@ type arg struct {
expect *vector.Vector expect *vector.Vector
} }
func newProc() *process.Process {
return process.New(mheap.New(guest.New(1<<10, host.New(1<<10))))
}
func makeBoolVector(values []bool) *vector.Vector {
vec := vector.New(bt)
vec.Col = values
return vec
}
func makeScalarBool(v bool, length int) *vector.Vector {
vec := newProc().AllocScalarVector(bt)
vec.Length = length
vec.Col = []bool{v}
return vec
}
func makeInt64Vector(is []int64, nsp []uint64) *vector.Vector {
vec := vector.New(i64)
vec.Col = is
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
return vec
}
func makeScalarInt64(i int64, length int) *vector.Vector {
vec := newProc().AllocScalarVector(i64)
vec.Length = length
vec.Col = []int64{i}
return vec
}
func makeScalarNull(length int) *vector.Vector {
vec := newProc().AllocScalarNullVector(types.Type{Oid: types.T_any})
vec.Length = length
return vec
}
func TestCwFn1(t *testing.T) { func TestCwFn1(t *testing.T) {
testCases := []arg{ testCases := []arg{
{ {
info: "when a = 1 then 1, when a = 2 then 2, else 3", proc: newProc(), info: "when a = 1 then 1, when a = 2 then 2, else 3", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{true, true, false, false, false}), // a = 1
makeScalarInt64(1, 5), // 1 testutil.MakeScalarInt64(1, 5), // 1
makeBoolVector([]bool{false, false, false, true, false}), // a = 2 testutil.MakeBoolVector([]bool{false, false, false, true, false}), // a = 2
makeScalarInt64(2, 5), // 2 testutil.MakeScalarInt64(2, 5), // 2
makeScalarInt64(3, 5), // 3 testutil.MakeScalarInt64(3, 5), // 3
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 1, 3, 2, 3}, nil), expect: testutil.MakeInt64Vector([]int64{1, 1, 3, 2, 3}, nil),
}, },
{ {
info: "when a = 1 then 1, when a = 2 then 2, else null", proc: newProc(), info: "when a = 1 then 1, when a = 2 then 2, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{false, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{false, false, false, false}), // a = 1
makeScalarInt64(1, 4), // 1 testutil.MakeScalarInt64(1, 4), // 1
makeBoolVector([]bool{true, false, false, false}), // a = 2 testutil.MakeBoolVector([]bool{true, false, false, false}), // a = 2
makeScalarInt64(2, 4), // 2 testutil.MakeScalarInt64(2, 4), // 2
makeScalarNull(4), testutil.MakeScalarNull(4),
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{2, 0, 0, 0}, []uint64{1, 2, 3}), expect: testutil.MakeInt64Vector([]int64{2, 0, 0, 0}, []uint64{1, 2, 3}),
}, },
{ {
info: "when a = 1 then 1, when a = 2 then 2", proc: newProc(), info: "when a = 1 then 1, when a = 2 then 2", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{false, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{false, false, false, false}), // a = 1
makeScalarInt64(1, 4), // 1 testutil.MakeScalarInt64(1, 4), // 1
makeBoolVector([]bool{true, false, false, false}), // a = 2 testutil.MakeBoolVector([]bool{true, false, false, false}), // a = 2
makeScalarInt64(2, 4), // 2 testutil.MakeScalarInt64(2, 4), // 2
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{2, 0, 0, 0}, []uint64{1, 2, 3}), expect: testutil.MakeInt64Vector([]int64{2, 0, 0, 0}, []uint64{1, 2, 3}),
}, },
{ {
info: "when a = 1 then c1, when a = 2 then c2", proc: newProc(), info: "when a = 1 then c1, when a = 2 then c2", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{true, true, false, false, false}), // a = 1
makeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5 testutil.MakeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5
makeBoolVector([]bool{false, false, true, true, false}), // a = 2 testutil.MakeBoolVector([]bool{false, false, true, true, false}), // a = 2
makeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0 testutil.MakeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null expect: testutil.MakeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null
}, },
{ {
info: "when a = 1 then c1, when a = 2 then c2", proc: newProc(), info: "when a = 1 then c1, when a = 2 then c2", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{true, true, false, false, false}), // a = 1
makeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5 testutil.MakeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5
makeBoolVector([]bool{false, false, true, true, false}), // a = 2 testutil.MakeBoolVector([]bool{false, false, true, true, false}), // a = 2
makeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0 testutil.MakeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null expect: testutil.MakeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null
}, },
{ {
info: "when a = 1 then c1, when a = 2 then c2, else null", proc: newProc(), info: "when a = 1 then c1, when a = 2 then c2, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{true, true, false, false, false}), // a = 1
makeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5 testutil.MakeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5
makeBoolVector([]bool{false, false, true, true, false}), // a = 2 testutil.MakeBoolVector([]bool{false, false, true, true, false}), // a = 2
makeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0 testutil.MakeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null expect: testutil.MakeInt64Vector([]int64{1, 0, 0, 0, 0}, []uint64{1, 2, 3, 4}), // 1, null, null, null, null
}, },
{ {
info: "when a = 1 then c1, when a = 2 then c2, else c3", proc: newProc(), info: "when a = 1 then c1, when a = 2 then c2, else c3", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false, false}), // a = 1 testutil.MakeBoolVector([]bool{true, true, false, false, false}), // a = 1
makeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5 testutil.MakeInt64Vector([]int64{1, 0, 3, 4, 5}, []uint64{1}), // 1, null, 3, 4, 5
makeBoolVector([]bool{false, false, true, true, false}), // a = 2 testutil.MakeBoolVector([]bool{false, false, true, true, false}), // a = 2
makeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0 testutil.MakeInt64Vector([]int64{0, 0, 0, 0, 0}, []uint64{1, 2, 3}), // 0, null, null, null, 0
makeInt64Vector([]int64{100, 200, 300, 0, 500}, []uint64{3}), // 100, 200, 300, null, 500 testutil.MakeInt64Vector([]int64{100, 200, 300, 0, 500}, []uint64{3}), // 100, 200, 300, null, 500
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 0, 0, 0, 500}, []uint64{1, 2, 3}), // 1, null, null, null, 500 expect: testutil.MakeInt64Vector([]int64{1, 0, 0, 0, 500}, []uint64{1, 2, 3}), // 1, null, null, null, 500
}, },
{ {
info: "when true then c1, when false then c2, else null", proc: newProc(), info: "when true then c1, when false then c2, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeScalarBool(true, 4), testutil.MakeScalarBool(true, 4),
makeInt64Vector([]int64{1, 2, 3, 4}, nil), // 1, 2, 3, 4 testutil.MakeInt64Vector([]int64{1, 2, 3, 4}, nil), // 1, 2, 3, 4
makeScalarBool(false, 4), testutil.MakeScalarBool(false, 4),
makeInt64Vector([]int64{4, 3, 2, 1}, nil), testutil.MakeInt64Vector([]int64{4, 3, 2, 1}, nil),
makeScalarNull(4), testutil.MakeScalarNull(4),
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 2, 3, 4}, nil), // 1, 2, 3, 4 expect: testutil.MakeInt64Vector([]int64{1, 2, 3, 4}, nil), // 1, 2, 3, 4
}, },
{ {
info: "when true then 1, when false then 2, else null", proc: newProc(), info: "when true then 1, when false then 2, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeScalarBool(true, 4), testutil.MakeScalarBool(true, 4),
makeScalarInt64(1, 4), testutil.MakeScalarInt64(1, 4),
makeScalarBool(false, 4), testutil.MakeScalarBool(false, 4),
makeScalarInt64(2, 4), testutil.MakeScalarInt64(2, 4),
makeScalarNull(4), testutil.MakeScalarNull(4),
}, },
match: true, match: true,
err: false, err: false,
expect: makeScalarInt64(1, 4), expect: testutil.MakeScalarInt64(1, 4),
}, },
{ {
info: "when a = 1 then null, when a = 2 then null, else null", proc: newProc(), info: "when a = 1 then null, when a = 2 then null, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{false, false, false, false}), testutil.MakeBoolVector([]bool{false, false, false, false}),
makeScalarNull(4), testutil.MakeScalarNull(4),
makeBoolVector([]bool{false, false, false, false}), testutil.MakeBoolVector([]bool{false, false, false, false}),
makeScalarNull(4), testutil.MakeScalarNull(4),
makeScalarNull(4), testutil.MakeScalarNull(4),
}, },
match: false, match: false,
}, },
{ {
// special case 1 // special case 1
info: "when a = 1 then 1, when a = 1 then 2, else null", proc: newProc(), info: "when a = 1 then 1, when a = 1 then 2, else null", proc: testutil.NewProc(),
vs: []*vector.Vector{ vs: []*vector.Vector{
makeBoolVector([]bool{true, true, false, false}), testutil.MakeBoolVector([]bool{true, true, false, false}),
makeScalarInt64(1, 4), testutil.MakeScalarInt64(1, 4),
makeBoolVector([]bool{false, true, true, false}), testutil.MakeBoolVector([]bool{false, true, true, false}),
makeScalarInt64(2, 4), testutil.MakeScalarInt64(2, 4),
makeScalarNull(4), testutil.MakeScalarNull(4),
}, },
match: true, match: true,
err: false, err: false,
expect: makeInt64Vector([]int64{1, 1, 2, 0}, []uint64{3}), expect: testutil.MakeInt64Vector([]int64{1, 1, 2, 0}, []uint64{3}),
}, },
} }
...@@ -238,31 +191,7 @@ func TestCwFn1(t *testing.T) { ...@@ -238,31 +191,7 @@ func TestCwFn1(t *testing.T) {
require.Errorf(t, ergot, fmt.Sprintf("case '%d' expected error, but no error happens", i)) require.Errorf(t, ergot, fmt.Sprintf("case '%d' expected error, but no error happens", i))
} else { } else {
require.NoError(t, ergot) require.NoError(t, ergot)
//println(fmt.Sprintf("e: %v", tc.expect.Col)) require.True(t, testutil.CompareVectors(tc.expect, got), "got vector is different with expected")
//println(fmt.Sprintf("g: %v", got.Col))
if tc.expect.IsScalar() {
require.True(t, got.IsScalar())
if tc.expect.IsScalarNull() {
require.True(t, got.IsScalarNull())
} else {
require.Equal(t, tc.expect.Col.([]int64)[0], got.Col.([]int64)[0])
}
} else {
require.False(t, got.IsScalar())
expectL := vector.Length(tc.expect)
gotL := vector.Length(got)
require.Equal(t, expectL, gotL)
require.Equal(t, nulls.Any(tc.expect.Nsp), nulls.Any(got.Nsp))
for k := 0; k < gotL; k++ {
c := nulls.Contains(tc.expect.Nsp, uint64(k))
require.Equal(t, c, nulls.Contains(got.Nsp, uint64(k)))
if !c {
require.Equal(t, tc.expect.Col.([]int64)[k], got.Col.([]int64)[k])
}
}
}
} }
}) })
} }
......
...@@ -2024,24 +2024,6 @@ var operators = map[int][]Function{ ...@@ -2024,24 +2024,6 @@ var operators = map[int][]Function{
TypeCheckFn: strictTypeCheck, TypeCheckFn: strictTypeCheck,
Fn: operator.ModFloat[float64], Fn: operator.ModFloat[float64],
}, },
{
Index: 10,
Flag: plan.Function_STRICT,
Layout: BINARY_ARITHMETIC_OPERATOR,
Args: []types.T{types.T_decimal64, types.T_decimal64},
ReturnTyp: types.T_decimal64,
TypeCheckFn: strictTypeCheck,
Fn: nil,
},
{
Index: 11,
Flag: plan.Function_STRICT,
Layout: BINARY_ARITHMETIC_OPERATOR,
Args: []types.T{types.T_decimal128, types.T_decimal128},
ReturnTyp: types.T_decimal128,
TypeCheckFn: strictTypeCheck,
Fn: nil,
},
}, },
UNARY_PLUS: { UNARY_PLUS: {
{ {
......
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
Package testutil implements some function may be used while doing unit-test for
functions in compute-layer.
Such as:
1. init functions for common structure, likes vector, types.Bytes and so on.
2.
*/
package testutil
import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
)
func MakeBytes(strs []string) *types.Bytes {
ret := &types.Bytes{}
next := uint32(0)
for _, s := range strs {
l := uint32(len(s))
ret.Data = append(ret.Data, []byte(s)...)
ret.Lengths = append(ret.Lengths, l)
ret.Offsets = append(ret.Offsets, next)
next += l
}
return ret
}
func MakeInt8Vector(vs []int8, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_int8, Size: 1})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeInt16Vector(vs []int16, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_int16, Size: 2})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeInt32Vector(vs []int32, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_int32, Size: 4})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeInt64Vector(vs []int64, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_int64, Size: 8})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeUint8Vector(vs []uint8, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_uint8, Size: 1})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeUint16Vector(vs []uint16, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_uint16, Size: 2})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeUint32Vector(vs []uint32, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_uint32, Size: 4})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeUint64Vector(vs []uint64, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_uint64, Size: 8})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeStringVector(vs []string, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_varchar, Size: 24})
ret.Ref = ref
vector.SetCol(ret, MakeBytes(vs))
return ret
}
func MakeFloat32Vector(vs []float32, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_float32, Size: 4})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
func MakeFloat64Vector(vs []float64, ref uint64) *vector.Vector {
ret := vector.New(types.Type{Oid: types.T_float64, Size: 8})
ret.Ref = ref
vector.SetCol(ret, vs)
// vector.SetLength(ret, len(vs))
return ret
}
...@@ -13,3 +13,343 @@ ...@@ -13,3 +13,343 @@
// limitations under the License. // limitations under the License.
package testutil package testutil
import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/vm/mheap"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/guest"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/host"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"golang.org/x/exp/constraints"
"reflect"
"unsafe"
)
var (
bt = types.T_bool.ToType()
i8 = types.T_int8.ToType()
i16 = types.T_int16.ToType()
i32 = types.T_int32.ToType()
i64 = types.T_int64.ToType()
u8 = types.T_uint8.ToType()
u16 = types.T_uint16.ToType()
u32 = types.T_uint32.ToType()
u64 = types.T_uint64.ToType()
f32 = types.T_float32.ToType()
f64 = types.T_float64.ToType()
ct = types.T_char.ToType()
vc = types.T_varchar.ToType()
d64 = types.T_decimal64.ToType()
d128 = types.T_decimal128.ToType()
dt = types.T_date.ToType()
dti = types.T_datetime.ToType()
)
type vecType interface {
constraints.Integer | constraints.Float | bool
}
func makeVector[T vecType](values []T, nsp []uint64, typ types.Type) *vector.Vector {
vec := vector.New(typ)
vec.Col = values
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
return vec
}
func makeScalar[T vecType](value T, length int, typ types.Type) *vector.Vector {
vec := NewProc().AllocScalarVector(typ)
vec.Length = length
vec.Col = []T{value}
return vec
}
func makeStringVector(values []string, nsp []uint64, typ types.Type) *vector.Vector {
vec := vector.New(typ)
bs := &types.Bytes{
Lengths: make([]uint32, len(values)),
Offsets: make([]uint32, len(values)),
}
next := uint32(0)
if nsp == nil {
for i, s := range values {
l := uint32(len(s))
bs.Data = append(bs.Data, []byte(s)...)
bs.Lengths[i] = l
bs.Offsets[i] = next
next += l
}
} else {
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
for i := range values {
if nulls.Contains(vec.Nsp, uint64(i)) {
continue
}
s := values[i]
l := uint32(len(s))
bs.Data = append(bs.Data, []byte(s)...)
bs.Lengths[i] = l
bs.Offsets[i] = next
next += l
}
}
vec.Col = bs
return vec
}
func NewProc() *process.Process {
return process.New(mheap.New(guest.New(1<<10, host.New(1<<10))))
}
func MakeScalarNull(length int) *vector.Vector {
vec := NewProc().AllocScalarNullVector(types.Type{Oid: types.T_any})
vec.Length = length
return vec
}
func MakeBoolVector(values []bool) *vector.Vector {
return makeVector[bool](values, nil, bt)
}
func MakeScalarBool(v bool, length int) *vector.Vector {
return makeScalar[bool](v, length, bt)
}
func MakeInt64Vector(values []int64, nsp []uint64) *vector.Vector {
return makeVector[int64](values, nsp, i64)
}
func MakeScalarInt64(v int64, length int) *vector.Vector {
return makeScalar[int64](v, length, i64)
}
func MakeInt32Vector(values []int32, nsp []uint64) *vector.Vector {
return makeVector[int32](values, nsp, i32)
}
func MakeScalarInt32(v int32, length int) *vector.Vector {
return makeScalar[int32](v, length, i32)
}
func MakeInt16Vector(values []int16, nsp []uint64) *vector.Vector {
return makeVector[int16](values, nsp, i16)
}
func MakeScalarInt16(v int16, length int) *vector.Vector {
return makeScalar[int16](v, length, i16)
}
func MakeInt8Vector(values []int8, nsp []uint64) *vector.Vector {
return makeVector[int8](values, nsp, i8)
}
func MakeScalarInt8(v int8, length int) *vector.Vector {
return makeScalar[int8](v, length, i8)
}
func MakeUint64Vector(values []uint64, nsp []uint64) *vector.Vector {
return makeVector[uint64](values, nsp, u64)
}
func MakeScalarUint64(v uint64, length int) *vector.Vector {
return makeScalar[uint64](v, length, u64)
}
func MakeUint32Vector(values []uint32, nsp []uint64) *vector.Vector {
return makeVector[uint32](values, nsp, u32)
}
func MakeScalarUint32(v uint32, length int) *vector.Vector {
return makeScalar[uint32](v, length, u32)
}
func MakeUint16Vector(values []uint16, nsp []uint64) *vector.Vector {
return makeVector[uint16](values, nsp, u16)
}
func MakeScalarUint16(v uint16, length int) *vector.Vector {
return makeScalar[uint16](v, length, u16)
}
func MakeUint8Vector(values []uint8, nsp []uint64) *vector.Vector {
return makeVector[uint8](values, nsp, u8)
}
func MakeScalarUint8(v uint8, length int) *vector.Vector {
return makeScalar[uint8](v, length, u8)
}
func MakeFloat32Vector(values []float32, nsp []uint64) *vector.Vector {
return makeVector[float32](values, nsp, f32)
}
func MakeScalarFloat32(v float32, length int) *vector.Vector {
return makeScalar[float32](v, length, f32)
}
func MakeFloat64Vector(values []float64, nsp []uint64) *vector.Vector {
return makeVector[float64](values, nsp, f64)
}
func MakeScalarFloat64(v float64, length int) *vector.Vector {
return makeScalar[float64](v, length, f64)
}
func MakeCharVector(values []string, nsp []uint64) *vector.Vector {
return makeStringVector(values, nsp, ct)
}
func MakeVarcharVector(values []string, nsp []uint64) *vector.Vector {
return makeStringVector(values, nsp, vc)
}
func MakeDecimal64Vector(values []int64, nsp []uint64) *vector.Vector {
vec := vector.New(d64)
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
vec.Col = (*types.Decimal64)(unsafe.Pointer(&values))
return vec
}
func MakeScalarDecimal64(v int64, length int) *vector.Vector {
vec := NewProc().AllocScalarVector(d64)
vec.Length = length
vec.Col = []types.Decimal64{types.Decimal64(v)}
return vec
}
func MakeDecimal128Vector(values []uint64, nsp []uint64) *vector.Vector {
vec := vector.New(d128)
cols := make([]types.Decimal128, len(values))
if nsp == nil {
for i, v := range values {
d := types.InitDecimal128UsingUint(v)
cols[i] = d
}
} else {
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
for i, v := range values {
if nulls.Contains(vec.Nsp, uint64(i)) {
continue
}
d := types.InitDecimal128UsingUint(v)
cols[i] = d
}
}
vec.Col = cols
return vec
}
func MakeScalarDecimal128(v uint64, length int) *vector.Vector {
vec := NewProc().AllocScalarVector(d128)
vec.Length = length
vec.Col = []types.Decimal128{types.InitDecimal128UsingUint(v)}
return vec
}
func MakeDateVector(values []string, nsp []uint64) *vector.Vector {
vec := vector.New(dt)
ds := make([]types.Date, len(values))
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
for i, s := range values {
if nulls.Contains(vec.Nsp, uint64(i)) {
continue
}
d, err := types.ParseDate(s)
if err != nil {
panic(err)
}
ds[i] = d
}
vec.Col = ds
return vec
}
func MakeScalarDate(value string, length int) *vector.Vector {
vec := NewProc().AllocScalarVector(dt)
vec.Length = length
d, err := types.ParseDate(value)
if err != nil {
panic(err)
}
vec.Col = []types.Date{d}
return vec
}
func MakeDateTimeVector(values []string, nsp []uint64) *vector.Vector {
vec := vector.New(dti)
ds := make([]types.Datetime, len(values))
for _, n := range nsp {
nulls.Add(vec.Nsp, n)
}
for i, s := range values {
if nulls.Contains(vec.Nsp, uint64(i)) {
continue
}
d, err := types.ParseDatetime(s)
if err != nil {
panic(err)
}
ds[i] = d
}
vec.Col = ds
return vec
}
func MakeScalarDateTime(value string, length int) *vector.Vector {
vec := NewProc().AllocScalarVector(dti)
vec.Length = length
d, err := types.ParseDatetime(value)
if err != nil {
panic(err)
}
vec.Col = []types.Datetime{d}
return vec
}
func CompareVectors(expected *vector.Vector, got *vector.Vector) bool {
if expected.IsScalar() {
if !got.IsScalar() {
return false
}
if expected.IsScalarNull() {
return got.IsScalarNull()
} else {
return reflect.DeepEqual(expected.Col, got.Col)
}
} else {
if got.IsScalar() {
return false
}
// expected length and got length
expectedLength := vector.Length(expected)
gotLength := vector.Length(got)
if expectedLength != gotLength {
return false
}
if nulls.Any(expected.Nsp) {
var k uint64 = 0
if !nulls.Any(got.Nsp) {
return false
}
for k = 0; k < uint64(expectedLength); k++ {
c1 := nulls.Contains(expected.Nsp, k)
c2 := nulls.Contains(got.Nsp, k)
if c1 != c2 {
return false
}
}
}
return reflect.DeepEqual(expected.Col, got.Col)
}
}
...@@ -24,7 +24,8 @@ import ( ...@@ -24,7 +24,8 @@ import (
) )
func makeArgs(ss []string) *types.Bytes { func makeArgs(ss []string) *types.Bytes {
return testutil.MakeBytes(ss) vec := testutil.MakeVarcharVector(ss, nil)
return vec.Col.(*types.Bytes)
} }
func Test_sliceLikePure(t *testing.T) { func Test_sliceLikePure(t *testing.T) {
......
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