github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/format.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 engine
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  )
    21  
    22  func (node *AttributeDef) Format(buf *bytes.Buffer) {
    23  	node.Attr.Format(buf)
    24  }
    25  
    26  func (node *Attribute) Format(buf *bytes.Buffer) {
    27  	buf.WriteString("`")
    28  	buf.WriteString(node.Name)
    29  	buf.WriteString("`")
    30  
    31  	buf.WriteByte(' ')
    32  	buf.WriteString(node.Type.String())
    33  
    34  	if node.Type.Width > 0 && node.Type.Scale > 0 {
    35  		buf.WriteString("(")
    36  		str := fmt.Sprintf("%d", node.Type.Width)
    37  		buf.WriteString(str)
    38  		buf.WriteString(", ")
    39  		buf.WriteByte(')')
    40  	} else if node.Type.Width > 0 {
    41  		buf.WriteString("(")
    42  		str := fmt.Sprintf("%d", node.Type.Width)
    43  		buf.WriteString(str)
    44  		buf.WriteByte(')')
    45  	}
    46  	if node.Default.NullAbility {
    47  		buf.WriteString(" NULL ")
    48  	}
    49  	val := node.Default.Expr.String()
    50  	if val != "" {
    51  		buf.WriteString(" DEFAULT ")
    52  		buf.WriteString(val)
    53  	}
    54  }
    55  
    56  func (node *IndexTableDef) Format(buf *bytes.Buffer) {
    57  	buf.WriteString("KEY")
    58  	buf.WriteString(" `")
    59  	buf.WriteString(node.Name)
    60  	buf.WriteString("`")
    61  
    62  	prefix := " ("
    63  	for _, c := range node.ColNames {
    64  		buf.WriteString(prefix)
    65  		buf.WriteString("`")
    66  		buf.WriteString(c)
    67  		buf.WriteString("`")
    68  		prefix = ", "
    69  	}
    70  	buf.WriteString(")")
    71  
    72  	buf.WriteString(" USING ")
    73  	buf.WriteString(node.Typ.ToString())
    74  }