001package gudusoft.gsqlparser.stmt.snowflake; 002 003 004import gudusoft.gsqlparser.EDbVendor; 005import gudusoft.gsqlparser.ESqlClause; 006import gudusoft.gsqlparser.ESqlStatementType; 007import gudusoft.gsqlparser.TCustomSqlStatement; 008import gudusoft.gsqlparser.nodes.TCreateTableOption; 009import gudusoft.gsqlparser.nodes.TObjectName; 010import gudusoft.gsqlparser.nodes.TObjectNameList; 011import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 012import gudusoft.gsqlparser.nodes.TStageLocation; 013import gudusoft.gsqlparser.nodes.snowflake.TCopyIntoNode; 014import gudusoft.gsqlparser.stmt.TSelectSqlStatement; 015 016import java.util.ArrayList; 017 018public class TSnowflakeCopyIntoStmt extends TCustomSqlStatement { 019 020 private ArrayList<String> fileList = new ArrayList<>(); 021 022 023 public ArrayList<String> getFileList() { 024 return fileList; 025 } 026 027 private String fileFormatName = null; 028 private String fileFormatType = null; 029 030 public void setFileFormatName(String fileFormatName) { 031 this.fileFormatName = fileFormatName; 032 } 033 034 public void setFileFormatType(String fileFormatType) { 035 this.fileFormatType = fileFormatType; 036 } 037 038 public String getFileFormatName() { 039 return fileFormatName; 040 } 041 042 public String getFileFormatType() { 043 return fileFormatType; 044 } 045 046 public static int COPY_INTO_TABLE = 0; 047 public static int COPY_INTO_LOCATION = 1; 048 049 private String regex_pattern; 050 051 public void setRegex_pattern(String regex_pattern) { 052 this.regex_pattern = regex_pattern; 053 } 054 055 public String getRegex_pattern() { 056 return regex_pattern; 057 } 058 059 private int copyIntoType = TSnowflakeCopyIntoStmt.COPY_INTO_TABLE; 060 061 public int getCopyIntoType() { 062 return copyIntoType; 063 } 064 065 private TStageLocation stageLocation; 066 067 public TStageLocation getStageLocation() { 068 return stageLocation; 069 } 070 071 private TObjectName tableName; 072 private TSelectSqlStatement subQuery; 073 public TSnowflakeCopyIntoStmt(EDbVendor dbvendor) { 074 super(dbvendor); 075 sqlstatementtype = ESqlStatementType.sstCopyInto; 076 } 077 078 public void setTableName(TObjectName tableName) { 079 this.tableName = tableName; 080 } 081 082 public void setSubQuery(TSelectSqlStatement subQuery) { 083 this.subQuery = subQuery; 084 } 085 086 public TObjectName getTableName() { 087 088 return tableName; 089 } 090 091 public TSelectSqlStatement getSubQuery() { 092 return subQuery; 093 } 094 095 private TObjectName fromSourceLocation; 096 public TObjectName getFromSourceLocation() { 097 return fromSourceLocation; 098 } 099 100 private TObjectNameList tableColumnList; 101 102 public void setTableColumnList(TObjectNameList tableColumnList) { 103 this.tableColumnList = tableColumnList; 104 } 105 106 public TObjectNameList getTableColumnList() { 107 return tableColumnList; 108 } 109 110 111 public int doParseStatement(TCustomSqlStatement psql) { 112 if (rootNode == null) return -1; 113 super.doParseStatement(psql); 114 TCopyIntoNode node = (TCopyIntoNode)(rootNode); 115 tableName = node.getTableName(); 116 this.copyIntoType = node.getCopyIntoType(); 117 this.stageLocation = node.getStageLocation(); 118 119 if (node.getSubquery() != null){ 120 subQuery = new TSelectSqlStatement(this.dbvendor); 121 subQuery.rootNode = node.getSubquery(); 122 subQuery.doParseStatement(this); 123 } 124 125 ArrayList<TCreateTableOption> tableOptions = node.tableOptions; 126 if (tableOptions != null){ 127 for(int i=0;i<tableOptions.size();i++){ 128 tableOptions.get(i).doParse(this, ESqlClause.unknown); 129 } 130 } 131 132 fromSourceLocation = node.getFromSourceLocation(); 133 tableColumnList = node.getTableColumnList(); 134 135 return 0; 136 } 137 138 public void accept(TParseTreeVisitor v){ 139 v.preVisit(this); 140 v.postVisit(this); 141 } 142 143 public void acceptChildren(TParseTreeVisitor v){ 144 v.preVisit(this); 145 if (this.subQuery != null){ 146 this.subQuery.acceptChildren(v); 147 } 148 v.postVisit(this); 149 } 150 151}