github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/function_test.go (about) 1 // Copyright 2021 - 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 function 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestFunctionOverloadID(t *testing.T) { 27 tcs := []struct { 28 fid int32 29 overloadId int32 30 }{ 31 {fid: 0, overloadId: 0}, 32 {fid: 1, overloadId: 10}, 33 {fid: 10, overloadId: 15}, 34 {fid: 400, overloadId: 1165}, 35 {fid: 3004, overloadId: 12345}, 36 } 37 for _, tc := range tcs { 38 f := EncodeOverloadID(tc.fid, tc.overloadId) 39 actualF, actualO := DecodeOverloadID(f) 40 require.Equal(t, tc.fid, actualF) 41 require.Equal(t, tc.overloadId, actualO) 42 } 43 } 44 45 func TestToPrintCastTable(t *testing.T) { 46 println("[Implicit Type Convert Rule for +, -, *, >, = and so on:]") 47 for i, rs := range binaryTable { 48 for j, r := range rs { 49 if r.convert { 50 println(fmt.Sprintf("%s + %s ===> %s + %s", 51 types.T(i).OidString(), types.T(j).OidString(), 52 r.left.OidString(), r.right.OidString())) 53 } 54 } 55 } 56 57 for i := 0; i < 5; i++ { 58 fmt.Println() 59 } 60 61 println("[Implicit Type Convert Rule for div and / :]") 62 for i, rs := range binaryTable2 { 63 for j, r := range rs { 64 if r.convert { 65 println(fmt.Sprintf("%s / %s ===> %s / %s", 66 types.T(i).OidString(), types.T(j).OidString(), 67 r.left.OidString(), r.right.OidString())) 68 } 69 } 70 } 71 72 for i := 0; i < 5; i++ { 73 fmt.Println() 74 } 75 76 println("[Implicit type conversions that we support :]") 77 for t1, t := range castTable { 78 for t2, k := range t { 79 if k { 80 str := fmt.Sprintf("%s ==> %s", 81 types.T(t1).OidString(), types.T(t2).OidString()) 82 if preferredTypeConvert[t1][t2] { 83 str += " (preferred)" 84 } 85 println(str) 86 } 87 } 88 } 89 }