001package gudusoft.gsqlparser.nodes;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.stmt.TSelectSqlStatement;
005
006
007public class TGroupByItem extends TParseTreeNode {
008
009    public void setGroupingSetType(EGroupingSetType groupingSetType) {
010        this.groupingSetType = groupingSetType;
011    }
012
013    public EGroupingSetType getGroupingSetType() {
014        return groupingSetType;
015    }
016
017    private EGroupingSetType groupingSetType;
018
019    private TExpression expr = null;
020    private TRollupCube rollupCube = null;
021    private TGroupingSet groupingSet = null;
022    private TExpressionList exprList = null;
023
024    /**
025     * @deprecated As of v1.6.4.9, use {@link #getExpr()} instead
026     * @return expression list
027     */
028    public TExpressionList getExprList() {
029        return exprList;
030    }
031
032    public TExpression getExpr() {
033        return expr;
034    }
035
036    public TGroupingSet getGroupingSet() {
037        return groupingSet;
038    }
039
040    public void setExpr(TExpression expr) {
041        this.expr = expr;
042    }
043
044    public TRollupCube getRollupCube() {
045        return rollupCube;
046    }
047
048    public void init(Object arg1)
049    {
050        if (arg1 instanceof TExpression)
051            {expr = (TExpression)arg1;}
052        else if (arg1 instanceof TRollupCube){
053            {rollupCube = (TRollupCube)arg1;}
054        }
055        else if (arg1 instanceof TGroupingSet){
056            {groupingSet = (TGroupingSet)arg1;}
057        }else if (arg1 instanceof TExpressionList){
058            exprList = (TExpressionList)arg1;
059        }
060    }
061
062    public void init(Object arg1,Object arg2){
063        groupingSetType =(EGroupingSetType)arg1;
064        switch (groupingSetType){
065            case gsEmpty:
066                break;
067            case gsExpr:
068                expr = (TExpression)arg2;
069                break;
070            case gsList:
071                exprList = (TExpressionList)arg2;
072                break;
073            case gsCube:
074                rollupCube = (TRollupCube)arg2;
075                break;
076            case gsRollup:
077                rollupCube = (TRollupCube)arg2;
078                break;
079        }
080    }
081
082    public void doParse(TCustomSqlStatement psql, ESqlClause plocation){
083        if (expr != null){
084           // System.out.println(expr.getObjectOperand());
085            //let check is this column of column alias in select list
086            if ((psql instanceof TSelectSqlStatement) && (expr.getExpressionType() == EExpressionType.simple_object_name_t)){
087                TObjectName objectName = expr.getObjectOperand();
088                TSelectSqlStatement select = (TSelectSqlStatement)psql;
089                if (select.getResultColumnList() != null)
090                    for(int i=0;i<select.getResultColumnList().size();i++){
091                        TResultColumn resultColumn = select.getResultColumnList().getResultColumn(i);
092                        if (resultColumn.getAliasClause() != null){
093                            TAliasClause  aliasClause = resultColumn.getAliasClause();
094                            if (aliasClause.getAliasName().toString().equalsIgnoreCase(objectName.toString())){
095                                objectName.setObjectType(TObjectName.ttobjColumnAlias);
096                            }
097                        }
098                    }
099            }
100          expr.doParse(psql,plocation);
101        }else if (rollupCube != null){
102          rollupCube.doParse(psql,plocation);
103        }else if (groupingSet != null){
104          groupingSet.doParse(psql,plocation);
105        }else if (exprList != null){
106          exprList.doParse(psql,plocation);
107        }
108
109    }
110
111    public void accept(TParseTreeVisitor v){
112        v.preVisit(this);
113        v.postVisit(this);
114    }
115
116    public void acceptChildren(TParseTreeVisitor v){
117        v.preVisit(this);
118        if (expr != null){
119            expr.acceptChildren(v);
120        }
121        v.postVisit(this);
122    }
123
124    public void setRollupCube(TRollupCube rollupCube) {
125        this.rollupCube = rollupCube;
126    }
127
128    public void setGroupingSet(TGroupingSet groupingSet) {
129        this.groupingSet = groupingSet;
130    }
131
132    public void setExprList(TExpressionList exprList) {
133        this.exprList = exprList;
134    }
135}