001package gudusoft.gsqlparser.nodes; 002 003import gudusoft.gsqlparser.EExpressionType; 004import gudusoft.gsqlparser.TBaseType; 005import gudusoft.gsqlparser.TSourceToken; 006import gudusoft.gsqlparser.nodes.oracle.TErrorLoggingClause; 007 008import java.util.ArrayList; 009 010/** 011 * Interal used by parser. 012*/ 013public class TInsertSqlNode extends TParseTreeNode { 014 015 private String fileFormat; 016 private String fileOptions = null; 017 018 public String getFileFormat() { 019 return fileFormat; 020 } 021 022 public String getFileOptions() { 023 return fileOptions; 024 } 025 026 public void setFileFormat(TDummy dummy){ 027 fileFormat = dummy.st1.toString(); 028 if (dummy.node1 != null){ 029 fileOptions = dummy.node1.toString(); 030 } 031 } 032 033 private TObjectName sourceValueTable; 034 035 public TObjectName getSourceValueTable() { 036 return sourceValueTable; 037 } 038 039 private boolean insertAll = false; 040 private boolean insertFirst = false; 041 042 public boolean isInsertAll() { 043 return insertAll; 044 } 045 046 public boolean isInsertFirst() { 047 return insertFirst; 048 } 049 050 public void setInsertAllOrFirst(TSourceToken st){ 051 if (st == null) return; 052 insertAll = st.toString().equalsIgnoreCase("all"); 053 insertFirst = st.toString().equalsIgnoreCase("first"); 054 } 055 056 private TErrorLoggingClause errorLoggingClause; 057 058 public void setErrorLoggingClause(TErrorLoggingClause errorLoggingClause) { 059 this.errorLoggingClause = errorLoggingClause; 060 } 061 062 public TErrorLoggingClause getErrorLoggingClause() { 063 064 return errorLoggingClause; 065 } 066 067 public void setDirectoryName(TObjectName directoryName) { 068 this.directoryName = directoryName; 069 } 070 071 072 public void setOverwrite(TSourceToken overwrite) { 073 if (overwrite == null) return; 074 if (overwrite.toString().equalsIgnoreCase("overwrite")) { 075 this.hiveInsertType = EHiveInsertType.overwriteTable; 076 } 077 return; 078 } 079 080 081 public void setHiveInsertType(EHiveInsertType hiveInsertType) { 082 083 this.hiveInsertType = hiveInsertType; 084 this.valueType = TBaseType.vt_hive; 085 } 086 087 private EHiveInsertType hiveInsertType = EHiveInsertType.intoUnknown; 088 private TObjectName directoryName; 089 090 public EHiveInsertType getHiveInsertType() { 091 return hiveInsertType; 092 } 093 094 public TObjectName getDirectoryName() { 095 return directoryName; 096 } 097 //private THiveTableOrPartition tableOrPartition; 098 099 private TPTNodeList<TInsertCondition> insertConditions; 100 101 public void init(Object arg1){ 102 directoryName = (TObjectName)arg1; 103 } 104 105 public TCTEList getCteList() { 106 return cteList; 107 } 108 109 public TPTNodeList<TInsertCondition> getInsertConditions() { 110 return insertConditions; 111 } 112 113 public TPTNodeList<TInsertIntoValue> getInsertIntoValues() { 114 return insertIntoValues; 115 } 116 117 public void setInsertConditions(TPTNodeList<TInsertCondition> insertConditions) { 118 this.insertConditions = insertConditions; 119 } 120 121 private TPTNodeList<TInsertIntoValue> elseIntoValues; 122 123 public void setElseIntoValues(TPTNodeList<TInsertIntoValue> elseIntoValues) { 124 this.elseIntoValues = elseIntoValues; 125 } 126 127 public TPTNodeList<TInsertIntoValue> getElseIntoValues() { 128 129 return elseIntoValues; 130 } 131 132 private TPTNodeList<TInsertIntoValue> insertIntoValues; 133 134 public void setInsertIntoValues(TPTNodeList<TInsertIntoValue> insertIntoValues) { 135 this.insertIntoValues = insertIntoValues; 136 } 137 138 public void setInsertToken(TSourceToken insertToken) { 139 this.insertToken = insertToken; 140 } 141 142 public TSourceToken getInsertToken() { 143 144 return insertToken; 145 } 146 147 private TSourceToken insertToken = null; 148 149 public TSelectSqlNode getSubQueryNode() { 150 return subQueryNode; 151 } 152 153 public TMultiTargetList getValues() { 154 155 return values; 156 } 157 158 public void setSubQueryNode(TSelectSqlNode subQueryNode) { 159 this.subQueryNode = subQueryNode; 160 this.valueType = TBaseType.vt_query; 161 if (this.valueType == TBaseType.vt_hive){ 162 this.valueType = TBaseType.vt_hive_query; 163 } 164 } 165 166 public int getValueType() { 167 168 return valueType; 169 } 170 171 public void setValueType(int valueType) { 172 this.valueType = valueType; 173 } 174 175 private int valueType = TBaseType.vt_values; 176 177 public TCTEList cteList = null; 178 private TTopClause topClause = null; 179 180 public TReturningClause getReturningClause() { 181 return returningClause; 182 } 183 184 public TObjectNameList getColumnList() { 185 186 return columnList; 187 } 188 189 public TOutputClause getOutputClause() { 190 191 return outputClause; 192 } 193 194 public TFromTable getTargetTable() { 195 196 return targetTable; 197 } 198 199 public TTopClause getTopClause() { 200 201 return topClause; 202 } 203 204 private TOutputClause outputClause = null; 205 private TFromTable targetTable = null; 206 private TObjectNameList columnList = null; 207 private TReturningClause returningClause = null; 208 private TResultColumnList onDuplicateKeyUpdate = null; 209 210 public void setOnDuplicateKeyUpdate(TResultColumnList onDuplicateKeyUpdate) { 211 this.onDuplicateKeyUpdate = onDuplicateKeyUpdate; 212 } 213 214 public TResultColumnList getOnDuplicateKeyUpdate() { 215 216 return onDuplicateKeyUpdate; 217 } 218 219 private TSourceToken ignore; 220 private TSourceToken priority_delayed; 221 222 public void setIgnore(TSourceToken ignore) { 223 this.ignore = ignore; 224 } 225 226 public void setPriority_delayed(TSourceToken priority_delayed) { 227 this.priority_delayed = priority_delayed; 228 } 229 230 public TSourceToken getIgnore() { 231 232 return ignore; 233 } 234 235 public TSourceToken getPriority_delayed() { 236 return priority_delayed; 237 } 238 239 public void setReturningClause(TReturningClause returningClause) { 240 this.returningClause = returningClause; 241 } 242 243 /* 244 * this function was used in teradata y file to support syntax like this: 245 * insert into t(v1,v2,v3) 246 * @param columnList 247 */ 248 public void setColumnListByResultColumnList(TResultColumnList columnList){ 249 // expression in resultcolumn must be type TExpression.SimpleObject 250 this.columnList = new TObjectNameList(); 251 TResultColumn column = null; 252 TExpression expr = null; 253 for(int i=0; i<columnList.size();i++){ 254 column = columnList.getResultColumn(i); 255 expr = column.getExpr(); 256 if (expr.getExpressionType() == EExpressionType.simple_object_name_t){ 257 this.columnList.addObjectName(expr.getObjectOperand()); 258 } 259 } 260 } 261 262 public void setColumnList(TObjectNameList columnList) { 263 this.columnList = columnList; 264 } 265 266 public void setTargetTable(TFromTable targetTable) { 267 this.targetTable = targetTable; 268 } 269 270 public void setTargetTable(TDummy targetTableAndColumns) { 271 this.targetTable = (TFromTable) targetTableAndColumns.node1; 272 if (targetTableAndColumns.objectNameList != null){ 273 this.columnList = targetTableAndColumns.objectNameList; 274 } 275 if (targetTableAndColumns.node2 != null){ 276 this.subQueryNode = (TSelectSqlNode) targetTableAndColumns.node2; 277 this.valueType = TBaseType.vt_query; 278 } 279 } 280 281 public void setOutputClause(TOutputClause outputClause) { 282 this.outputClause = outputClause; 283 } 284 285 public void setTopClause(TTopClause topClause) { 286 this.topClause = topClause; 287 } 288 289 private TMultiTargetList values = null; 290 private TSelectSqlNode subQueryNode = null; 291 private TExecuteSqlNode executeSqlNode = null; 292 293 public TFunctionCall getFunctionCall() { 294 return functionCall; 295 } 296 297 private TFunctionCall functionCall = null; 298 299 /* 300 * this function was used in teradata y file to support syntax like this: 301 * insert into t(v1,v2,v3) 302 */ 303 304 public TObjectName getRecordName() { 305 return recordName; 306 } 307 308 private TObjectName recordName = null; 309 310 public void setValuesByMultiTarget(TMultiTarget mt){ 311 this.valueType = TBaseType.vt_values; 312 values = new TMultiTargetList(); 313 values.addMultiTarget(mt); 314 } 315 316 public void setValuesByMultiTargetList(TMultiTargetList mtList){ 317 this.valueType = TBaseType.vt_values; 318 values = mtList; 319 } 320 321 private TResultColumnList setColumnValues = null; 322 323 public TResultColumnList getSetColumnValues() { 324 return setColumnValues; 325 } 326 327 private TIsolationClause isolationClause = null; 328 329 public void setIsolationClause(TIsolationClause isolationClause) { 330 this.isolationClause = isolationClause; 331 } 332 333 public TIsolationClause getIsolationClause() { 334 return isolationClause; 335 } 336 337 public TExecuteSqlNode getExecuteSqlNode() { 338 return executeSqlNode; 339 } 340 341 public void setValues(TDummy dummyNode){ 342 valueType = dummyNode.int1; 343 switch(valueType){ 344 case TBaseType.vt_values: 345 values = (TMultiTargetList)dummyNode.list1; 346 break; 347 case TBaseType.vt_query: 348 subQueryNode = (TSelectSqlNode)dummyNode.node1; 349 break; 350 case TBaseType.vt_default_values: 351 break; 352 case TBaseType.vt_execute: 353 executeSqlNode = (TExecuteSqlNode)dummyNode.node1; 354 break; 355 case TBaseType.vt_values_function: 356 357 functionCall = (TFunctionCall)dummyNode.node1; 358 break; 359 case TBaseType.vt_values_oracle_record: 360 recordName = (TObjectName)dummyNode.node1; 361 break; 362 case TBaseType.vt_values_empty: 363 break; 364 case TBaseType.vt_set_column_value: 365 this.setColumnValues = (TResultColumnList)dummyNode.list1; 366 break; 367 case TBaseType.vt_table: 368 this.sourceValueTable = (TObjectName) dummyNode.node1; 369 break; 370 } 371 } 372 373 private ArrayList<TInsertSqlNode> insertSqlNodes; 374 375 public ArrayList<TInsertSqlNode> getInsertSqlNodes() { 376 return insertSqlNodes; 377 } 378 379 public void setInsertSqlNodes(ArrayList<TInsertSqlNode> insertSqlNodes) { 380 this.insertSqlNodes = insertSqlNodes; 381 } 382 383 public static void setFromList(ArrayList<TInsertSqlNode> insertSqlNodes, TFromTableList fromTables){ 384 for(int i=0;i<insertSqlNodes.size();i++){ 385 TInsertSqlNode insertSqlNode = insertSqlNodes.get(i); 386 insertSqlNode.getSubQueryNode().setFromTableList(fromTables); 387 } 388 } 389 390 public static TInsertSqlNode getFirstInsertSqlNode(ArrayList<TInsertSqlNode> insertSqlNodes){ 391 return insertSqlNodes.get(0); 392 } 393}