github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/table_function/meta_scan.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 table_function 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/catalog" 19 "github.com/matrixorigin/matrixone/pkg/container/batch" 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/sql/colexec" 23 "github.com/matrixorigin/matrixone/pkg/vm" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/blockio" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 26 "github.com/matrixorigin/matrixone/pkg/vm/process" 27 ) 28 29 func metaScanPrepare(proc *process.Process, arg *Argument) (err error) { 30 arg.ctr = new(container) 31 arg.ctr.executorsForArgs, err = colexec.NewExpressionExecutorsFromPlanExpressions(proc, arg.Args) 32 return err 33 } 34 35 func metaScanCall(_ int, proc *process.Process, arg *Argument, result *vm.CallResult) (bool, error) { 36 var ( 37 err error 38 rbat *batch.Batch 39 ) 40 bat := result.Batch 41 defer func() { 42 if err != nil && rbat != nil { 43 rbat.Clean(proc.Mp()) 44 } 45 }() 46 if bat == nil { 47 return true, nil 48 } 49 50 v, err := arg.ctr.executorsForArgs[0].Eval(proc, []*batch.Batch{bat}) 51 if err != nil { 52 return false, err 53 } 54 uuid := vector.MustFixedCol[types.Uuid](v)[0] 55 // get file size 56 path := catalog.BuildQueryResultMetaPath(proc.SessionInfo.Account, uuid.ToString()) 57 // read meta's meta 58 reader, err := blockio.NewFileReader(proc.FileService, path) 59 if err != nil { 60 return false, err 61 } 62 var idxs []uint16 63 for i, name := range catalog.MetaColNames { 64 for _, attr := range arg.Attrs { 65 if name == attr { 66 idxs = append(idxs, uint16(i)) 67 } 68 } 69 } 70 // read meta's data 71 bats, closeCB, err := reader.LoadAllColumns(proc.Ctx, idxs, common.DefaultAllocator) 72 if err != nil { 73 return false, err 74 } 75 defer func() { 76 if closeCB != nil { 77 closeCB() 78 } 79 }() 80 rbat = batch.NewWithSize(len(bats[0].Vecs)) 81 metaVecs := rbat.Vecs 82 for i, vec := range bats[0].Vecs { 83 metaVecs[i], err = vec.Dup(proc.Mp()) 84 if err != nil { 85 rbat.Clean(proc.Mp()) 86 return false, err 87 } 88 } 89 rbat.SetAttributes(catalog.MetaColNames) 90 rbat.SetRowCount(1) 91 result.Batch = rbat 92 return false, nil 93 }