private void SetGroupby(GroupbyContext groupby, string name, string varName)
 {
     if (groupby != null)
     {
         var                    dq              = new DataCube(name, DataStatement.GROUPBY, varName);
         FieldsContext          fields          = groupby.fields();
         FilterconditionContext Filtercondition = groupby.filtercondition();
         SortstatementContext   sortStatement   = groupby.sortstatement();
         AggContext             agg             = groupby.agg();
         if (fields != null)
         {
             string[] s = fields.GetText().Split(',');
             for (int i = 0; i < s.Length; i++)
             {
                 dq.GroupByStatement.AddField(new State.DataField(s[i], s[i]));
             }
         }
         if (agg != null)
         {
             string[] s = agg.GetText().Split(',');
             for (int i = 0; i < s.Length; i++)
             {
                 string[] f = s[i].Split('.');
                 var      a = new State.AggregateField(f[0], f[0])
                 {
                     AggregateType = f[1]
                 };
                 dq.GroupByStatement.AddAgg(a);
             }
         }
         if (Filtercondition != null)
         {
             ConditionContext condition = Filtercondition.condition();
             var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
             dq.SelectStatement.AddCondition(search);
         }
         if (sortStatement != null)
         {
             OrderContext order = sortStatement.order();
             dq.SelectStatement.AddOrder(new State.SortBy(order.ORDERBY()[0].GetText(), order.fields()[0].GetText()));
         }
         DataCubes.Add(dq);
     }
 }
        private void SetRollup(RollupContext rollup, string name, string varName)
        {
            var dq = new DataCube(name, DataStatement.ROLLUP, varName);

            if (rollup != null)
            {
                FilterconditionContext Filtercondition = rollup.filtercondition();
                SortstatementContext   sortStatement   = rollup.sortstatement();
                FieldsContext          fs      = rollup.fields();
                AggtypeContext         aggtype = rollup.aggtype();
                dq.RollupStatement = new State.Rollup()
                {
                    Aggregate = aggtype.GetText()
                };
                if (fs != null)
                {
                    string[] s = fs.GetText().Split(',');
                    for (int i = 0; i < s.Length; i++)
                    {
                        dq.RollupStatement.AddField(new State.DataField(s[i], s[i]));
                    }
                }
                if (Filtercondition != null)
                {
                    ConditionContext condition = Filtercondition.condition();
                    var search = new State.Search(condition.children[0].GetText(), condition.children[1].GetText(), condition.children[2].GetText());
                    dq.RollupStatement.AddCondition(search);
                }
                if (sortStatement != null)
                {
                    OrderContext order = sortStatement.order();
                    dq.RollupStatement.AddOrder(new State.SortBy(order.ORDERBY()[0].GetText(), order.fields()[0].GetText()));
                }
                DataCubes.Add(dq);
            }
        }