github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/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 FileFormat string 19 Files Exprs 20 Bundle bool 21 Options KVOptions 22 } 23 24 var _ Statement = &Import{} 25 26 // Format implements the NodeFormatter interface. 27 func (node *Import) Format(ctx *FmtCtx) { 28 ctx.WriteString("IMPORT ") 29 30 if node.Bundle { 31 if node.Table != nil { 32 ctx.WriteString("TABLE ") 33 ctx.FormatNode(node.Table) 34 ctx.WriteString(" FROM ") 35 } 36 ctx.WriteString(node.FileFormat) 37 ctx.WriteByte(' ') 38 ctx.FormatNode(&node.Files) 39 } else { 40 if node.Into { 41 ctx.WriteString("INTO ") 42 ctx.FormatNode(node.Table) 43 if node.IntoCols != nil { 44 ctx.WriteByte('(') 45 ctx.FormatNode(&node.IntoCols) 46 ctx.WriteString(") ") 47 } else { 48 ctx.WriteString(" ") 49 } 50 } else { 51 ctx.WriteString("TABLE ") 52 ctx.FormatNode(node.Table) 53 } 54 ctx.WriteString(node.FileFormat) 55 ctx.WriteString(" DATA (") 56 ctx.FormatNode(&node.Files) 57 ctx.WriteString(")") 58 } 59 60 if node.Options != nil { 61 ctx.WriteString(" WITH OPTIONS (") 62 ctx.FormatNode(&node.Options) 63 ctx.WriteString(")") 64 } 65 }