github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/tools.go (about) 1 // Copyright 2021 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 logtail 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "github.com/matrixorigin/matrixone/pkg/logutil" 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 25 "go.uber.org/zap/zapcore" 26 ) 27 28 func ToStringTemplate(vec containers.Vector, printN int, opts ...common.TypePrintOpt) string { 29 var w bytes.Buffer 30 _, _ = w.WriteString(fmt.Sprintf("[%d]: ", vec.Length())) 31 if printN < 0 || printN > vec.Length() { 32 printN = vec.Length() 33 } 34 first := true 35 typ := vec.GetType() 36 for i := 0; i < printN; i++ { 37 if !first { 38 _ = w.WriteByte(',') 39 } 40 v := vec.Get(i) 41 _, _ = w.WriteString(common.TypeStringValue(typ, v, opts...)) 42 first = false 43 } 44 45 return w.String() 46 } 47 48 const PrintN = 3 49 50 func DebugBatchToString(name string, bat *containers.Batch, isSpecialRowID bool, lvl zapcore.Level) string { 51 if logutil.GetSkip1Logger().Core().Enabled(lvl) { 52 return BatchToString(name, bat, isSpecialRowID) 53 } 54 return "not required level" 55 } 56 57 func BatchToString(name string, bat *containers.Batch, isSpecialRowID bool) string { 58 var w bytes.Buffer 59 _, _ = w.WriteString(fmt.Sprintf("[BatchName=%s]\n", name)) 60 for i, vec := range bat.Vecs { 61 _, _ = w.WriteString(fmt.Sprintf("(attr=%s)", bat.Attrs[i])) 62 if bat.Attrs[i] == catalog.AttrRowID { 63 if isSpecialRowID { 64 _, _ = w.WriteString(ToStringTemplate(vec, PrintN, common.WithSpecialRowid{})) 65 } else { 66 _, _ = w.WriteString(ToStringTemplate(vec, PrintN)) 67 } 68 } else { 69 _, _ = w.WriteString(ToStringTemplate(vec, PrintN, common.WithDoNotPrintBin{})) 70 } 71 _ = w.WriteByte('\n') 72 } 73 return w.String() 74 }