001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.hive.THiveFromQuerySqlNode;
005import gudusoft.gsqlparser.nodes.hive.THiveKeyValueProperty;
006import gudusoft.gsqlparser.nodes.hive.THivePartitionedTableFunction;
007import gudusoft.gsqlparser.nodes.snowflake.TAtBeforeClause;
008import gudusoft.gsqlparser.nodes.snowflake.TStageReference;
009import gudusoft.gsqlparser.nodes.teradata.THashByClause;
010import gudusoft.gsqlparser.nodes.teradata.TTDUnpivot;
011
012import java.util.ArrayList;
013
014/**
015* Represents table source in from clause of select/delete statement, and update table clause of update statement.    
016*
017*/
018public class TFromTable extends TNodeWithAliasClause{
019
020//    private TPartitionClause partitionClause;
021//
022//    public void setPartitionClause(TPartitionClause partitionClause) {
023//
024//        this.partitionClause = partitionClause;
025//    }
026//
027//    public TPartitionClause getPartitionClause() {
028//        return partitionClause;
029//    }
030
031    private TStageReference stageReference;
032
033    public TStageReference getStageReference() {
034        return stageReference;
035    }
036
037    private TAtBeforeClause timeTravelClause;
038
039    public void setTimeTravelClause(TAtBeforeClause timeTravelClause) {
040        this.timeTravelClause = timeTravelClause;
041    }
042
043    public TAtBeforeClause getTimeTravelClause() {
044        return timeTravelClause;
045    }
046    private TCaseJoinClause caseJoin;
047
048    public TCaseJoinClause getCaseJoin() {
049        return caseJoin;
050    }
051
052    private TExpression joinCondition;
053
054    public void setJoinCondition(TExpression joinCondition) {
055        this.joinCondition = joinCondition;
056    }
057
058    /**
059     * used in couchbase only
060     * @return
061     */
062    public TExpression getJoinCondition() {
063
064        return joinCondition;
065    }
066
067    private int parenthesisCount = 0;
068    private int parenthesisAfterAliasCount = 0;
069
070    public TPxGranule getPxGranule() {
071        return pxGranule;
072    }
073
074    public void incParenthesisCount(){
075        parenthesisCount++;
076    }
077
078    public void incParenthesisAfterAliasCount(){
079        parenthesisAfterAliasCount++;
080    }
081
082    public int getParenthesisCount() {
083        return parenthesisCount;
084    }
085
086    public int getParenthesisAfterAliasCount() {
087        return parenthesisAfterAliasCount;
088    }
089
090    public void setTableProperties(TPTNodeList<THiveKeyValueProperty> tableProperties) {
091        this.tableProperties = tableProperties;
092    }
093
094    /**
095     *
096     * @return hive table property list
097     */
098    public TPTNodeList<THiveKeyValueProperty> getTableProperties() {
099
100        return tableProperties;
101    }
102
103    private TPTNodeList<THiveKeyValueProperty> tableProperties;
104
105    private THiveFromQuerySqlNode fromQuerySqlNode;
106
107    private TPartitionExtensionClause partitionExtensionClause;
108
109    public TPartitionExtensionClause getPartitionExtensionClause() {
110        return partitionExtensionClause;
111    }
112
113    public void setPartitionExtensionClause(TPartitionExtensionClause partitionExtensionClause) {
114
115        this.partitionExtensionClause = partitionExtensionClause;
116    }
117
118    private TColumnDefinitionList columnDefinitions;
119
120    public TColumnDefinitionList getColumnDefinitions() {
121        return columnDefinitions;
122    }
123
124    private TValueClause valueClause;
125
126    public TValueClause getValueClause() {
127        return valueClause;
128    }
129
130    private TJsonTable jsonTable;
131
132    public TJsonTable getJsonTable() {
133        return jsonTable;
134    }
135
136    private TXmlTable xmlTable;
137
138    public TXmlTable getXmlTable() {
139        return xmlTable;
140    }
141
142    public TObjectName getTableObjectName() {
143        return tableObjectName;
144    }
145
146    public TExpression getTableExpr() {
147        return tableExpr;
148    }
149
150    public void setTableObjectName(TObjectName tableObjectName) {
151        //tableObjectName.parseTablename();
152        this.tableObjectName = tableObjectName;
153        this.tableObjectName.setObjectType(TObjectName.ttobjTable);
154        this.tableObjectName.setDbObjectType(EDbObjectType.table);
155    }
156
157    private TObjectName tableObjectName;
158
159    public TOpenQuery getOpenQuery() {
160        return openQuery;
161    }
162
163    private TPTNodeList<TTableHint> tableHintList;
164
165    public void setTableHintList(TPTNodeList<TTableHint> tableHintList) {
166        this.tableHintList = tableHintList;
167    }
168
169    public TPTNodeList<TTableHint> getTableHintList() {
170
171        return tableHintList;
172    }
173
174    public TSelectSqlNode getSubquerynode() {
175        return subquerynode;
176    }
177
178    private TSelectSqlNode subquerynode;
179    private TExpression tableExpr;
180
181    private TMultiTargetList rowList;
182
183    public TMultiTargetList getRowList() {
184        return rowList;
185    }
186
187    private TSourceToken tableonly;
188
189    private boolean tableKeyword = false;
190    private boolean onlyKeyword = false;
191
192    /**
193     * Redshift array-unnesting positional index alias.
194     * <p>
195     * In Redshift you can iterate over an array column in the FROM clause and
196     * bind a name to the element as well as to its ordinal position, e.g.
197     * <pre>FROM schema.tbl t, t.array_col AS element AT idx</pre>
198     * Here {@code element} becomes the table/element alias (the regular
199     * {@link #getAliasClause() aliasClause}) and {@code idx} is captured here as
200     * the array index alias.
201     */
202    private TObjectName arrayIndexAlias;
203
204    public TObjectName getArrayIndexAlias() {
205        return arrayIndexAlias;
206    }
207
208    public void setArrayIndexAlias(TObjectName arrayIndexAlias) {
209        this.arrayIndexAlias = arrayIndexAlias;
210    }
211
212    /**
213     * Redshift SUPER object unpivoting from-clause item, e.g.
214     * <pre>FROM c.c_orders AS o, UNPIVOT o AS val AT attr</pre>
215     * When {@code true} this from item unpivots the SUPER expression: the
216     * regular {@link #getAliasClause() aliasClause} is the value alias and
217     * {@link #getArrayIndexAlias() arrayIndexAlias} (from {@code AT}) is the
218     * attribute-name alias.
219     */
220    private boolean superUnpivot = false;
221
222    public boolean isSuperUnpivot() {
223        return superUnpivot;
224    }
225
226    public void setSuperUnpivot(boolean superUnpivot) {
227        this.superUnpivot = superUnpivot;
228    }
229
230    public boolean isTableKeyword() {
231        return tableKeyword;
232    }
233
234    public boolean isOnlyKeyword() {
235        return onlyKeyword;
236    }
237
238    public TJoinExpr getJoinExpr() {
239        return joinExpr;
240    }
241
242    private TJoinExpr joinExpr;
243
244    public ETableSource getFromtableType() {
245        return fromtableType;
246
247    }
248
249    private ETableSource fromtableType;
250
251
252    public TOpenDatasource getOpenDatasource() {
253        return openDatasource;
254    }
255
256    private TOpenDatasource openDatasource = null;
257
258    public TOpenRowSet getOpenRowSet() {
259        return openRowSet;
260    }
261
262    public TOpenXML getOpenXML() {
263        return openXML;
264    }
265
266    private TOpenXML openXML = null;
267
268    private TOpenRowSet openRowSet = null;
269
270    private TOpenQuery openQuery = null;
271    
272    public TContainsTable getContainsTable() {
273        return containsTable;
274    }
275
276    private TContainsTable containsTable = null;
277
278    public void setTableonly(TSourceToken tableonly) {
279        this.tableonly = tableonly;
280        if (tableonly.toString().equalsIgnoreCase("only")){
281            onlyKeyword = true;
282        }else if(tableonly.toString().equalsIgnoreCase("table")){
283            tableKeyword = true;
284            if (tableExpr != null){
285                fromtableType = ETableSource.tableExpr;
286            }
287        }
288    }
289
290    public void setTableSample(TTableSample tableSample) {
291        this.tableSample = tableSample;
292    }
293
294    public void setPxGranule(TPxGranule pxGranule) {
295        this.pxGranule = pxGranule;
296    }
297
298    public void setFlashback(TFlashback flashback) {
299        this.flashback = flashback;
300    }
301
302    private TTableSample tableSample;
303    private TPxGranule pxGranule;
304
305    public TFlashback getFlashback() {
306        return flashback;
307    }
308
309    private TFlashback flashback;
310
311    public TTableSample getTableSample() {
312        return tableSample;
313    }
314
315    private TDataChangeTable datachangeTable = null;
316    private TRelationExpr relationExpr;
317
318    /**
319     * Postgresql relation expr
320     * @return
321     */
322    public TRelationExpr getRelationExpr() {
323        return relationExpr;
324    }
325
326    /**
327     * DB2 data change
328     * @return
329     */
330    public TDataChangeTable getDatachangeTable() {
331        return datachangeTable;
332    }
333
334
335    public TMergeSqlNode getMergeSqlNode() {
336        return mergeSqlNode;
337    }
338
339    private TMergeSqlNode mergeSqlNode;
340    private TPivotedTable pivotedTable;
341
342    public TPivotedTable getPivotedTable() {
343        return pivotedTable;
344    }
345
346    public void setPivotClause(TPivotClause pivotClause) {
347        this.pivotClause = pivotClause;
348    }
349
350    public TPivotClause getPivotClause() {
351
352        return pivotClause;
353    }
354
355    private TPivotClause pivotClause = null;
356
357    /**
358     * a table-valued function, in SQL Server, Postgresql
359     * @return
360     */
361    public TFunctionCall getFuncCall() {
362        return funcCall;
363    }
364
365    private TFunctionCall funcCall = null;
366
367    private TInformixOuterClause outerClause;
368
369    private TFromTableList fromTableList;
370
371    public TFromTableList getFromTableList() {
372        return fromTableList;
373    }
374
375    public TInformixOuterClause getOuterClause() {
376        return outerClause;
377    }
378
379    private THivePartitionedTableFunction partitionedTableFunction;
380
381
382    public THivePartitionedTableFunction getPartitionedTableFunction() {
383        return partitionedTableFunction;
384    }
385
386    private ArrayList<TLateralView> lateralViewList;
387
388    public void setLateralViewList(ArrayList<TLateralView> lateralViewList) {
389        this.lateralViewList = lateralViewList;
390    }
391
392    /**
393     *
394     * @return hive lateral view list
395     */
396    public ArrayList<TLateralView> getLateralViewList() {
397
398        return lateralViewList;
399    }
400
401    private TExpressionList joinExprList;
402
403    public void setJoinExprList(TExpressionList joinExprList) {
404        this.joinExprList = joinExprList;
405    }
406
407    /**
408     *
409     * @return hive uniqueJoinExpr list
410     */
411    public TExpressionList getJoinExprList() {
412
413        return joinExprList;
414    }
415
416    public THiveFromQuerySqlNode getFromQuerySqlNode() {
417        return fromQuerySqlNode;
418    }
419
420    public void setColumnDefinitions(TColumnDefinitionList columnDefinitions) {
421        this.columnDefinitions = columnDefinitions;
422        if (this.columnDefinitions != null){
423            fromtableType = ETableSource.externalTable;
424        }
425    }
426
427    private TDummy tableFunctionReturn;
428
429    public void setTableFunctionReturn(TDummy tableFunctionReturn) {
430        if (tableFunctionReturn == null) return;
431        this.tableFunctionReturn = tableFunctionReturn;
432        if (this.tableFunctionReturn.list1 != null){
433            this.columnDefinitions = (TColumnDefinitionList)this.tableFunctionReturn.list1;
434        }
435    }
436
437    /**
438     * Teradata HASH BY clause for table functions.
439     * <p>
440     * Example: HASH BY col1, col2
441     */
442    private THashByClause hashByClause;
443
444    /**
445     * Gets the HASH BY clause for Teradata table functions.
446     *
447     * @return the HASH BY clause, or null if not specified
448     */
449    public THashByClause getHashByClause() {
450        return hashByClause;
451    }
452
453    /**
454     * Sets the HASH BY clause for Teradata table functions.
455     *
456     * @param hashByClause the HASH BY clause
457     */
458    public void setHashByClause(THashByClause hashByClause) {
459        this.hashByClause = hashByClause;
460    }
461
462    /**
463     * Teradata LOCAL ORDER BY clause for table functions.
464     * <p>
465     * Example: LOCAL ORDER BY col1, col2
466     */
467    private TOrderBy localOrderBy;
468
469    /**
470     * Gets the LOCAL ORDER BY clause for Teradata table functions.
471     *
472     * @return the LOCAL ORDER BY clause, or null if not specified
473     */
474    public TOrderBy getLocalOrderBy() {
475        return localOrderBy;
476    }
477
478    /**
479     * Sets the LOCAL ORDER BY clause for Teradata table functions.
480     *
481     * @param localOrderBy the LOCAL ORDER BY clause
482     */
483    public void setLocalOrderBy(TOrderBy localOrderBy) {
484        this.localOrderBy = localOrderBy;
485    }
486
487    // Constants for type codes
488    private static final int TYPE_OBJECT_NAME = 1;
489    private static final int TYPE_SELECT_SQL_NODE = 2;
490    private static final int TYPE_EXPRESSION = 3;
491    private static final int TYPE_JOIN_EXPR = 4;
492    private static final int TYPE_DUMMY = 5;
493    private static final int TYPE_CONTAINS_TABLE = 6;
494    private static final int TYPE_OPEN_ROW_SET = 7;
495    private static final int TYPE_OPEN_XML = 8;
496    private static final int TYPE_OPEN_DATASOURCE = 9;
497    private static final int TYPE_OPEN_QUERY = 10;
498    private static final int TYPE_DATA_CHANGE_TABLE = 11;
499    private static final int TYPE_RELATION_EXPR = 12;
500    private static final int TYPE_JSON_TABLE = 13;
501    private static final int TYPE_FUNCTION_CALL = 14;
502    private static final int TYPE_XML_TABLE = 15;
503    private static final int TYPE_INFORMIX_OUTER_CLAUSE = 16;
504    private static final int TYPE_FROM_TABLE_LIST = 17;
505    private static final int TYPE_HIVE_PARTITIONED_TABLE_FUNCTION = 18;
506    private static final int TYPE_HIVE_FROM_QUERY_SQL_NODE = 19;
507    private static final int TYPE_PIVOTED_TABLE = 20;
508    private static final int TYPE_MERGE_SQL_NODE = 21;
509    private static final int TYPE_TD_UNPIVOT = 22;
510    private static final int TYPE_UNNEST_CLAUSE = 23;
511    private static final int TYPE_VALUE_CLAUSE = 24;
512    private static final int TYPE_CASE_JOIN_CLAUSE = 25;
513    private static final int TYPE_STAGE_REFERENCE = 26;
514
515    public void init(Object arg1) {
516        if (arg1 == null) return;
517
518        int typeCode = getTypeCode(arg1);
519
520        switch (typeCode) {
521            case TYPE_OBJECT_NAME:
522                setTableObjectName((TObjectName) arg1);
523                fromtableType = ETableSource.objectname;
524                break;
525            case TYPE_SELECT_SQL_NODE:
526                subquerynode = (TSelectSqlNode) arg1;
527                fromtableType = ETableSource.subquery;
528                setStartToken(subquerynode.getStartToken());
529                setEndToken(subquerynode.getEndToken());
530                break;
531            case TYPE_EXPRESSION:
532                initExpression((TExpression) arg1);
533                break;
534            case TYPE_JOIN_EXPR:
535                joinExpr = (TJoinExpr) arg1;
536                fromtableType = ETableSource.join;
537                break;
538            case TYPE_DUMMY:
539                initTableDefInDummyNode((TDummy) arg1);
540                break;
541            case TYPE_CONTAINS_TABLE:
542                containsTable = (TContainsTable) arg1;
543                fromtableType = ETableSource.containsTable;
544                break;
545            case TYPE_OPEN_ROW_SET:
546                openRowSet = (TOpenRowSet) arg1;
547                fromtableType = ETableSource.openrowset;
548                break;
549            case TYPE_OPEN_XML:
550                openXML = (TOpenXML) arg1;
551                fromtableType = ETableSource.openxml;
552                break;
553            case TYPE_OPEN_DATASOURCE:
554                openDatasource = (TOpenDatasource) arg1;
555                fromtableType = ETableSource.opendatasource;
556                break;
557            case TYPE_OPEN_QUERY:
558                openQuery = (TOpenQuery) arg1;
559                fromtableType = ETableSource.openquery;
560                break;
561            case TYPE_DATA_CHANGE_TABLE:
562                datachangeTable = (TDataChangeTable) arg1;
563                fromtableType = ETableSource.datachangeTable;
564                break;
565            case TYPE_RELATION_EXPR:
566                initRelationExpr((TRelationExpr) arg1);
567                break;
568            case TYPE_JSON_TABLE:
569                jsonTable = (TJsonTable) arg1;
570                fromtableType = ETableSource.jsonTable;
571                break;
572            case TYPE_FUNCTION_CALL:
573                // This will handle TFunctionCall and all its subclasses
574                funcCall = (TFunctionCall) arg1;
575                fromtableType = ETableSource.function;
576                break;
577            case TYPE_XML_TABLE:
578                xmlTable = (TXmlTable) arg1;
579                fromtableType = ETableSource.xmltable;
580                break;
581            case TYPE_INFORMIX_OUTER_CLAUSE:
582                outerClause = (TInformixOuterClause) arg1;
583                fromtableType = ETableSource.informixOuter;
584                break;
585            case TYPE_FROM_TABLE_LIST:
586                fromTableList = (TFromTableList) arg1;
587                fromtableType = ETableSource.table_ref_list;
588                break;
589            case TYPE_HIVE_PARTITIONED_TABLE_FUNCTION:
590                partitionedTableFunction = (THivePartitionedTableFunction) arg1;
591                break;
592            case TYPE_HIVE_FROM_QUERY_SQL_NODE:
593                fromQuerySqlNode = (THiveFromQuerySqlNode) arg1;
594                fromtableType = ETableSource.hiveFromQuery;
595                break;
596            case TYPE_PIVOTED_TABLE:
597                pivotedTable = (TPivotedTable) arg1;
598                fromtableType = ETableSource.pivoted_table;
599                break;
600            case TYPE_MERGE_SQL_NODE:
601                mergeSqlNode = (TMergeSqlNode) arg1;
602                fromtableType = ETableSource.output_merge;
603                break;
604            case TYPE_TD_UNPIVOT:
605                tdUnpivot = (TTDUnpivot) arg1;
606                fromtableType = ETableSource.td_unpivot;
607                break;
608            case TYPE_UNNEST_CLAUSE:
609                unnestClause = (TUnnestClause) arg1;
610                fromtableType = ETableSource.unnest;
611                break;
612            case TYPE_VALUE_CLAUSE:
613                valueClause = (TValueClause) arg1;
614                fromtableType = ETableSource.rowList;
615                break;
616            case TYPE_CASE_JOIN_CLAUSE:
617                caseJoin = (TCaseJoinClause) arg1;
618                fromtableType = ETableSource.caseJoin;
619                break;
620            case TYPE_STAGE_REFERENCE:
621                stageReference = (TStageReference) arg1;
622                fromtableType = ETableSource.stageReference;
623                break;
624            default:
625                // Handle unexpected types or throw an exception
626                throw new IllegalArgumentException("Unexpected argument type: " + arg1.getClass().getSimpleName());
627        }
628    }
629
630    private int getTypeCode(Object arg1) {
631        if (arg1 instanceof TObjectName) return TYPE_OBJECT_NAME;
632        if (arg1 instanceof TSelectSqlNode) return TYPE_SELECT_SQL_NODE;
633        if (arg1 instanceof TExpression) return TYPE_EXPRESSION;
634        if (arg1 instanceof TJoinExpr) return TYPE_JOIN_EXPR;
635        if (arg1 instanceof TDummy) return TYPE_DUMMY;
636        if (arg1 instanceof TContainsTable) return TYPE_CONTAINS_TABLE;
637        if (arg1 instanceof TOpenRowSet) return TYPE_OPEN_ROW_SET;
638        if (arg1 instanceof TOpenXML) return TYPE_OPEN_XML;
639        if (arg1 instanceof TOpenDatasource) return TYPE_OPEN_DATASOURCE;
640        if (arg1 instanceof TOpenQuery) return TYPE_OPEN_QUERY;
641        if (arg1 instanceof TDataChangeTable) return TYPE_DATA_CHANGE_TABLE;
642        if (arg1 instanceof TRelationExpr) return TYPE_RELATION_EXPR;
643        if (arg1 instanceof TJsonTable) return TYPE_JSON_TABLE;
644        if (arg1 instanceof TFunctionCall) return TYPE_FUNCTION_CALL;
645        if (arg1 instanceof TXmlTable) return TYPE_XML_TABLE;
646        if (arg1 instanceof TInformixOuterClause) return TYPE_INFORMIX_OUTER_CLAUSE;
647        if (arg1 instanceof TFromTableList) return TYPE_FROM_TABLE_LIST;
648        if (arg1 instanceof THivePartitionedTableFunction) return TYPE_HIVE_PARTITIONED_TABLE_FUNCTION;
649        if (arg1 instanceof THiveFromQuerySqlNode) return TYPE_HIVE_FROM_QUERY_SQL_NODE;
650        if (arg1 instanceof TPivotedTable) return TYPE_PIVOTED_TABLE;
651        if (arg1 instanceof TMergeSqlNode) return TYPE_MERGE_SQL_NODE;
652        if (arg1 instanceof TTDUnpivot) return TYPE_TD_UNPIVOT;
653        if (arg1 instanceof TUnnestClause) return TYPE_UNNEST_CLAUSE;
654        if (arg1 instanceof TValueClause) return TYPE_VALUE_CLAUSE;
655        if (arg1 instanceof TCaseJoinClause) return TYPE_CASE_JOIN_CLAUSE;
656        if (arg1 instanceof TStageReference) return TYPE_STAGE_REFERENCE;
657        return 0; // Unknown type
658    }
659    private void initExpression(TExpression expr) {
660        tableExpr = expr;
661        fromtableType = ETableSource.tableExpr;
662        if (tableExpr.getExpressionType() == EExpressionType.simple_object_name_t) {
663            setTableObjectName(tableExpr.getObjectOperand());
664            fromtableType = ETableSource.objectname;
665        }
666    }
667
668    private void initRelationExpr(TRelationExpr expr) {
669        relationExpr = expr;
670        setTableObjectName(relationExpr.getRelationName());
671        fromtableType = ETableSource.objectname;
672    }
673    private TUnnestClause unnestClause;
674
675    public TUnnestClause getUnnestClause() {
676        return unnestClause;
677    }
678
679    private TTDUnpivot tdUnpivot;
680
681    public TTDUnpivot getTdUnpivot() {
682        return tdUnpivot;
683    }
684
685    private TPTNodeList <TTableHint> nameListToTableHint(Object arg1,boolean isSybaseIndexHint){
686        TPTNodeList<TTableHint> hints = new TPTNodeList<TTableHint>();
687        if (arg1 instanceof TObjectNameList){
688            TObjectNameList columns = (TObjectNameList)arg1;
689            for (int i=0;i<columns.size();i++){
690                TObjectName column = columns.getObjectName(i);
691                if ((isSybaseIndexHint)||(isSQLServerHint(column.toString()))){
692                    TTableHint tableHint = new TTableHint();
693                    tableHint.setHint(column);
694                    if (i == 0)
695                      tableHint.setStartToken(column.getStartToken());
696                    if (i == columns.size() - 1)
697                      tableHint.setEndToken(column.getStartToken());
698                    hints.addElement(tableHint);
699                }else {
700                    hints.removeAllElements();
701                    break;
702                }
703            }
704        }else if (arg1 instanceof TExpressionList){
705            TExpressionList expressionList = (TExpressionList)arg1;
706            for(int i=0;i<expressionList.size();i++){
707                TExpression expression = expressionList.getExpression(i);
708                if ((isSybaseIndexHint)||(isSQLServerHint(expression.toString()))){
709                    TTableHint tableHint = new TTableHint();
710                    tableHint.setHint(expression.getObjectOperand());
711                    if (i == 0)
712                      tableHint.setStartToken(expression.getStartToken());
713                    if (i == expressionList.size() - 1)
714                      tableHint.setEndToken(expression.getStartToken());
715                    hints.addElement(tableHint);
716                }else {
717                    hints.removeAllElements();
718                    break;
719                }
720            }
721        }
722
723        if (hints.size() > 0)
724            return hints;
725        else
726            return null;
727    }
728
729    private boolean isSQLServerHint(String pstr){
730        boolean retval = false;
731        String[] hints = new String[] {
732        "fastfirstrow","holdlock","nolock","nowait","paglock",
733       "readcommitted","readcommittedlock","readpast","readuncommitted","repeatableread",
734       "rowlock","serializable","tablock","tablockx","updlock",
735       "xlock","keepidentity","keepdefaults","ignore_constraints","ignore_triggers",
736       "index"
737        };
738
739        for(int i=0;i<21;i++)
740        {
741            if (hints[i].compareToIgnoreCase(pstr) == 0){
742                retval = true;
743                break;
744            }
745        }
746
747        return retval;
748    }
749    
750    private void initTableDefInDummyNode(TDummy pdummy){
751        fromtableType = ETableSource.objectname; //default, may change to ftt_function later
752
753       if (pdummy.int1 == 0){
754           setTableObjectName((TObjectName)(pdummy.node1));
755       }else if (pdummy.int1 == 1){
756           if (pdummy.list1 == null){
757               //it's a function
758               funcCall =  new TFunctionCall();//(TFunctionCall)createNode(ENodeType.T_FunctionCall.getId(),((TObjectName)pdummy.node1));
759               funcCall.init(((TObjectName) pdummy.node1),EFunctionType.udf_t);
760               //((TObjectName)pdummy.node1).parseFunctionName();
761               // ((TObjectName)pdummy.node1).setObjectType(TObjectName.ttobjFunctionName);
762               funcCall.setStartToken(pdummy.getStartToken());
763               funcCall.setEndToken(pdummy.getEndToken());
764               funcCall.setArgs(null);
765               fromtableType = ETableSource.function;
766           }else{
767               tableHintList = nameListToTableHint(((TExpressionList)pdummy.list1),false);
768              if ( tableHintList != null){
769              //if (isSQLServerHint(((TExpressionList)pdummy.list1).getExpression(0).toString())){
770                  //this is sql server hint, not a function, so set table name
771                  setTableObjectName((TObjectName)(pdummy.node1));
772              }else{
773                  //it's a function
774                  funcCall =  new TFunctionCall();//(TFunctionCall)createNode(ENodeType.T_FunctionCall.getId(),((TObjectName)pdummy.node1));
775                  funcCall.init(((TObjectName)pdummy.node1),EFunctionType.udf_t);
776                  //((TObjectName)pdummy.node1).parseFunctionName();
777                 // ((TObjectName)pdummy.node1).setObjectType(TObjectName.ttobjFunctionName);
778                  funcCall.setArgs((TExpressionList)pdummy.list1);
779                  fromtableType = ETableSource.function;
780                  funcCall.setStartToken(pdummy.getStartToken());
781                  funcCall.setEndToken(pdummy.getEndToken());
782              }
783           }
784       }else if (pdummy.int1 == 2){
785           setTableObjectName((TObjectName)(pdummy.node1));
786           tableHintList = nameListToTableHint(pdummy.list1,false); //sql server only, maybe deleted in future
787       }else if (pdummy.int1 == 3){
788           setTableObjectName((TObjectName)(pdummy.node1));
789           tableHintList = (TPTNodeList)(pdummy.node3); //sybase index table hint
790       }
791
792       if (pdummy.node2 != null){
793           this.setAliasClause((TAliasClause)(pdummy.node2));
794           if (this.getAliasClause().isSybaseIndexHint()){
795             tableHintList = this.getAliasClause().getTableHints();
796             this.getAliasClause().setEndToken(this.getAliasClause().getAliasName().getEndToken());
797           }else
798               if (this.getAliasClause().getColumns() != null){
799                   tableHintList = nameListToTableHint(this.getAliasClause().getColumns(),this.getAliasClause().isSybaseIndexHint());
800                   if (tableHintList != null){
801                       //this is not column list of table alias, this is table hint like NOLOCK in this sql:
802                       // SELECT COUNT(DISTINCT(SD_KEY)) FROM SHORTWINDOW PAST (NOLOCK)
803                       this.getAliasClause().setEndToken(this.getAliasClause().getAliasName().getEndToken());
804                   }
805               }
806
807       }
808
809    }
810
811    public void init(Object arg1,Object arg2)
812    {
813        init(arg1);
814        if (arg2 != null){
815            this.setAliasClause((TAliasClause)arg2);
816            // this is table alias
817            this.getAliasClause().setDBObjectToAlias(EDbObjectType.table_alias);
818        }
819    }
820
821    public void setTableProperties(TDummyList tableProperties){
822        for(int i=0;i<tableProperties.size();i++){
823            TDummy dummy = tableProperties.getDummyItem(i);
824            TParseTreeNode node = dummy.node1;
825            if (node instanceof TAliasClause){
826                this.setAliasClause( (TAliasClause)node);
827            }
828        }
829    }
830
831    public void setParenthesisCount(int parenthesisCount) {
832        this.parenthesisCount = parenthesisCount;
833    }
834
835    public void setParenthesisAfterAliasCount(int parenthesisAfterAliasCount) {
836        this.parenthesisAfterAliasCount = parenthesisAfterAliasCount;
837    }
838
839    public void setXmlTable(TXmlTable xmlTable) {
840        this.xmlTable = xmlTable;
841    }
842
843    public void setTableExpr(TExpression tableExpr) {
844        this.tableExpr = tableExpr;
845    }
846
847    public void setRowList(TMultiTargetList rowList) {
848        this.rowList = rowList;
849    }
850
851    public void setTableKeyword(boolean tableKeyword) {
852        this.tableKeyword = tableKeyword;
853    }
854
855    public void setOnlyKeyword(boolean onlyKeyword) {
856        this.onlyKeyword = onlyKeyword;
857    }
858
859    public void setJoinExpr(TJoinExpr joinExpr) {
860        this.joinExpr = joinExpr;
861    }
862
863    public void setFromtableType(ETableSource fromtableType) {
864        this.fromtableType = fromtableType;
865    }
866
867    public void setOpenDatasource(TOpenDatasource openDatasource) {
868        this.openDatasource = openDatasource;
869    }
870
871    public void setOpenXML(TOpenXML openXML) {
872        this.openXML = openXML;
873    }
874
875    public void setOpenRowSet(TOpenRowSet openRowSet) {
876        this.openRowSet = openRowSet;
877    }
878
879    public void setOpenQuery(TOpenQuery openQuery) {
880        this.openQuery = openQuery;
881    }
882
883    public void setContainsTable(TContainsTable containsTable) {
884        this.containsTable = containsTable;
885    }
886
887    public void setDatachangeTable(TDataChangeTable datachangeTable) {
888        this.datachangeTable = datachangeTable;
889    }
890
891    public void setRelationExpr(TRelationExpr relationExpr) {
892        this.relationExpr = relationExpr;
893    }
894
895    public void setPivotedTable(TPivotedTable pivotedTable) {
896        this.pivotedTable = pivotedTable;
897    }
898
899    public void setFuncCall(TFunctionCall funcCall) {
900        this.funcCall = funcCall;
901    }
902
903    public void setOuterClause(TInformixOuterClause outerClause) {
904        this.outerClause = outerClause;
905    }
906
907    public void setFromTableList(TFromTableList fromTableList) {
908        this.fromTableList = fromTableList;
909    }
910
911    public void setPartitionedTableFunction(THivePartitionedTableFunction partitionedTableFunction) {
912        this.partitionedTableFunction = partitionedTableFunction;
913    }
914
915    public void accept(TParseTreeVisitor v){
916        v.preVisit(this);
917        v.postVisit(this);
918    }
919
920    public void acceptChildren(TParseTreeVisitor v) {
921        v.preVisit(this);
922        switch (fromtableType){
923            case objectname:
924                tableObjectName.acceptChildren(v);
925                break;
926            case subquery:
927                // subquerynode
928                break;
929            case tableExpr:
930                tableExpr.acceptChildren(v);
931                break;
932            case join:
933                joinExpr.acceptChildren(v);
934                break;
935            case function:
936                funcCall.acceptChildren(v);
937                break;
938            case containsTable:
939                containsTable.acceptChildren(v);
940                break;
941            case openrowset:
942                openRowSet.acceptChildren(v);
943                break;
944            case openxml:
945                openXML.acceptChildren(v);
946                break;
947            case opendatasource:
948                openDatasource.acceptChildren(v);
949                break;
950            case openquery:
951                openQuery.acceptChildren(v);
952                break;
953            case datachangeTable:
954                datachangeTable.acceptChildren(v);
955                break;
956            case xmltable:
957                xmlTable.acceptChildren(v);
958                break;
959            case informixOuter:
960                outerClause.acceptChildren(v);
961                break;
962            case table_ref_list:
963                fromTableList.acceptChildren(v);
964                break;
965            case hiveFromQuery:
966                fromQuerySqlNode.acceptChildren(v);
967                break;
968            case pivoted_table:
969                pivotedTable.acceptChildren(v);
970                break;
971            case output_merge:
972                mergeSqlNode.acceptChildren(v);
973                break;
974            case td_unpivot:
975                tdUnpivot.acceptChildren(v);
976                break;
977            case unnest:
978                unnestClause.acceptChildren(v);
979                break;
980            case jsonTable:
981                jsonTable.acceptChildren(v);
982                break;
983            case rowList:
984                valueClause.acceptChildren(v);
985                break;
986        }
987
988        v.postVisit(this);
989    }
990}