github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/table_name.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 tree 16 17 type TableName struct { 18 TableExpr 19 objName 20 AtTsExpr *AtTimeStamp 21 } 22 23 func (tn TableName) Format(ctx *FmtCtx) { 24 if tn.ExplicitCatalog { 25 ctx.WriteString(string(tn.CatalogName)) 26 ctx.WriteByte('.') 27 } 28 if tn.ExplicitSchema { 29 ctx.WriteString(string(tn.SchemaName)) 30 ctx.WriteByte('.') 31 } 32 ctx.WriteString(string(tn.ObjectName)) 33 if tn.AtTsExpr != nil { 34 ctx.WriteString("{") 35 tn.AtTsExpr.Format(ctx) 36 ctx.WriteString("}") 37 } 38 } 39 40 func (tn *TableName) Name() Identifier { 41 return tn.ObjectName 42 } 43 44 func (tn *TableName) Schema() Identifier { 45 return tn.SchemaName 46 } 47 48 func (tn *TableName) Catalog() Identifier { 49 return tn.CatalogName 50 } 51 52 var _ TableExpr = &TableName{} 53 54 // table name array 55 type TableNames []*TableName 56 57 func (node *TableNames) Format(ctx *FmtCtx) { 58 prefix := "" 59 for _, t := range *node { 60 ctx.WriteString(prefix) 61 t.Format(ctx) 62 prefix = ", " 63 } 64 } 65 66 func NewTableName(name Identifier, prefix ObjectNamePrefix, AtTsExpr *AtTimeStamp) *TableName { 67 return &TableName{ 68 objName: objName{ 69 ObjectName: name, 70 ObjectNamePrefix: prefix, 71 }, 72 AtTsExpr: AtTsExpr, 73 } 74 } 75 76 type AtTimeStamp struct { 77 Type ATTimeStampType 78 Expr Expr 79 } 80 81 func (node *AtTimeStamp) Format(ctx *FmtCtx) { 82 ctx.WriteString(node.Type.String()) 83 ctx.WriteString(" = ") 84 node.Expr.Format(ctx) 85 } 86 87 type ATTimeStampType int 88 89 const ( 90 ATTIMESTAMPNONE ATTimeStampType = iota 91 ATTIMESTAMPTIME 92 ATTIMESTAMPSNAPSHOT 93 ATMOTIMESTAMP 94 ) 95 96 func (a ATTimeStampType) String() string { 97 switch a { 98 case ATTIMESTAMPNONE: // none 99 return "none" 100 case ATTIMESTAMPTIME: // format: {timestamp = expr} 101 return "timestamp" 102 case ATTIMESTAMPSNAPSHOT: // format: {snapshot = expr} 103 return "snapshot" 104 case ATMOTIMESTAMP: // format: {mo-timestamp = expr} 105 return "mo-timestamp" 106 } 107 return "unknown" 108 }