github.com/matrixorigin/matrixone@v1.2.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  import "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/data"
    18  
    19  // XXX this API is broken.  In case of inplementing a cursor like interface
    20  // we cannot use error.  moerr is a very heavy mechanism.
    21  //
    22  // Return a int code.
    23  type Processor interface {
    24  	OnDatabase(database *DBEntry) error
    25  	OnPostDatabase(database *DBEntry) error
    26  	OnTable(table *TableEntry) error
    27  	OnPostTable(table *TableEntry) error
    28  	OnPostObject(object *ObjectEntry) error
    29  	OnObject(object *ObjectEntry) error
    30  	OnTombstone(tombstone data.Tombstone) error
    31  }
    32  
    33  type LoopProcessor struct {
    34  	DatabaseFn     func(*DBEntry) error
    35  	TableFn        func(*TableEntry) error
    36  	ObjectFn       func(*ObjectEntry) error
    37  	PostDatabaseFn func(*DBEntry) error
    38  	PostTableFn    func(*TableEntry) error
    39  	PostObjectFn   func(*ObjectEntry) error
    40  	TombstoneFn    func(data.Tombstone) error
    41  }
    42  
    43  func (p *LoopProcessor) OnDatabase(database *DBEntry) error {
    44  	if p.DatabaseFn != nil {
    45  		return p.DatabaseFn(database)
    46  	}
    47  	return nil
    48  }
    49  
    50  func (p *LoopProcessor) OnPostDatabase(database *DBEntry) error {
    51  	if p.PostDatabaseFn != nil {
    52  		return p.PostDatabaseFn(database)
    53  	}
    54  	return nil
    55  }
    56  
    57  func (p *LoopProcessor) OnTable(table *TableEntry) error {
    58  	if p.TableFn != nil {
    59  		return p.TableFn(table)
    60  	}
    61  	return nil
    62  }
    63  
    64  func (p *LoopProcessor) OnPostTable(table *TableEntry) error {
    65  	if p.PostTableFn != nil {
    66  		return p.PostTableFn(table)
    67  	}
    68  	return nil
    69  }
    70  
    71  func (p *LoopProcessor) OnPostObject(Object *ObjectEntry) error {
    72  	if p.PostObjectFn != nil {
    73  		return p.PostObjectFn(Object)
    74  	}
    75  	return nil
    76  }
    77  
    78  func (p *LoopProcessor) OnObject(Object *ObjectEntry) error {
    79  	if p.ObjectFn != nil {
    80  		return p.ObjectFn(Object)
    81  	}
    82  	return nil
    83  }
    84  func (p *LoopProcessor) OnTombstone(tombstone data.Tombstone) error {
    85  	if p.TombstoneFn != nil {
    86  		return p.TombstoneFn(tombstone)
    87  	}
    88  	return nil
    89  }