Program: 169128
Project: 169128
Buggy source:
public final QueryMeta statement() throws RecognitionException {
  QueryMeta qMeta=null;
  Token id=null;
  Token dir=null;
  Token l=null;
  Token s1=null;
  Token s2=null;
  Token s=null;
  Having h=null;
  PostAggItem p=null;
  qMeta=GroupByQueryMeta.promote(new QueryMeta());
  ((BaseAggQueryMeta)qMeta).aggregations=new ArrayList<>();
  qMeta.intervals=new ArrayList<>();
  try {
{
      match(input,SELECT,FOLLOW_SELECT_in_statement160);
      int alt16=3;
      int LA16_0=input.LA(1);
      if ((LA16_0 == WS)) {
        int LA16_1=input.LA(2);
        if ((LA16_1 == 71)) {
          alt16=2;
        }
 else         if ((LA16_1 == COUNT || LA16_1 == DOUBLE_SUM || LA16_1 == ID || LA16_1 == JAVASCRIPT || LA16_1 == LONG_SUM || (LA16_1 >= MAX && LA16_1 <= MIN) || LA16_1 == UNIQUE)) {
          alt16=1;
        }
      }
switch (alt16) {
case 1:
{
{
            match(input,WS,FOLLOW_WS_in_statement188);
            pushFollow(FOLLOW_selectItems_in_statement190);
            selectItems(qMeta);
            state._fsp--;
            loop15:             while (true) {
              int alt15=2;
              int LA15_0=input.LA(1);
              if ((LA15_0 == WS)) {
                int LA15_1=input.LA(2);
                if ((LA15_1 == 72)) {
                  alt15=1;
                }
              }
 else               if ((LA15_0 == 72)) {
                alt15=1;
              }
switch (alt15) {
case 1:
{
                  int alt13=2;
                  int LA13_0=input.LA(1);
                  if ((LA13_0 == WS)) {
                    alt13=1;
                  }
switch (alt13) {
case 1:
{
                      match(input,WS,FOLLOW_WS_in_statement194);
                    }
                  break;
              }
              match(input,72,FOLLOW_72_in_statement197);
              int alt14=2;
              int LA14_0=input.LA(1);
              if ((LA14_0 == WS)) {
                alt14=1;
              }
switch (alt14) {
case 1:
{
                  match(input,WS,FOLLOW_WS_in_statement199);
                }
              break;
          }
          pushFollow(FOLLOW_selectItems_in_statement202);
          selectItems(qMeta);
          state._fsp--;
        }
      break;
default :
    break loop15;
}
}
}
}
break;
case 2:
{
{
match(input,WS,FOLLOW_WS_in_statement233);
match(input,71,FOLLOW_71_in_statement235);
}
}
break;
}
match(input,WS,FOLLOW_WS_in_statement250);
match(input,FROM,FOLLOW_FROM_in_statement252);
match(input,WS,FOLLOW_WS_in_statement254);
id=(Token)match(input,ID,FOLLOW_ID_in_statement258);
qMeta.dataSource=(id != null ? id.getText() : null);
if (((BaseAggQueryMeta)qMeta).aggregations.isEmpty()) {
qMeta=SelectQueryMeta.promote(qMeta);
}
int alt41=2;
int LA41_0=input.LA(1);
if ((LA41_0 == WS)) {
int LA41_1=input.LA(2);
if ((LA41_1 == WHERE)) {
alt41=1;
}
}
switch (alt41) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement274);
match(input,WHERE,FOLLOW_WHERE_in_statement276);
match(input,WS,FOLLOW_WS_in_statement278);
pushFollow(FOLLOW_whereClause_in_statement280);
whereClause(qMeta);
state._fsp--;
{
int alt17=2;
int LA17_0=input.LA(1);
if ((LA17_0 == WS)) {
int LA17_1=input.LA(2);
if ((LA17_1 == BREAK)) {
alt17=1;
}
}
switch (alt17) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement297);
match(input,BREAK,FOLLOW_BREAK_in_statement299);
match(input,WS,FOLLOW_WS_in_statement301);
match(input,BY,FOLLOW_BY_in_statement303);
match(input,WS,FOLLOW_WS_in_statement305);
pushFollow(FOLLOW_granularityClause_in_statement307);
granularityClause(qMeta);
state._fsp--;
}
break;
}
int alt22=2;
int LA22_0=input.LA(1);
if ((LA22_0 == WS)) {
int LA22_1=input.LA(2);
if ((LA22_1 == GROUP)) {
alt22=1;
}
}
switch (alt22) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement318);
match(input,GROUP,FOLLOW_GROUP_in_statement320);
match(input,WS,FOLLOW_WS_in_statement322);
match(input,BY,FOLLOW_BY_in_statement324);
match(input,WS,FOLLOW_WS_in_statement326);
qMeta=GroupByQueryMeta.promote(qMeta);
if (((GroupByQueryMeta)qMeta).fetchDimensions == null) {
System.err.println("String_Node_Str");
}
{
id=(Token)match(input,ID,FOLLOW_ID_in_statement352);
if (!((GroupByQueryMeta)qMeta).checkDimOrAlias((id != null ? id.getText() : null))) {
System.err.println("String_Node_Str" + (id != null ? id.getText() : null) + "String_Node_Str");
}
loop20: while (true) {
int alt20=2;
int LA20_0=input.LA(1);
if ((LA20_0 == WS)) {
int LA20_1=input.LA(2);
if ((LA20_1 == 72)) {
alt20=1;
}
}
 else if ((LA20_0 == 72)) {
alt20=1;
}
switch (alt20) {
case 1:
{
int alt18=2;
int LA18_0=input.LA(1);
if ((LA18_0 == WS)) {
alt18=1;
}
switch (alt18) {
case 1:
{
  match(input,WS,FOLLOW_WS_in_statement384);
}
break;
}
match(input,72,FOLLOW_72_in_statement387);
int alt19=2;
int LA19_0=input.LA(1);
if ((LA19_0 == WS)) {
alt19=1;
}
switch (alt19) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement389);
}
break;
}
id=(Token)match(input,ID,FOLLOW_ID_in_statement394);
if (!((GroupByQueryMeta)qMeta).checkDimOrAlias((id != null ? id.getText() : null))) {
System.err.println("String_Node_Str" + (id != null ? id.getText() : null) + "String_Node_Str");
}
}
break;
default :
break loop20;
}
}
}
int alt21=2;
int LA21_0=input.LA(1);
if ((LA21_0 == WS)) {
int LA21_1=input.LA(2);
if ((LA21_1 == HAVING)) {
alt21=1;
}
}
switch (alt21) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement451);
match(input,HAVING,FOLLOW_HAVING_in_statement453);
match(input,WS,FOLLOW_WS_in_statement455);
pushFollow(FOLLOW_havingClause_in_statement459);
h=havingClause();
state._fsp--;
((GroupByQueryMeta)qMeta).having=h;
}
break;
}
}
break;
}
qMeta=QueryUtils.checkAndPromoteToTimeSeries(qMeta);
int alt24=2;
int LA24_0=input.LA(1);
if ((LA24_0 == WS)) {
int LA24_1=input.LA(2);
if ((LA24_1 == ORDER)) {
alt24=1;
}
}
switch (alt24) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement503);
match(input,ORDER,FOLLOW_ORDER_in_statement505);
match(input,WS,FOLLOW_WS_in_statement507);
match(input,BY,FOLLOW_BY_in_statement509);
match(input,WS,FOLLOW_WS_in_statement511);
{
id=(Token)match(input,ID,FOLLOW_ID_in_statement516);
}
if (((PlainDimQueryMeta)qMeta).fetchDimensions.size() != 1) {
((GroupByQueryMeta)qMeta).limitSpec=new LimitSpec();
}
 else {
qMeta=TopNQueryMeta.promote(qMeta);
((TopNQueryMeta)qMeta).metric=(id != null ? id.getText() : null);
}
int alt23=2;
int LA23_0=input.LA(1);
if ((LA23_0 == WS)) {
int LA23_1=input.LA(2);
if ((LA23_1 == ASC || LA23_1 == DESC)) {
alt23=1;
}
}
switch (alt23) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement549);
dir=input.LT(1);
if (input.LA(1) == ASC || input.LA(1) == DESC) {
input.consume();
state.errorRecovery=false;
}
 else {
MismatchedSetException mse=new MismatchedSetException(null,input);
throw mse;
}
if (qMeta instanceof GroupByQueryMeta && ((GroupByQueryMeta)qMeta).limitSpec != null) {
if (dir != null && (dir != null ? dir.getText() : null) != null) {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),(dir != null ? dir.getText() : null));
}
 else {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),"String_Node_Str");
}
}
}
break;
}
if (qMeta instanceof GroupByQueryMeta && ((GroupByQueryMeta)qMeta).limitSpec != null) {
if (!((GroupByQueryMeta)qMeta).limitSpec.columns.containsKey((id != null ? id.getText() : null))) {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),"String_Node_Str");
}
}
}
break;
}
int alt25=2;
int LA25_0=input.LA(1);
if ((LA25_0 == WS)) {
int LA25_1=input.LA(2);
if ((LA25_1 == LIMIT)) {
alt25=1;
}
}
switch (alt25) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement603);
match(input,LIMIT,FOLLOW_LIMIT_in_statement605);
match(input,WS,FOLLOW_WS_in_statement607);
{
l=(Token)match(input,LONG,FOLLOW_LONG_in_statement612);
}
if (((PlainDimQueryMeta)qMeta).fetchDimensions.size() != 1) {
((GroupByQueryMeta)qMeta).limitSpec.limit=Long.valueOf((l != null ? l.getText() : null));
}
 else if (qMeta instanceof TopNQueryMeta) {
((TopNQueryMeta)qMeta).threshold=Integer.valueOf((l != null ? l.getText() : null));
}
 else if (qMeta instanceof SelectQueryMeta) {
((SelectQueryMeta)qMeta).pagingSpec.threshold=Integer.valueOf((l != null ? l.getText() : null));
}
}
break;
}
int alt26=2;
int LA26_0=input.LA(1);
if ((LA26_0 == WS)) {
int LA26_1=input.LA(2);
if ((LA26_1 == THEN)) {
alt26=1;
}
}
switch (alt26) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement650);
match(input,THEN,FOLLOW_THEN_in_statement652);
match(input,WS,FOLLOW_WS_in_statement654);
pushFollow(FOLLOW_postAggItem_in_statement658);
p=postAggItem();
state._fsp--;
QueryUtils.setPostAggregation(qMeta,p);
}
break;
}
}
int alt36=2;
int LA36_0=input.LA(1);
if ((LA36_0 == WS)) {
int LA36_1=input.LA(2);
if ((LA36_1 == WHICH)) {
alt36=1;
}
}
switch (alt36) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement673);
match(input,WHICH,FOLLOW_WHICH_in_statement675);
match(input,WS,FOLLOW_WS_in_statement677);
match(input,CONTAINS,FOLLOW_CONTAINS_in_statement679);
qMeta=SearchQueryMeta.promote(qMeta);
int alt27=2;
int LA27_0=input.LA(1);
if ((LA27_0 == WS)) {
alt27=1;
}
switch (alt27) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement683);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement686);
int alt28=2;
int LA28_0=input.LA(1);
if ((LA28_0 == WS)) {
alt28=1;
}
switch (alt28) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement688);
}
break;
}
{
s1=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement694);
((SearchQueryMeta)qMeta).type="String_Node_Str";
((SearchQueryMeta)qMeta).addValue((s1 != null ? s1.getText() : null));
loop31: while (true) {
int alt31=2;
int LA31_0=input.LA(1);
if ((LA31_0 == WS)) {
int LA31_1=input.LA(2);
if ((LA31_1 == 72)) {
alt31=1;
}
}
 else if ((LA31_0 == 72)) {
alt31=1;
}
switch (alt31) {
case 1:
{
int alt29=2;
int LA29_0=input.LA(1);
if ((LA29_0 == WS)) {
alt29=1;
}
switch (alt29) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement698);
}
break;
}
match(input,72,FOLLOW_72_in_statement701);
int alt30=2;
int LA30_0=input.LA(1);
if ((LA30_0 == WS)) {
alt30=1;
}
switch (alt30) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement703);
}
break;
}
s2=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement708);
((SearchQueryMeta)qMeta).type="String_Node_Str";
((SearchQueryMeta)qMeta).addValue((s2 != null ? s2.getText() : null));
}
break;
default :
break loop31;
}
}
}
int alt32=2;
int LA32_0=input.LA(1);
if ((LA32_0 == WS)) {
alt32=1;
}
switch (alt32) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement715);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement718);
match(input,WS,FOLLOW_WS_in_statement724);
match(input,SORT,FOLLOW_SORT_in_statement726);
int alt33=2;
int LA33_0=input.LA(1);
if ((LA33_0 == WS)) {
alt33=1;
}
switch (alt33) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement728);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement731);
int alt34=2;
int LA34_0=input.LA(1);
if ((LA34_0 == WS)) {
alt34=1;
}
switch (alt34) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement733);
}
break;
}
{
s=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement739);
}
((SearchQueryMeta)qMeta).setSort((s != null ? s.getText() : null));
int alt35=2;
int LA35_0=input.LA(1);
if ((LA35_0 == WS)) {
alt35=1;
}
switch (alt35) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement744);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement747);
}
break;
}
int alt40=2;
int LA40_0=input.LA(1);
if ((LA40_0 == WS)) {
int LA40_1=input.LA(2);
if ((LA40_1 == HINT)) {
alt40=1;
}
}
switch (alt40) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement759);
match(input,HINT,FOLLOW_HINT_in_statement761);
int alt37=2;
int LA37_0=input.LA(1);
if ((LA37_0 == WS)) {
alt37=1;
}
switch (alt37) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement763);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement766);
int alt38=2;
int LA38_0=input.LA(1);
if ((LA38_0 == WS)) {
alt38=1;
}
switch (alt38) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement768);
}
break;
}
s=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement773);
qMeta=HintProcessor.process(qMeta,(s != null ? s.getText() : null));
int alt39=2;
int LA39_0=input.LA(1);
if ((LA39_0 == WS)) {
alt39=1;
}
switch (alt39) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement777);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement780);
}
break;
}
}
break;
}
if (qMeta.intervals == null || qMeta.intervals.isEmpty()) {
qMeta=TimeBoundaryQueryMeta.promote(qMeta);
}
}
}
 catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
 finally {
}
return qMeta;
}

Fixed version (ground truth):
public final QueryMeta statement() throws RecognitionException {
  QueryMeta qMeta=null;
  Token id=null;
  Token dir=null;
  Token l=null;
  Token s1=null;
  Token s2=null;
  Token s=null;
  Having h=null;
  PostAggItem p=null;
  qMeta=GroupByQueryMeta.promote(new QueryMeta());
  ((BaseAggQueryMeta)qMeta).aggregations=new ArrayList<>();
  qMeta.intervals=new ArrayList<>();
  try {
{
      match(input,SELECT,FOLLOW_SELECT_in_statement191);
      int alt17=3;
      int LA17_0=input.LA(1);
      if ((LA17_0 == WS)) {
        int LA17_1=input.LA(2);
        if ((LA17_1 == 71)) {
          alt17=2;
        }
 else         if ((LA17_1 == COUNT || LA17_1 == DOUBLE_SUM || LA17_1 == ID || LA17_1 == JAVASCRIPT || LA17_1 == LONG_SUM || (LA17_1 >= MAX && LA17_1 <= MIN) || LA17_1 == UNIQUE)) {
          alt17=1;
        }
      }
switch (alt17) {
case 1:
{
{
            match(input,WS,FOLLOW_WS_in_statement219);
            pushFollow(FOLLOW_selectItems_in_statement221);
            selectItems(qMeta);
            state._fsp--;
            loop16:             while (true) {
              int alt16=2;
              int LA16_0=input.LA(1);
              if ((LA16_0 == WS)) {
                int LA16_1=input.LA(2);
                if ((LA16_1 == 72)) {
                  alt16=1;
                }
              }
 else               if ((LA16_0 == 72)) {
                alt16=1;
              }
switch (alt16) {
case 1:
{
                  int alt14=2;
                  int LA14_0=input.LA(1);
                  if ((LA14_0 == WS)) {
                    alt14=1;
                  }
switch (alt14) {
case 1:
{
                      match(input,WS,FOLLOW_WS_in_statement225);
                    }
                  break;
              }
              match(input,72,FOLLOW_72_in_statement228);
              int alt15=2;
              int LA15_0=input.LA(1);
              if ((LA15_0 == WS)) {
                alt15=1;
              }
switch (alt15) {
case 1:
{
                  match(input,WS,FOLLOW_WS_in_statement230);
                }
              break;
          }
          pushFollow(FOLLOW_selectItems_in_statement233);
          selectItems(qMeta);
          state._fsp--;
        }
      break;
default :
    break loop16;
}
}
}
}
break;
case 2:
{
{
match(input,WS,FOLLOW_WS_in_statement264);
match(input,71,FOLLOW_71_in_statement266);
}
}
break;
}
match(input,WS,FOLLOW_WS_in_statement281);
match(input,FROM,FOLLOW_FROM_in_statement283);
match(input,WS,FOLLOW_WS_in_statement285);
id=(Token)match(input,ID,FOLLOW_ID_in_statement289);
qMeta.dataSource=(id != null ? id.getText() : null);
if (((BaseAggQueryMeta)qMeta).aggregations.isEmpty()) {
qMeta=SelectQueryMeta.promote(qMeta);
}
int alt42=2;
int LA42_0=input.LA(1);
if ((LA42_0 == WS)) {
int LA42_1=input.LA(2);
if ((LA42_1 == WHERE)) {
alt42=1;
}
}
switch (alt42) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement305);
match(input,WHERE,FOLLOW_WHERE_in_statement307);
match(input,WS,FOLLOW_WS_in_statement309);
pushFollow(FOLLOW_whereClause_in_statement311);
whereClause(qMeta);
state._fsp--;
{
int alt18=2;
int LA18_0=input.LA(1);
if ((LA18_0 == WS)) {
int LA18_1=input.LA(2);
if ((LA18_1 == BREAK)) {
alt18=1;
}
}
switch (alt18) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement328);
match(input,BREAK,FOLLOW_BREAK_in_statement330);
match(input,WS,FOLLOW_WS_in_statement332);
match(input,BY,FOLLOW_BY_in_statement334);
match(input,WS,FOLLOW_WS_in_statement336);
pushFollow(FOLLOW_granularityClause_in_statement338);
granularityClause(qMeta);
state._fsp--;
}
break;
}
int alt23=2;
int LA23_0=input.LA(1);
if ((LA23_0 == WS)) {
int LA23_1=input.LA(2);
if ((LA23_1 == GROUP)) {
alt23=1;
}
}
switch (alt23) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement349);
match(input,GROUP,FOLLOW_GROUP_in_statement351);
match(input,WS,FOLLOW_WS_in_statement353);
match(input,BY,FOLLOW_BY_in_statement355);
match(input,WS,FOLLOW_WS_in_statement357);
qMeta=GroupByQueryMeta.promote(qMeta);
if (((GroupByQueryMeta)qMeta).fetchDimensions == null) {
System.err.println("String_Node_Str");
}
{
id=(Token)match(input,ID,FOLLOW_ID_in_statement383);
if (!((GroupByQueryMeta)qMeta).checkDimOrAlias((id != null ? id.getText() : null))) {
System.err.println("String_Node_Str" + (id != null ? id.getText() : null) + "String_Node_Str");
}
loop21: while (true) {
int alt21=2;
int LA21_0=input.LA(1);
if ((LA21_0 == WS)) {
int LA21_1=input.LA(2);
if ((LA21_1 == 72)) {
alt21=1;
}
}
 else if ((LA21_0 == 72)) {
alt21=1;
}
switch (alt21) {
case 1:
{
int alt19=2;
int LA19_0=input.LA(1);
if ((LA19_0 == WS)) {
alt19=1;
}
switch (alt19) {
case 1:
{
  match(input,WS,FOLLOW_WS_in_statement415);
}
break;
}
match(input,72,FOLLOW_72_in_statement418);
int alt20=2;
int LA20_0=input.LA(1);
if ((LA20_0 == WS)) {
alt20=1;
}
switch (alt20) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement420);
}
break;
}
id=(Token)match(input,ID,FOLLOW_ID_in_statement425);
if (!((GroupByQueryMeta)qMeta).checkDimOrAlias((id != null ? id.getText() : null))) {
System.err.println("String_Node_Str" + (id != null ? id.getText() : null) + "String_Node_Str");
}
}
break;
default :
break loop21;
}
}
}
int alt22=2;
int LA22_0=input.LA(1);
if ((LA22_0 == WS)) {
int LA22_1=input.LA(2);
if ((LA22_1 == HAVING)) {
alt22=1;
}
}
switch (alt22) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement482);
match(input,HAVING,FOLLOW_HAVING_in_statement484);
match(input,WS,FOLLOW_WS_in_statement486);
pushFollow(FOLLOW_havingClause_in_statement490);
h=havingClause();
state._fsp--;
((GroupByQueryMeta)qMeta).having=h;
}
break;
}
}
break;
}
qMeta=QueryUtils.checkAndPromoteToTimeSeries(qMeta);
int alt25=2;
int LA25_0=input.LA(1);
if ((LA25_0 == WS)) {
int LA25_1=input.LA(2);
if ((LA25_1 == ORDER)) {
alt25=1;
}
}
switch (alt25) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement534);
match(input,ORDER,FOLLOW_ORDER_in_statement536);
match(input,WS,FOLLOW_WS_in_statement538);
match(input,BY,FOLLOW_BY_in_statement540);
match(input,WS,FOLLOW_WS_in_statement542);
{
id=(Token)match(input,ID,FOLLOW_ID_in_statement547);
}
if (((PlainDimQueryMeta)qMeta).fetchDimensions.size() != 1) {
((GroupByQueryMeta)qMeta).limitSpec=new LimitSpec();
}
 else {
qMeta=TopNQueryMeta.promote(qMeta);
((TopNQueryMeta)qMeta).metric=(id != null ? id.getText() : null);
}
int alt24=2;
int LA24_0=input.LA(1);
if ((LA24_0 == WS)) {
int LA24_1=input.LA(2);
if ((LA24_1 == ASC || LA24_1 == DESC)) {
alt24=1;
}
}
switch (alt24) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement580);
dir=input.LT(1);
if (input.LA(1) == ASC || input.LA(1) == DESC) {
input.consume();
state.errorRecovery=false;
}
 else {
MismatchedSetException mse=new MismatchedSetException(null,input);
throw mse;
}
if (qMeta instanceof GroupByQueryMeta && ((GroupByQueryMeta)qMeta).limitSpec != null) {
if (dir != null && (dir != null ? dir.getText() : null) != null) {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),(dir != null ? dir.getText() : null));
}
 else {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),"String_Node_Str");
}
}
}
break;
}
if (qMeta instanceof GroupByQueryMeta && ((GroupByQueryMeta)qMeta).limitSpec != null) {
if (!((GroupByQueryMeta)qMeta).limitSpec.columns.containsKey((id != null ? id.getText() : null))) {
((GroupByQueryMeta)qMeta).limitSpec.addColumn((id != null ? id.getText() : null),"String_Node_Str");
}
}
}
break;
}
int alt26=2;
int LA26_0=input.LA(1);
if ((LA26_0 == WS)) {
int LA26_1=input.LA(2);
if ((LA26_1 == LIMIT)) {
alt26=1;
}
}
switch (alt26) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement634);
match(input,LIMIT,FOLLOW_LIMIT_in_statement636);
match(input,WS,FOLLOW_WS_in_statement638);
{
l=(Token)match(input,LONG,FOLLOW_LONG_in_statement643);
}
if (((PlainDimQueryMeta)qMeta).fetchDimensions.size() != 1) {
((GroupByQueryMeta)qMeta).limitSpec.limit=Long.valueOf((l != null ? l.getText() : null));
}
 else if (qMeta instanceof TopNQueryMeta) {
((TopNQueryMeta)qMeta).threshold=Integer.valueOf((l != null ? l.getText() : null));
}
 else if (qMeta instanceof SelectQueryMeta) {
((SelectQueryMeta)qMeta).pagingSpec.threshold=Integer.valueOf((l != null ? l.getText() : null));
}
}
break;
}
int alt27=2;
int LA27_0=input.LA(1);
if ((LA27_0 == WS)) {
int LA27_1=input.LA(2);
if ((LA27_1 == THEN)) {
alt27=1;
}
}
switch (alt27) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement681);
match(input,THEN,FOLLOW_THEN_in_statement683);
match(input,WS,FOLLOW_WS_in_statement685);
pushFollow(FOLLOW_postAggItem_in_statement689);
p=postAggItem();
state._fsp--;
QueryUtils.setPostAggregation(qMeta,p);
}
break;
}
}
int alt37=2;
int LA37_0=input.LA(1);
if ((LA37_0 == WS)) {
int LA37_1=input.LA(2);
if ((LA37_1 == WHICH)) {
alt37=1;
}
}
switch (alt37) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement704);
match(input,WHICH,FOLLOW_WHICH_in_statement706);
match(input,WS,FOLLOW_WS_in_statement708);
match(input,CONTAINS,FOLLOW_CONTAINS_in_statement710);
qMeta=SearchQueryMeta.promote(qMeta);
int alt28=2;
int LA28_0=input.LA(1);
if ((LA28_0 == WS)) {
alt28=1;
}
switch (alt28) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement714);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement717);
int alt29=2;
int LA29_0=input.LA(1);
if ((LA29_0 == WS)) {
alt29=1;
}
switch (alt29) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement719);
}
break;
}
{
s1=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement725);
((SearchQueryMeta)qMeta).type="String_Node_Str";
((SearchQueryMeta)qMeta).addValue((s1 != null ? s1.getText() : null));
loop32: while (true) {
int alt32=2;
int LA32_0=input.LA(1);
if ((LA32_0 == WS)) {
int LA32_1=input.LA(2);
if ((LA32_1 == 72)) {
alt32=1;
}
}
 else if ((LA32_0 == 72)) {
alt32=1;
}
switch (alt32) {
case 1:
{
int alt30=2;
int LA30_0=input.LA(1);
if ((LA30_0 == WS)) {
alt30=1;
}
switch (alt30) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement729);
}
break;
}
match(input,72,FOLLOW_72_in_statement732);
int alt31=2;
int LA31_0=input.LA(1);
if ((LA31_0 == WS)) {
alt31=1;
}
switch (alt31) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement734);
}
break;
}
s2=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement739);
((SearchQueryMeta)qMeta).type="String_Node_Str";
((SearchQueryMeta)qMeta).addValue((s2 != null ? s2.getText() : null));
}
break;
default :
break loop32;
}
}
}
int alt33=2;
int LA33_0=input.LA(1);
if ((LA33_0 == WS)) {
alt33=1;
}
switch (alt33) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement746);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement749);
match(input,WS,FOLLOW_WS_in_statement755);
match(input,SORT,FOLLOW_SORT_in_statement757);
int alt34=2;
int LA34_0=input.LA(1);
if ((LA34_0 == WS)) {
alt34=1;
}
switch (alt34) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement759);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement762);
int alt35=2;
int LA35_0=input.LA(1);
if ((LA35_0 == WS)) {
alt35=1;
}
switch (alt35) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement764);
}
break;
}
{
s=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement770);
}
((SearchQueryMeta)qMeta).setSort((s != null ? s.getText() : null));
int alt36=2;
int LA36_0=input.LA(1);
if ((LA36_0 == WS)) {
alt36=1;
}
switch (alt36) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement775);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement778);
}
break;
}
int alt41=2;
int LA41_0=input.LA(1);
if ((LA41_0 == WS)) {
int LA41_1=input.LA(2);
if ((LA41_1 == HINT)) {
alt41=1;
}
}
switch (alt41) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement790);
match(input,HINT,FOLLOW_HINT_in_statement792);
int alt38=2;
int LA38_0=input.LA(1);
if ((LA38_0 == WS)) {
alt38=1;
}
switch (alt38) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement794);
}
break;
}
match(input,LPARAN,FOLLOW_LPARAN_in_statement797);
int alt39=2;
int LA39_0=input.LA(1);
if ((LA39_0 == WS)) {
alt39=1;
}
switch (alt39) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement799);
}
break;
}
s=(Token)match(input,SINGLE_QUOTE_STRING,FOLLOW_SINGLE_QUOTE_STRING_in_statement804);
qMeta=HintProcessor.process(qMeta,(s != null ? s.getText() : null));
int alt40=2;
int LA40_0=input.LA(1);
if ((LA40_0 == WS)) {
alt40=1;
}
switch (alt40) {
case 1:
{
match(input,WS,FOLLOW_WS_in_statement808);
}
break;
}
match(input,RPARAN,FOLLOW_RPARAN_in_statement811);
}
break;
}
}
break;
}
if (qMeta.intervals == null || qMeta.intervals.isEmpty()) {
qMeta=TimeBoundaryQueryMeta.promote(qMeta);
}
}
}
 catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
 finally {
}
return qMeta;
}