github.com/matrixorigin/matrixone@v0.7.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  }
    21  
    22  func (tn TableName) Format(ctx *FmtCtx) {
    23  	if tn.ExplicitCatalog {
    24  		ctx.WriteString(string(tn.CatalogName))
    25  		ctx.WriteByte('.')
    26  	}
    27  	if tn.ExplicitSchema {
    28  		ctx.WriteString(string(tn.SchemaName))
    29  		ctx.WriteByte('.')
    30  	}
    31  	ctx.WriteString(string(tn.ObjectName))
    32  }
    33  
    34  func (tn *TableName) Name() Identifier {
    35  	return tn.ObjectName
    36  }
    37  
    38  func (tn *TableName) Schema() Identifier {
    39  	return tn.SchemaName
    40  }
    41  
    42  func (tn *TableName) Catalog() Identifier {
    43  	return tn.CatalogName
    44  }
    45  
    46  var _ TableExpr = &TableName{}
    47  
    48  // table name array
    49  type TableNames []*TableName
    50  
    51  func (node *TableNames) Format(ctx *FmtCtx) {
    52  	prefix := ""
    53  	for _, t := range *node {
    54  		ctx.WriteString(prefix)
    55  		t.Format(ctx)
    56  		prefix = ", "
    57  	}
    58  }
    59  
    60  func NewTableName(name Identifier, prefix ObjectNamePrefix) *TableName {
    61  	return &TableName{
    62  		objName: objName{
    63  			ObjectName:       name,
    64  			ObjectNamePrefix: prefix,
    65  		},
    66  	}
    67  }