github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/rpc/adaptors.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 rpc 16 17 import ( 18 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/matrixorigin/matrixone/pkg/container/batch" 22 "github.com/matrixorigin/matrixone/pkg/logutil" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 26 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 27 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/handle" 28 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/options" 29 ) 30 31 func CreateRelation( 32 _ context.Context, 33 dbH handle.Database, 34 name string, 35 id uint64, 36 defs []engine.TableDef) (err error) { 37 schema, err := DefsToSchema(name, defs) 38 if err != nil { 39 return 40 } 41 schema.BlockMaxRows = options.DefaultBlockMaxRows 42 schema.ObjectMaxBlocks = options.DefaultBlocksPerObject 43 _, err = dbH.CreateRelationWithID(schema, id) 44 return err 45 } 46 47 func TableDefs(rel handle.Relation) ([]engine.TableDef, error) { 48 schema := rel.Schema().(*catalog.Schema) 49 return SchemaToDefs(schema) 50 } 51 52 func TableNamesOfDB(db handle.Database) ([]string, error) { 53 var names []string 54 55 it := db.MakeRelationIt() 56 for it.Valid() { 57 names = append(names, it.GetRelation().Schema().(*catalog.Schema).Name) 58 it.Next() 59 } 60 return names, nil 61 } 62 63 func AppendDataToTable(ctx context.Context, rel handle.Relation, bat *batch.Batch) (err error) { 64 tnBat := containers.ToTNBatch(bat, common.WorkspaceAllocator) 65 defer tnBat.Close() 66 err = rel.Append(ctx, tnBat) 67 return 68 } 69 70 func GetHideKeysOfTable(rel handle.Relation) ([]*engine.Attribute, error) { 71 schema := rel.Schema().(*catalog.Schema) 72 if schema.PhyAddrKey == nil { 73 return nil, moerr.NewNotSupportedNoCtx("system table has no rowid") 74 } 75 key := new(engine.Attribute) 76 key.Name = schema.PhyAddrKey.Name 77 key.Type = schema.PhyAddrKey.Type 78 key.IsRowId = true 79 // key.IsHidden = true 80 logutil.Debugf("GetHideKey: %v", key) 81 return []*engine.Attribute{key}, nil 82 }