github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/binary/show_visible_bin_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package binary 16 17 import ( 18 "fmt" 19 "github.com/matrixorigin/matrixone/pkg/container/types" 20 "github.com/matrixorigin/matrixone/pkg/container/vector" 21 "github.com/matrixorigin/matrixone/pkg/pb/plan" 22 "github.com/matrixorigin/matrixone/pkg/testutil" 23 "github.com/stretchr/testify/require" 24 "testing" 25 ) 26 27 func TestShowVisibleBin(t *testing.T) { 28 var out *vector.Vector 29 tp := types.T_varchar.ToType() 30 buf, err := types.Encode(tp) 31 require.NoError(t, err) 32 require.NotNil(t, buf) 33 toCode := typNormal 34 c1 := makeVec(buf, uint8(toCode)) 35 out, err = ShowVisibleBin(c1, testutil.NewProc()) 36 require.NoError(t, err) 37 require.NotNil(t, out) 38 require.Equal(t, 1, out.Length()) 39 require.Equal(t, []byte(tp.String()), vector.MustBytesCols(out)[0]) 40 toCode = typWithLen 41 c2 := makeVec(buf, uint8(toCode)) 42 out, err = ShowVisibleBin(c2, testutil.NewProc()) 43 require.NoError(t, err) 44 require.NotNil(t, out) 45 require.Equal(t, 1, out.Length()) 46 require.Equal(t, fmt.Sprintf("%s(%d)", tp.String(), tp.Width), vector.MustStrCols(out)[0]) 47 48 update := new(plan.OnUpdate) 49 update.OriginString = "update" 50 update.Expr = &plan.Expr{} 51 buf, err = types.Encode(update) 52 require.NoError(t, err) 53 require.NotNil(t, buf) 54 toCode = onUpdateExpr 55 c3 := makeVec(buf, uint8(toCode)) 56 out, err = ShowVisibleBin(c3, testutil.NewProc()) 57 require.NoError(t, err) 58 require.NotNil(t, out) 59 require.Equal(t, 1, out.Length()) 60 require.Equal(t, update.OriginString, vector.MustStrCols(out)[0]) 61 62 def := new(plan.Default) 63 def.OriginString = "default" 64 def.Expr = &plan.Expr{} 65 buf, err = types.Encode(def) 66 require.NoError(t, err) 67 require.NotNil(t, buf) 68 toCode = defaultExpr 69 c4 := makeVec(buf, uint8(toCode)) 70 out, err = ShowVisibleBin(c4, testutil.NewProc()) 71 require.NoError(t, err) 72 require.NotNil(t, out) 73 require.Equal(t, 1, out.Length()) 74 require.Equal(t, def.OriginString, vector.MustStrCols(out)[0]) 75 76 } 77 func makeVec(buf []byte, toCode uint8) []*vector.Vector { 78 vec := vector.New(types.T_varchar.ToType()) 79 _ = vec.Append(buf, len(buf) == 0, testutil.TestUtilMp) 80 vec2 := vector.NewConst(types.T_uint8.ToType(), 1) 81 _ = vec2.Append(toCode, false, testutil.TestUtilMp) 82 return []*vector.Vector{vec, vec2} 83 }