001package gudusoft.gsqlparser.nodes;
002
003
004import gudusoft.gsqlparser.*;
005import gudusoft.gsqlparser.nodes.hive.*;
006import gudusoft.gsqlparser.nodes.oracle.TPhysicalProperties;
007import gudusoft.gsqlparser.nodes.postgresql.TPartitionBoundSpecSqlNode;
008import gudusoft.gsqlparser.nodes.teradata.TIndexDefinition;
009import gudusoft.gsqlparser.stmt.TCreateTableSqlStatement;
010import gudusoft.gsqlparser.nodes.postgresql.TInheritsClause;
011
012import java.util.ArrayList;
013import java.util.EnumSet;
014
015public class TCreateTableSqlNode extends TParseTreeNode {
016
017    private TDistributeBy distributeBy;
018
019    public void setDistributeBy(TDistributeBy distributeBy) {
020        this.distributeBy = distributeBy;
021    }
022
023    public TDistributeBy getDistributeBy() {
024        return distributeBy;
025    }
026
027    private TBaseTablePartition tablePartition;
028
029    public void setTablePartition(TBaseTablePartition tablePartition) {
030        this.tablePartition = tablePartition;
031    }
032
033    public TBaseTablePartition getTablePartition() {
034        return tablePartition;
035    }
036
037    public void setPartitionBoundSpec(TPartitionBoundSpecSqlNode partitionBoundSpec) {
038        this.partitionBoundSpec = partitionBoundSpec;
039    }
040
041    public TPartitionBoundSpecSqlNode getPartitionBoundSpec() {
042        return partitionBoundSpec;
043    }
044
045    /**
046     * postgresql PartitionBoundSpec
047     * https://www.postgresql.org/docs/current/sql-createtable.html
048     */
049    private TPartitionBoundSpecSqlNode partitionBoundSpec;
050
051    public TTableProperties getTableProperties() {
052        return tableProperties;
053    }
054
055    public void setTableProperties(TTableProperties tableProperties) {
056        this.tableProperties = tableProperties;
057    }
058
059    private TTableProperties tableProperties;
060
061    private ArrayList<TConstant> locationFiles;
062
063    public void setLocationFiles(ArrayList<TConstant> locationFiles) {
064        this.locationFiles = locationFiles;
065    }
066
067    public ArrayList<TConstant> getLocationFiles() {
068        return locationFiles;
069    }
070
071    public void setOptionStartParenthesis(TSourceToken optionStartParenthesis) {
072        this.optionStartParenthesis = optionStartParenthesis;
073    }
074
075    public void setOptionEndParenthesis(TSourceToken optionEndParenthesis) {
076        this.optionEndParenthesis = optionEndParenthesis;
077    }
078
079    public TSourceToken getOptionStartParenthesis() {
080        return optionStartParenthesis;
081    }
082
083    public TSourceToken getOptionEndParenthesis() {
084        return optionEndParenthesis;
085    }
086
087    private TSourceToken optionStartParenthesis;
088    private TSourceToken optionEndParenthesis;
089
090    private TCreateTableSqlStatement.TableSourceType tableSourceType = TCreateTableSqlStatement.TableSourceType.normal;
091
092    private TObjectName cloneSourceTable = null;
093
094    private TDummy netezzaExternalTableOption = null;
095
096    public void setCloneSourceTable(TObjectName cloneSourceTable) {
097        this.cloneSourceTable = cloneSourceTable;
098        this.tableSourceType = TCreateTableSqlStatement.TableSourceType.clone;
099    }
100
101    public TObjectName getCloneSourceTable() {
102        return cloneSourceTable;
103    }
104
105    public void setNetezzaExternalTableOption(TDummy netezzaExternalTableOption) {
106        this.netezzaExternalTableOption = netezzaExternalTableOption;
107    }
108
109    public TDummy getNetezzaExternalTableOption() {
110        return netezzaExternalTableOption;
111    }
112
113    public TObjectName getComment(){
114        return this.tableComment;
115    }
116    public void setTableOptions(ArrayList<TCreateTableOption> tableOptions) {
117
118        if (tableOptions == null) return;
119        for(TCreateTableOption option:tableOptions){
120            if (option.getCreateTableOptionType() == ECreateTableOption.etoComment){
121                this.tableComment = option.getComment();
122            }
123        }
124
125        this.tableOptions = tableOptions;
126
127    }
128
129    public void appendTableOption(TCreateTableOption tableOption) {
130        if (tableOption == null) return;
131        if (tableOptions == null){
132            tableOptions = new ArrayList<>();
133        }
134        tableOptions.add(tableOption);
135    }
136
137    public void addTableOptionByToken(TSourceToken st, ECreateTableOption createTableOption){
138        if (st == null) return;
139
140        TCreateTableOption newOption = new TCreateTableOption();
141        newOption.init(createTableOption,st);
142        switch (createTableOption){
143            case etoFileFormat:
144                newOption.setFileFormatType(st);
145                break;
146            case etoEncoding:
147                newOption.setEncoding(st);
148                break;
149        }
150
151        if (tableOptions == null){
152            tableOptions = new ArrayList<>();
153        }
154
155        tableOptions.add(newOption);
156    }
157    public ArrayList<TCreateTableOption> getTableOptions() {
158        return tableOptions;
159    }
160
161    private ArrayList<TCreateTableOption> tableOptions;
162
163    public void setOnFilegroup(TDummy onFilegroup) {
164        this.onFilegroup = onFilegroup;
165    }
166
167    public TDummy getOnFilegroup() {
168        return onFilegroup;
169    }
170
171    private TDummy onFilegroup = null;
172
173    private TPhysicalProperties physicalProperties;
174
175    public void setPhysicalProperties(TPhysicalProperties physicalProperties) {
176        this.physicalProperties = physicalProperties;
177    }
178
179    public void setTableOption(TCreateTableOption option){
180        if (option == null) return;
181        if (this.tableOptions == null){
182            this.tableOptions = new ArrayList<>();
183        }
184        this.tableOptions.add(option);
185    }
186
187    /**
188     * Oracle physical properties
189     *
190     * @return Oracle physical properties
191     */
192    public TPhysicalProperties getPhysicalProperties() {
193        return physicalProperties;
194    }
195
196    public void setTableKindByToken(TSourceToken st){
197        if (st == null) return;
198        if (st.toString().equalsIgnoreCase("set")){
199            tableKinds.add(ETableKind.etkSet);
200        }else if (st.toString().equalsIgnoreCase("multiset")){
201            tableKinds.add(ETableKind.etkMultiset);
202        }else if (st.toString().equalsIgnoreCase("volatile")){
203            tableKinds.add(ETableKind.etkVolatile);
204        }else if (st.toString().equalsIgnoreCase("global")){
205            tableKinds.add(ETableKind.etkGlobalTemporary);
206        }else if (st.toString().equalsIgnoreCase("temporary")){
207            tableKinds.add(ETableKind.etkTemporary);
208        }else if (st.toString().equalsIgnoreCase("temp")){
209            tableKinds.add(ETableKind.etkTemp);
210        }else if (st.toString().equalsIgnoreCase("external")){
211            tableKinds.add(ETableKind.etkExternal);
212            this.external = true;
213        }
214    }
215    public void setTableKindByNode(TDummy node) {
216        if ((TDummy) node.node1 == null) return;
217        TDummy node2 = (TDummy) node.node1;
218        setTableKindByToken(node2.st1);
219        setTableKindByToken(node2.st2);
220    }
221
222    private EnumSet<ETableKind> tableKinds = EnumSet.noneOf(ETableKind.class);
223
224    public void setTableKinds(EnumSet<ETableKind> tableKinds) {
225        this.tableKinds = tableKinds;
226    }
227
228    public EnumSet<ETableKind> getTableKinds() {
229
230        return tableKinds;
231    }
232
233    //private TObjectName asTableName;
234    private TTable asTable = null;
235
236    public TTable getAsTable() {
237        return asTable;
238    }
239
240    public void setAsTableName(TObjectName asTableName) {
241        asTable = new TTable();
242        asTableName.setObjectType(TObjectName.ttobjTable);
243        asTable.setTableName(asTableName);
244        asTable.setTableType(ETableSource.objectname);
245        asTable.setEffectType(ETableEffectType.tetCreateAs);
246    }
247
248
249
250    public void setExternalTable(boolean externalTable) {
251        this.externalTable = externalTable;
252    }
253
254    /**
255     * @deprecated As of v1.9.7.2 , replace by {@link #isExternal}
256     *
257     * @return true if it's an external table
258     */
259    public boolean isExternalTable() {
260
261        return externalTable;
262    }
263
264    private boolean externalTable;
265
266    private ArrayList <TIndexDefinition> indexDefinitions;
267
268    public void setIndexDefinitions(ArrayList<TIndexDefinition> indexDefinitions) {
269        this.indexDefinitions = indexDefinitions;
270    }
271
272    public ArrayList<TIndexDefinition> getIndexDefinitions() {
273
274        return indexDefinitions;
275    }
276
277    private boolean readable = false;
278    private boolean writable = false;
279    private boolean webTable = false;
280
281    public void setWebTable(boolean webTable) {
282        this.webTable = webTable;
283    }
284
285    public boolean isWebTable() {
286        return webTable;
287    }
288
289    private TConstant executeCmd;
290
291    public void setExecuteCmd(TConstant executeCmd) {
292        this.executeCmd = executeCmd;
293    }
294
295    public TConstant getExecuteCmd() {
296        return executeCmd;
297    }
298
299    public void setReadWritableByToken(TSourceToken st){
300        if (st == null) return;
301        if (st.toString().equalsIgnoreCase("readable")){
302            readable = true;
303        }else if (st.toString().equalsIgnoreCase("writable")){
304            writable = true;
305        }
306    }
307
308    public boolean isReadable() {
309        return readable;
310    }
311
312    public boolean isWritable() {
313        return writable;
314    }
315
316    private boolean external;
317    private boolean ifNotExists;
318    private TObjectName tableLocation;
319    private TObjectName tableComment;
320    private THiveTableProperties hiveTableProperties;
321    private THiveTablePartition hiveTablePartition;
322    private THiveTableBuckets hiveTableBuckets;
323    private THiveTableSkewed hiveTableSkewed;
324    private THiveRowFormat hiveRowFormat;
325    private THiveTableFileFormat hiveTableFileFormat;
326    private TObjectName likeTableName;
327
328    public void setDummyOfTemp(TDummy dummy){
329        if (dummy == null) return;
330        if (dummy.st1.toString().equalsIgnoreCase("external")){
331            this.external = true;
332        }
333    }
334
335    public void setExternal(boolean external) {
336        this.external = external;
337    }
338
339    public void setHiveRowFormat(THiveRowFormat hiveRowFormat) {
340        this.hiveRowFormat = hiveRowFormat;
341    }
342
343    public void setHiveTableBuckets(THiveTableBuckets hiveTableBuckets) {
344        this.hiveTableBuckets = hiveTableBuckets;
345    }
346
347    public void setHiveTableFileFormat(THiveTableFileFormat hiveTableFileFormat) {
348        this.hiveTableFileFormat = hiveTableFileFormat;
349    }
350
351    public void setHiveTablePartition(THiveTablePartition hiveTablePartition) {
352        this.hiveTablePartition = hiveTablePartition;
353    }
354
355    public void setHiveTableProperties(THiveTableProperties hiveTableProperties) {
356        this.hiveTableProperties = hiveTableProperties;
357    }
358
359    public void setHiveTableSkewed(THiveTableSkewed hiveTableSkewed) {
360        this.hiveTableSkewed = hiveTableSkewed;
361    }
362
363    public void setIfNotExists(boolean ifNotExists) {
364        this.ifNotExists = ifNotExists;
365    }
366
367    public void setLikeTableName(TObjectName likeTableName) {
368        if ((likeTableName != null)&&(tableSourceType == TCreateTableSqlStatement.TableSourceType.normal)){
369           tableSourceType = TCreateTableSqlStatement.TableSourceType.like;
370        }
371        this.likeTableName = likeTableName;
372    }
373
374    public void setTableComment(TObjectName tableComment) {
375        this.tableComment = tableComment;
376    }
377
378    public void setTableLocation(TObjectName tableLocation) {
379        this.tableLocation = tableLocation;
380    }
381
382    public boolean isExternal() {
383
384        return external;
385    }
386
387    public THiveRowFormat getHiveRowFormat() {
388        return hiveRowFormat;
389    }
390
391    public THiveTableBuckets getHiveTableBuckets() {
392        return hiveTableBuckets;
393    }
394
395    public THiveTableFileFormat getHiveTableFileFormat() {
396        return hiveTableFileFormat;
397    }
398
399    public THiveTablePartition getHiveTablePartition() {
400        return hiveTablePartition;
401    }
402
403    public THiveTableProperties getHiveTableProperties() {
404        return hiveTableProperties;
405    }
406
407    public THiveTableSkewed getHiveTableSkewed() {
408        return hiveTableSkewed;
409    }
410
411    public boolean isIfNotExists() {
412        return ifNotExists;
413    }
414
415    public TObjectName getLikeTableName() {
416        return likeTableName;
417    }
418
419    public TObjectName getTableComment() {
420        return tableComment;
421    }
422
423    public TObjectName getTableLocation() {
424        return tableLocation;
425    }
426
427    private TObjectName rowTypeName;
428    private TObjectName superTableName;
429
430    public void setRowTypeName(TObjectName rowTypeName) {
431        this.rowTypeName = rowTypeName;
432    }
433
434    public void setSuperTableName(TObjectName superTableName) {
435        this.superTableName = superTableName;
436    }
437
438    public TObjectName getRowTypeName() {
439
440        return rowTypeName;
441    }
442
443    public TObjectName getSuperTableName() {
444        return superTableName;
445    }
446
447
448    private TPTNodeList <TMySQLCreateTableOption> mySQLTableOptionList;
449
450    public void setMySQLTableOptionList(TPTNodeList<TMySQLCreateTableOption> mySQLTableOptionList) {
451        this.mySQLTableOptionList = mySQLTableOptionList;
452    }
453
454    public TPTNodeList<TMySQLCreateTableOption> getMySQLTableOptionList() {
455
456        return mySQLTableOptionList;
457    }
458
459    private TTable table = null;
460
461    public void setTableElementList(TTableElementList tableElementList) {
462        this.tableElementList = tableElementList;
463    }
464
465    private TTableElementList tableElementList = null;
466
467    public TObjectNameList getColumnList() {
468        return columnList;
469    }
470
471    public TTableElementList getTableElementList() {
472        return tableElementList;
473    }
474
475    public TTable getTable() {
476
477        return table;
478    }
479
480    public void setColumnList(TObjectNameList columnList) {
481        this.columnList = columnList;
482    }
483
484    public TSelectSqlNode getSubQueryNode() {
485        return subQueryNode;
486    }
487
488    private TObjectNameList columnList = null;
489    private TSelectSqlNode subQueryNode = null;
490
491    public void setExecuteSqlNode(TExecuteSqlNode executeSqlNode) {
492        this.executeSqlNode = executeSqlNode;
493    }
494
495    public TExecuteSqlNode getExecuteSqlNode() {
496
497        return executeSqlNode;
498    }
499
500    private TExecuteSqlNode executeSqlNode = null;//greenplum
501
502    public void setSubQueryNode(TSelectSqlNode subQueryNode) {
503        if (subQueryNode != null){
504            this.subQueryNode = subQueryNode;
505            tableSourceType = TCreateTableSqlStatement.TableSourceType.subquery;
506        }
507
508    }
509
510    public void init(Object arg1)
511    {
512        table = new TTable();
513        ((TObjectName)arg1).setObjectType(TObjectName.ttobjTable);
514        table.setTableName((TObjectName)arg1);
515        table.setTableType(ETableSource.objectname);
516        table.setEffectType(ETableEffectType.tetCreate);
517        table.setGsqlparser(((TObjectName)arg1).getGsqlparser());
518        if (table.getTableName().toString().startsWith("#")){
519            this.getTableKinds().add(ETableKind.etkTemporary);
520            table.getTableName().setTableKind(ETableKind.etkTemporary);
521        }
522    }
523
524    public TCreateTableSqlStatement.TableSourceType getTableSourceType() {
525        return tableSourceType;
526    }
527
528    public void init(Object arg1, Object arg2){
529        tableSourceType = (TCreateTableSqlStatement.TableSourceType)arg1;
530        init(arg2);
531    }
532
533    public void setInheritsClause(TInheritsClause inheritsClause) {
534        this.inheritsClause = inheritsClause;
535    }
536
537    public TInheritsClause getInheritsClause() {
538        return inheritsClause;
539    }
540
541    private TInheritsClause inheritsClause;
542}