public final HiveParser.selectStatement_return selectStatement() throws RecognitionException {
		HiveParser.selectStatement_return retval = new HiveParser.selectStatement_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		ParserRuleReturnScope selectClause732 =null;
		ParserRuleReturnScope fromClause733 =null;
		ParserRuleReturnScope whereClause734 =null;
		ParserRuleReturnScope groupByClause735 =null;
		ParserRuleReturnScope havingClause736 =null;
		ParserRuleReturnScope orderByClause737 =null;
		ParserRuleReturnScope clusterByClause738 =null;
		ParserRuleReturnScope distributeByClause739 =null;
		ParserRuleReturnScope sortByClause740 =null;
		ParserRuleReturnScope window_clause741 =null;
		ParserRuleReturnScope limitClause742 =null;

		RewriteRuleSubtreeStream stream_whereClause=new RewriteRuleSubtreeStream(adaptor,"rule whereClause");
		RewriteRuleSubtreeStream stream_window_clause=new RewriteRuleSubtreeStream(adaptor,"rule window_clause");
		RewriteRuleSubtreeStream stream_clusterByClause=new RewriteRuleSubtreeStream(adaptor,"rule clusterByClause");
		RewriteRuleSubtreeStream stream_distributeByClause=new RewriteRuleSubtreeStream(adaptor,"rule distributeByClause");
		RewriteRuleSubtreeStream stream_limitClause=new RewriteRuleSubtreeStream(adaptor,"rule limitClause");
		RewriteRuleSubtreeStream stream_orderByClause=new RewriteRuleSubtreeStream(adaptor,"rule orderByClause");
		RewriteRuleSubtreeStream stream_sortByClause=new RewriteRuleSubtreeStream(adaptor,"rule sortByClause");
		RewriteRuleSubtreeStream stream_groupByClause=new RewriteRuleSubtreeStream(adaptor,"rule groupByClause");
		RewriteRuleSubtreeStream stream_havingClause=new RewriteRuleSubtreeStream(adaptor,"rule havingClause");
		RewriteRuleSubtreeStream stream_selectClause=new RewriteRuleSubtreeStream(adaptor,"rule selectClause");
		RewriteRuleSubtreeStream stream_fromClause=new RewriteRuleSubtreeStream(adaptor,"rule fromClause");

		try {
			// HiveParser.g:1855:4: ( selectClause fromClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )? -> ^( TOK_QUERY fromClause ^( TOK_INSERT ^( TOK_DESTINATION ^( TOK_DIR TOK_TMP_FILE ) ) selectClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )? ) ) )
			// HiveParser.g:1856:4: selectClause fromClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )?
			{
			pushFollow(FOLLOW_selectClause_in_selectStatement11635);
			selectClause732=selectClause();
			state._fsp--;

			stream_selectClause.add(selectClause732.getTree());
			pushFollow(FOLLOW_fromClause_in_selectStatement11640);
			fromClause733=fromClause();
			state._fsp--;

			stream_fromClause.add(fromClause733.getTree());
			// HiveParser.g:1858:4: ( whereClause )?
			int alt200=2;
			int LA200_0 = input.LA(1);
			if ( (LA200_0==KW_WHERE) ) {
				alt200=1;
			}
			switch (alt200) {
				case 1 :
					// HiveParser.g:1858:4: whereClause
					{
					pushFollow(FOLLOW_whereClause_in_selectStatement11645);
					whereClause734=whereClause();
					state._fsp--;

					stream_whereClause.add(whereClause734.getTree());
					}
					break;

			}

			// HiveParser.g:1859:4: ( groupByClause )?
			int alt201=2;
			int LA201_0 = input.LA(1);
			if ( (LA201_0==KW_GROUP) ) {
				alt201=1;
			}
			switch (alt201) {
				case 1 :
					// HiveParser.g:1859:4: groupByClause
					{
					pushFollow(FOLLOW_groupByClause_in_selectStatement11651);
					groupByClause735=groupByClause();
					state._fsp--;

					stream_groupByClause.add(groupByClause735.getTree());
					}
					break;

			}

			// HiveParser.g:1860:4: ( havingClause )?
			int alt202=2;
			int LA202_0 = input.LA(1);
			if ( (LA202_0==KW_HAVING) ) {
				alt202=1;
			}
			switch (alt202) {
				case 1 :
					// HiveParser.g:1860:4: havingClause
					{
					pushFollow(FOLLOW_havingClause_in_selectStatement11657);
					havingClause736=havingClause();
					state._fsp--;

					stream_havingClause.add(havingClause736.getTree());
					}
					break;

			}

			// HiveParser.g:1861:4: ( orderByClause )?
			int alt203=2;
			int LA203_0 = input.LA(1);
			if ( (LA203_0==KW_ORDER) ) {
				alt203=1;
			}
			switch (alt203) {
				case 1 :
					// HiveParser.g:1861:4: orderByClause
					{
					pushFollow(FOLLOW_orderByClause_in_selectStatement11663);
					orderByClause737=orderByClause();
					state._fsp--;

					stream_orderByClause.add(orderByClause737.getTree());
					}
					break;

			}

			// HiveParser.g:1862:4: ( clusterByClause )?
			int alt204=2;
			int LA204_0 = input.LA(1);
			if ( (LA204_0==KW_CLUSTER) ) {
				alt204=1;
			}
			switch (alt204) {
				case 1 :
					// HiveParser.g:1862:4: clusterByClause
					{
					pushFollow(FOLLOW_clusterByClause_in_selectStatement11669);
					clusterByClause738=clusterByClause();
					state._fsp--;

					stream_clusterByClause.add(clusterByClause738.getTree());
					}
					break;

			}

			// HiveParser.g:1863:4: ( distributeByClause )?
			int alt205=2;
			int LA205_0 = input.LA(1);
			if ( (LA205_0==KW_DISTRIBUTE) ) {
				alt205=1;
			}
			switch (alt205) {
				case 1 :
					// HiveParser.g:1863:4: distributeByClause
					{
					pushFollow(FOLLOW_distributeByClause_in_selectStatement11675);
					distributeByClause739=distributeByClause();
					state._fsp--;

					stream_distributeByClause.add(distributeByClause739.getTree());
					}
					break;

			}

			// HiveParser.g:1864:4: ( sortByClause )?
			int alt206=2;
			int LA206_0 = input.LA(1);
			if ( (LA206_0==KW_SORT) ) {
				alt206=1;
			}
			switch (alt206) {
				case 1 :
					// HiveParser.g:1864:4: sortByClause
					{
					pushFollow(FOLLOW_sortByClause_in_selectStatement11681);
					sortByClause740=sortByClause();
					state._fsp--;

					stream_sortByClause.add(sortByClause740.getTree());
					}
					break;

			}

			// HiveParser.g:1865:4: ( window_clause )?
			int alt207=2;
			int LA207_0 = input.LA(1);
			if ( (LA207_0==KW_WINDOW) ) {
				alt207=1;
			}
			switch (alt207) {
				case 1 :
					// HiveParser.g:1865:4: window_clause
					{
					pushFollow(FOLLOW_window_clause_in_selectStatement11687);
					window_clause741=window_clause();
					state._fsp--;

					stream_window_clause.add(window_clause741.getTree());
					}
					break;

			}

			// HiveParser.g:1866:4: ( limitClause )?
			int alt208=2;
			int LA208_0 = input.LA(1);
			if ( (LA208_0==KW_LIMIT) ) {
				alt208=1;
			}
			switch (alt208) {
				case 1 :
					// HiveParser.g:1866:4: limitClause
					{
					pushFollow(FOLLOW_limitClause_in_selectStatement11693);
					limitClause742=limitClause();
					state._fsp--;

					stream_limitClause.add(limitClause742.getTree());
					}
					break;

			}

			// AST REWRITE
			// elements: orderByClause, window_clause, whereClause, fromClause, distributeByClause, groupByClause, sortByClause, havingClause, selectClause, limitClause, clusterByClause
			// token labels: 
			// rule labels: retval
			// token list labels: 
			// rule list labels: 
			// wildcard labels: 
			retval.tree = root_0;
			RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.getTree():null);

			root_0 = (CommonTree)adaptor.nil();
			// 1866:17: -> ^( TOK_QUERY fromClause ^( TOK_INSERT ^( TOK_DESTINATION ^( TOK_DIR TOK_TMP_FILE ) ) selectClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )? ) )
			{
				// HiveParser.g:1866:20: ^( TOK_QUERY fromClause ^( TOK_INSERT ^( TOK_DESTINATION ^( TOK_DIR TOK_TMP_FILE ) ) selectClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )? ) )
				{
				CommonTree root_1 = (CommonTree)adaptor.nil();
				root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TOK_QUERY, "TOK_QUERY"), root_1);
				adaptor.addChild(root_1, stream_fromClause.nextTree());
				// HiveParser.g:1866:43: ^( TOK_INSERT ^( TOK_DESTINATION ^( TOK_DIR TOK_TMP_FILE ) ) selectClause ( whereClause )? ( groupByClause )? ( havingClause )? ( orderByClause )? ( clusterByClause )? ( distributeByClause )? ( sortByClause )? ( window_clause )? ( limitClause )? )
				{
				CommonTree root_2 = (CommonTree)adaptor.nil();
				root_2 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TOK_INSERT, "TOK_INSERT"), root_2);
				// HiveParser.g:1866:56: ^( TOK_DESTINATION ^( TOK_DIR TOK_TMP_FILE ) )
				{
				CommonTree root_3 = (CommonTree)adaptor.nil();
				root_3 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TOK_DESTINATION, "TOK_DESTINATION"), root_3);
				// HiveParser.g:1866:74: ^( TOK_DIR TOK_TMP_FILE )
				{
				CommonTree root_4 = (CommonTree)adaptor.nil();
				root_4 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(TOK_DIR, "TOK_DIR"), root_4);
				adaptor.addChild(root_4, (CommonTree)adaptor.create(TOK_TMP_FILE, "TOK_TMP_FILE"));
				adaptor.addChild(root_3, root_4);
				}

				adaptor.addChild(root_2, root_3);
				}

				adaptor.addChild(root_2, stream_selectClause.nextTree());
				// HiveParser.g:1867:35: ( whereClause )?
				if ( stream_whereClause.hasNext() ) {
					adaptor.addChild(root_2, stream_whereClause.nextTree());
				}
				stream_whereClause.reset();

				// HiveParser.g:1867:48: ( groupByClause )?
				if ( stream_groupByClause.hasNext() ) {
					adaptor.addChild(root_2, stream_groupByClause.nextTree());
				}
				stream_groupByClause.reset();

				// HiveParser.g:1867:63: ( havingClause )?
				if ( stream_havingClause.hasNext() ) {
					adaptor.addChild(root_2, stream_havingClause.nextTree());
				}
				stream_havingClause.reset();

				// HiveParser.g:1867:77: ( orderByClause )?
				if ( stream_orderByClause.hasNext() ) {
					adaptor.addChild(root_2, stream_orderByClause.nextTree());
				}
				stream_orderByClause.reset();

				// HiveParser.g:1867:92: ( clusterByClause )?
				if ( stream_clusterByClause.hasNext() ) {
					adaptor.addChild(root_2, stream_clusterByClause.nextTree());
				}
				stream_clusterByClause.reset();

				// HiveParser.g:1868:22: ( distributeByClause )?
				if ( stream_distributeByClause.hasNext() ) {
					adaptor.addChild(root_2, stream_distributeByClause.nextTree());
				}
				stream_distributeByClause.reset();

				// HiveParser.g:1868:42: ( sortByClause )?
				if ( stream_sortByClause.hasNext() ) {
					adaptor.addChild(root_2, stream_sortByClause.nextTree());
				}
				stream_sortByClause.reset();

				// HiveParser.g:1868:56: ( window_clause )?
				if ( stream_window_clause.hasNext() ) {
					adaptor.addChild(root_2, stream_window_clause.nextTree());
				}
				stream_window_clause.reset();

				// HiveParser.g:1868:71: ( limitClause )?
				if ( stream_limitClause.hasNext() ) {
					adaptor.addChild(root_2, stream_limitClause.nextTree());
				}
				stream_limitClause.reset();

				adaptor.addChild(root_1, root_2);
				}

				adaptor.addChild(root_0, root_1);
				}

			}


			retval.tree = root_0;

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}

		catch (RecognitionException e) {
		 reportError(e);
		  throw e;
		}

		finally {
			// do for sure before leaving
		}
		return retval;
	}