github.com/matrixorigin/matrixone@v1.2.0/pkg/pb/api/api.go (about)

     1  // Copyright 2021 - 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  package api
    15  
    16  import (
    17  	"github.com/matrixorigin/matrixone/pkg/pb/plan"
    18  )
    19  
    20  var (
    21  	OpMethodName = map[OpCode]string{
    22  		OpCode_OpPing:             "Ping",
    23  		OpCode_OpFlush:            "Flush",
    24  		OpCode_OpCheckpoint:       "Checkpoint",
    25  		OpCode_OpInspect:          "Inspect",
    26  		OpCode_OpAddFaultPoint:    "AddFaultPoint",
    27  		OpCode_OpBackup:           "Backup",
    28  		OpCode_OpTraceSpan:        "TraceSpan",
    29  		OpCode_OpGlobalCheckpoint: "GlobalCheckpoint",
    30  		OpCode_OpInterceptCommit:  "InterceptCommit",
    31  		OpCode_OpCommitMerge:      "CommitMerge",
    32  	}
    33  )
    34  
    35  func NewUpdateConstraintReq(did, tid uint64, cstr string) *AlterTableReq {
    36  	return &AlterTableReq{
    37  		DbId:    did,
    38  		TableId: tid,
    39  		Kind:    AlterKind_UpdateConstraint,
    40  		Operation: &AlterTableReq_UpdateCstr{
    41  			&AlterTableConstraint{Constraints: []byte(cstr)},
    42  		},
    43  	}
    44  }
    45  
    46  func NewUpdateCommentReq(did, tid uint64, comment string) *AlterTableReq {
    47  	return &AlterTableReq{
    48  		DbId:    did,
    49  		TableId: tid,
    50  		Kind:    AlterKind_UpdateComment,
    51  		Operation: &AlterTableReq_UpdateComment{
    52  			&AlterTableComment{Comment: comment},
    53  		},
    54  	}
    55  }
    56  
    57  func NewRenameTableReq(did, tid uint64, old, new string) *AlterTableReq {
    58  	return &AlterTableReq{
    59  		DbId:    did,
    60  		TableId: tid,
    61  		Kind:    AlterKind_RenameTable,
    62  		Operation: &AlterTableReq_RenameTable{
    63  			&AlterTableRenameTable{OldName: old, NewName: new},
    64  		},
    65  	}
    66  }
    67  
    68  func NewAddColumnReq(did, tid uint64, name string, typ *plan.Type, insertAt int32) *AlterTableReq {
    69  	return &AlterTableReq{
    70  		DbId:    did,
    71  		TableId: tid,
    72  		Kind:    AlterKind_AddColumn,
    73  		Operation: &AlterTableReq_AddColumn{
    74  			&AlterTableAddColumn{
    75  				Column: &plan.ColDef{
    76  					Name: name,
    77  					Typ:  *typ,
    78  					Default: &plan.Default{
    79  						NullAbility:  true,
    80  						Expr:         nil,
    81  						OriginString: "",
    82  					},
    83  				},
    84  				InsertPosition: insertAt,
    85  			},
    86  		},
    87  	}
    88  }
    89  
    90  func NewRemoveColumnReq(did, tid uint64, idx, seqnum uint32) *AlterTableReq {
    91  	return &AlterTableReq{
    92  		DbId:    did,
    93  		TableId: tid,
    94  		Kind:    AlterKind_DropColumn,
    95  		Operation: &AlterTableReq_DropColumn{
    96  			&AlterTableDropColumn{
    97  				LogicalIdx:  idx,
    98  				SequenceNum: seqnum,
    99  			},
   100  		},
   101  	}
   102  }
   103  
   104  func NewAddPartitionReq(did, tid uint64, partitionDef *plan.PartitionByDef) *AlterTableReq {
   105  	return &AlterTableReq{
   106  		DbId:    did,
   107  		TableId: tid,
   108  		Kind:    AlterKind_AddPartition,
   109  		Operation: &AlterTableReq_AddPartition{
   110  			AddPartition: &AlterTableAddPartition{
   111  				PartitionDef: partitionDef,
   112  			},
   113  		},
   114  	}
   115  }
   116  
   117  func NewRenameColumnReq(did, tid uint64, oldname, newname string, seqnum uint32) *AlterTableReq {
   118  	return &AlterTableReq{
   119  		DbId:    did,
   120  		TableId: tid,
   121  		Kind:    AlterKind_RenameColumn,
   122  		Operation: &AlterTableReq_RenameCol{
   123  			&AlterTableRenameCol{
   124  				OldName:     oldname,
   125  				NewName:     newname,
   126  				SequenceNum: seqnum,
   127  			},
   128  		},
   129  	}
   130  }
   131  func (m *SyncLogTailReq) MarshalBinary() ([]byte, error) {
   132  	return m.Marshal()
   133  }
   134  
   135  func (m *SyncLogTailReq) UnmarshalBinary(data []byte) error {
   136  	return m.Unmarshal(data)
   137  }
   138  
   139  func (m *SyncLogTailResp) MarshalBinary() ([]byte, error) {
   140  	return m.Marshal()
   141  }
   142  
   143  func (m *SyncLogTailResp) UnmarshalBinary(data []byte) error {
   144  	return m.Unmarshal(data)
   145  }
   146  
   147  func (m *PrecommitWriteCmd) MarshalBinary() ([]byte, error) {
   148  	return m.Marshal()
   149  }
   150  
   151  func (m *PrecommitWriteCmd) UnmarshalBinary(data []byte) error {
   152  	return m.Unmarshal(data)
   153  }
   154  
   155  func (m *MergeCommitEntry) MarshalBinary() ([]byte, error) {
   156  	return m.Marshal()
   157  }
   158  
   159  func (m *MergeCommitEntry) UnmarshalBinary(data []byte) error {
   160  	return m.Unmarshal(data)
   161  }