github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/catalog/processor.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 catalog 16 17 // XXX this API is broken. In case of inplementing a cursor like interface 18 // we cannot use error. moerr is a very heavy mechanism. 19 // 20 // Return a int code. 21 type Processor interface { 22 OnDatabase(database *DBEntry) error 23 OnTable(table *TableEntry) error 24 OnPostSegment(segment *SegmentEntry) error 25 OnSegment(segment *SegmentEntry) error 26 OnBlock(block *BlockEntry) error 27 } 28 29 type LoopProcessor struct { 30 DatabaseFn func(*DBEntry) error 31 TableFn func(*TableEntry) error 32 SegmentFn func(*SegmentEntry) error 33 BlockFn func(*BlockEntry) error 34 PostSegmentFn func(*SegmentEntry) error 35 } 36 37 func (p *LoopProcessor) OnDatabase(database *DBEntry) error { 38 if p.DatabaseFn != nil { 39 return p.DatabaseFn(database) 40 } 41 return nil 42 } 43 44 func (p *LoopProcessor) OnTable(table *TableEntry) error { 45 if p.TableFn != nil { 46 return p.TableFn(table) 47 } 48 return nil 49 } 50 51 func (p *LoopProcessor) OnPostSegment(segment *SegmentEntry) error { 52 if p.PostSegmentFn != nil { 53 return p.PostSegmentFn(segment) 54 } 55 return nil 56 } 57 58 func (p *LoopProcessor) OnSegment(segment *SegmentEntry) error { 59 if p.SegmentFn != nil { 60 return p.SegmentFn(segment) 61 } 62 return nil 63 } 64 65 func (p *LoopProcessor) OnBlock(block *BlockEntry) error { 66 if p.BlockFn != nil { 67 return p.BlockFn(block) 68 } 69 return nil 70 }