github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/import.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package tree
    12  
    13  // Import represents a IMPORT statement.
    14  type Import struct {
    15  	Table      *TableName
    16  	Into       bool
    17  	IntoCols   NameList
    18  	CreateFile Expr
    19  	CreateDefs TableDefs
    20  	FileFormat string
    21  	Files      Exprs
    22  	Bundle     bool
    23  	Options    KVOptions
    24  }
    25  
    26  var _ Statement = &Import{}
    27  
    28  // Format implements the NodeFormatter interface.
    29  func (node *Import) Format(ctx *FmtCtx) {
    30  	ctx.WriteString("IMPORT ")
    31  
    32  	if node.Bundle {
    33  		if node.Table != nil {
    34  			ctx.WriteString("TABLE ")
    35  			ctx.FormatNode(node.Table)
    36  			ctx.WriteString(" FROM ")
    37  		}
    38  		ctx.WriteString(node.FileFormat)
    39  		ctx.WriteByte(' ')
    40  		ctx.FormatNode(&node.Files)
    41  	} else {
    42  		if node.Into {
    43  			ctx.WriteString("INTO ")
    44  			ctx.FormatNode(node.Table)
    45  			if node.IntoCols != nil {
    46  				ctx.WriteByte('(')
    47  				ctx.FormatNode(&node.IntoCols)
    48  				ctx.WriteString(") ")
    49  			} else {
    50  				ctx.WriteString(" ")
    51  			}
    52  		} else {
    53  			ctx.WriteString("TABLE ")
    54  			ctx.FormatNode(node.Table)
    55  
    56  			if node.CreateFile != nil {
    57  				ctx.WriteString(" CREATE USING ")
    58  				ctx.FormatNode(node.CreateFile)
    59  				ctx.WriteString(" ")
    60  			} else {
    61  				ctx.WriteString(" (")
    62  				ctx.FormatNode(&node.CreateDefs)
    63  				ctx.WriteString(") ")
    64  			}
    65  		}
    66  		ctx.WriteString(node.FileFormat)
    67  		ctx.WriteString(" DATA (")
    68  		ctx.FormatNode(&node.Files)
    69  		ctx.WriteString(")")
    70  	}
    71  
    72  	if node.Options != nil {
    73  		ctx.WriteString(" WITH ")
    74  		ctx.FormatNode(&node.Options)
    75  	}
    76  }