github.com/matrixorigin/matrixone@v0.7.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/common/moerr" 20 "github.com/matrixorigin/matrixone/pkg/container/batch" 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 "github.com/matrixorigin/matrixone/pkg/container/vector" 23 "github.com/matrixorigin/matrixone/pkg/objectio" 24 "github.com/matrixorigin/matrixone/pkg/sql/colexec" 25 "github.com/matrixorigin/matrixone/pkg/vm/process" 26 ) 27 28 func metaScanPrepare(_ *process.Process, arg *Argument) error { 29 return nil 30 } 31 32 func metaScanCall(_ int, proc *process.Process, arg *Argument) (bool, error) { 33 var ( 34 err error 35 rbat *batch.Batch 36 ) 37 defer func() { 38 if err != nil && rbat != nil { 39 rbat.Clean(proc.Mp()) 40 } 41 }() 42 bat := proc.InputBatch() 43 if bat == nil { 44 return true, nil 45 } 46 v, err := colexec.EvalExpr(bat, proc, arg.Args[0]) 47 if err != nil { 48 return false, err 49 } 50 uuid := vector.MustTCols[types.Uuid](v)[0] 51 // get file size 52 fs := objectio.NewObjectFS(proc.FileService, catalog.QueryResultMetaDir) 53 dirs, err := fs.ListDir(catalog.QueryResultMetaDir) 54 if err != nil { 55 return false, err 56 } 57 var size int64 = -1 58 name := catalog.BuildQueryResultMetaName(proc.SessionInfo.Account, uuid.ToString()) 59 for _, d := range dirs { 60 if d.Name == name { 61 size = d.Size 62 } 63 } 64 if size == -1 { 65 return false, moerr.NewQueryIdNotFound(proc.Ctx, uuid.ToString()) 66 } 67 // read meta's meta 68 path := catalog.BuildQueryResultMetaPath(proc.SessionInfo.Account, uuid.ToString()) 69 reader, err := objectio.NewObjectReader(path, proc.FileService) 70 if err != nil { 71 return false, err 72 } 73 bs, err := reader.ReadAllMeta(proc.Ctx, size, proc.Mp()) 74 if err != nil { 75 return false, err 76 } 77 var idxs []uint16 78 for i, name := range catalog.MetaColNames { 79 for _, attr := range arg.Attrs { 80 if name == attr { 81 idxs = append(idxs, uint16(i)) 82 } 83 } 84 } 85 // read meta's data 86 iov, err := reader.Read(proc.Ctx, bs[0].GetExtent(), idxs, proc.Mp()) 87 if err != nil { 88 return false, err 89 } 90 rbat = batch.NewWithSize(len(idxs)) 91 rbat.SetAttributes(catalog.MetaColNames) 92 rbat.Cnt = 1 93 for i, e := range iov.Entries { 94 rbat.Vecs[i] = vector.New(catalog.MetaColTypes[idxs[i]]) 95 if err = rbat.Vecs[i].Read(e.Object.([]byte)); err != nil { 96 return false, err 97 } 98 } 99 rbat.InitZsOne(1) 100 proc.SetInputBatch(rbat) 101 return false, nil 102 }