hql.g:681:1: subQuery : innerSubQuery ( UNION ^ innerSubQuery )* ;
967275
public final hqlParser.subQuery_return subQuery() throws RecognitionException {
		hqlParser.subQuery_return retval = new hqlParser.subQuery_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token UNION298=null;
		ParserRuleReturnScope innerSubQuery297 =null;
		ParserRuleReturnScope innerSubQuery299 =null;

		CommonTree UNION298_tree=null;

		try {
			// hql.g:682:2: ( innerSubQuery ( UNION ^ innerSubQuery )* )
			// hql.g:682:4: innerSubQuery ( UNION ^ innerSubQuery )*
			{
			root_0 = (CommonTree)adaptor.nil();


			pushFollow(FOLLOW_innerSubQuery_in_subQuery3501);
			innerSubQuery297=innerSubQuery();
			state._fsp--;

			adaptor.addChild(root_0, innerSubQuery297.getTree());

			// hql.g:682:18: ( UNION ^ innerSubQuery )*
			loop107:
			while (true) {
				int alt107=2;
				int LA107_0 = input.LA(1);
				if ( (LA107_0==UNION) ) {
					alt107=1;
				}

				switch (alt107) {
				case 1 :
					// hql.g:682:19: UNION ^ innerSubQuery
					{
					UNION298=(Token)match(input,UNION,FOLLOW_UNION_in_subQuery3504);
					UNION298_tree = (CommonTree)adaptor.create(UNION298);
					root_0 = (CommonTree)adaptor.becomeRoot(UNION298_tree, root_0);

					pushFollow(FOLLOW_innerSubQuery_in_subQuery3507);
					innerSubQuery299=innerSubQuery();
					state._fsp--;

					adaptor.addChild(root_0, innerSubQuery299.getTree());

					}
					break;

				default :
					break loop107;
				}
			}

			}

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

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

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
853854
@SuppressWarnings("unchecked")
    public static <T> Expression<T> any(SubQueryExpression<? extends T> col) {
        return new OperationImpl<T>(col.getType(), Ops.QuantOps.ANY, ImmutableList.<Expression<?>>of(col));
    }
850810
private SelectSubqueryExpression parseSubqueryExpression(VoltXMLElement exprNode) {
        assert(exprNode.children.size() == 1);
        VoltXMLElement subqueryElmt = exprNode.children.get(0);
        AbstractParsedStmt subqueryStmt = parseSubquery(subqueryElmt);
        // add table to the query cache
        String withoutAlias = null;
        StmtSubqueryScan stmtSubqueryScan =
                addSubqueryToStmtCache(subqueryStmt, withoutAlias);
        // Set to the default SELECT_SUBQUERY. May be overridden depending on the context
        return new SelectSubqueryExpression(ExpressionType.SELECT_SUBQUERY, stmtSubqueryScan);
    }
869905
SQLExecutableQuery generateSourceQuery(IntermediateQuery intermediateQuery)
			throws OntopReformulationException {

		IQ normalizedQuery = normalizeIQ(intermediateQuery);

		DatalogProgram queryProgram = iq2DatalogTranslator.translate(normalizedQuery);

		for (CQIE cq : queryProgram.getRules()) {
			datalogNormalizer.addMinimalEqualityToLeftOrNestedInnerJoin(cq);
		}
		log.debug("Program normalized for SQL translation:\n" + queryProgram);

		MutableQueryModifiers queryModifiers = queryProgram.getQueryModifiers();
		isDistinct = queryModifiers.hasModifiers() && queryModifiers.isDistinct();
		isOrderBy = queryModifiers.hasModifiers() && !queryModifiers.getSortConditions().isEmpty();

		DatalogDependencyGraphGenerator depGraph = new DatalogDependencyGraphGenerator(queryProgram.getRules());
		Multimap<Predicate, CQIE> ruleIndex = depGraph.getRuleIndex();
		List<Predicate> predicatesInBottomUp = depGraph.getPredicatesInBottomUp();
		List<Predicate> extensionalPredicates = depGraph.getExtensionalPredicates();

		ImmutableList<String> signature = intermediateQuery.getProjectionAtom().getArguments().stream()
				.map(Variable::getName)
				.collect(ImmutableCollectors.toList());

		final String resultingQuery;
		String queryString = generateQuery(signature, ruleIndex, predicatesInBottomUp, extensionalPredicates);
		if (queryModifiers.hasModifiers()) {
			//List<Variable> groupby = queryProgram.getQueryModifiers().getGroupConditions();
			// if (!groupby.isEmpty()) {
			// subquery += "\n" + sqladapter.sqlGroupBy(groupby, "") + " " +
			// havingStr + "\n";
			// }
			// List<OrderCondition> conditions =
			// query.getQueryModifiers().getSortConditions();

			long limit = queryModifiers.getLimit();
			long offset = queryModifiers.getOffset();
			List<OrderCondition> conditions = queryModifiers.getSortConditions();

			final String modifier;
			if (!conditions.isEmpty()) {
				modifier = sqladapter.sqlOrderByAndSlice(conditions, OUTER_VIEW_NAME, limit, offset) + "\n";
			}
			else if (limit != -1 || offset != -1) {
				modifier = sqladapter.sqlSlice(limit, offset) + "\n";
			}
			else {
				modifier = "";
			}

			resultingQuery = "SELECT *\n" +
					"FROM " + inBrackets("\n" + queryString + "\n") + " " + OUTER_VIEW_NAME + "\n" +
					modifier;
		}
		else {
			resultingQuery = queryString;
		}
		return new SQLExecutableQuery(resultingQuery, signature);
	}
718382
def compile_select(self, query):
        
        sql = super(MySqlQueryGrammar, self).compile_select(query)

        if query.unions:
            sql = '(%s) %s' % (sql, self._compile_unions(query))

        return sql
264346
public void configureEventSubscriptionQuery(EventSubscriptionQueryImpl query) {
    configureQuery(query);
    CompositePermissionCheck permissionCheck = new PermissionCheckBuilder()
            .disjunctive()
            .atomicCheck(PROCESS_INSTANCE, "RES.PROC_INST_ID_", READ)
            .atomicCheck(PROCESS_DEFINITION, "PROCDEF.KEY_", READ_INSTANCE)
            .build();
    addPermissionCheck(query.getAuthCheck(), permissionCheck);
  }
1081225
private InternalQueryCache createUnderlyingQueryCache(QueryCacheConfig queryCacheConfig,
                                                          QueryCacheRequest request,
                                                          String cacheId) {
        SubscriberContext subscriberContext = context.getSubscriberContext();
        QueryCacheFactory queryCacheFactory = subscriberContext.getQueryCacheFactory();
        request.withQueryCacheConfig(queryCacheConfig);
        return queryCacheFactory.create(request, cacheId);
    }
956137
public static <T> Union<T> union(List<SubQueryExpression<T>> sq) {
        return new SQLQuery<Void>().union(sq);
    }
1323538
private static QueryComponent getQueryComponent(Queue filterClauseQueue)
    {
        QueryComponent subQuery = new QueryComponent();
        QueryComponent currentSubQuery = subQuery;

        for (Object object : filterClauseQueue)
        {
            if (object instanceof FilterClause)
            {
                currentSubQuery.clauses.add(object);
            }
            else if (object instanceof String)
            {
                String interClauseConstruct = (String) object;
                if (interClauseConstruct.equals("("))
                {
                    QueryComponent temp = new QueryComponent();
                    currentSubQuery.children.add(temp);
                    temp.parent = currentSubQuery;
                    currentSubQuery = temp;
                }
                else if (interClauseConstruct.equals(")"))
                {
                    currentSubQuery = currentSubQuery.parent;
                }
                else if (interClauseConstruct.equalsIgnoreCase("AND"))
                {
                    currentSubQuery.isAnd = true;
                }
                else if (interClauseConstruct.equalsIgnoreCase("OR"))
                {
                    currentSubQuery.isAnd = false;
                }
            }
        }

        return subQuery;
    }
996774
public static <T> JPQLQuery<T> select(Expression<T> expr) {
        return new JPASubQuery<Void>().select(expr);
    }
572289
private static MtasSpanQuery createSubQueryFromGroupHit(List<String>[] subHit,
      boolean reverse, String field) {
    MtasSpanQuery query = null;
    if (subHit != null && subHit.length > 0) {
      List<MtasSpanSequenceItem> items = new ArrayList<>();
      List<String> subHitItem;
      for (int i = 0; i < subHit.length; i++) {
        MtasSpanQuery item = null;
        if (reverse) {
          subHitItem = subHit[(subHit.length - i - 1)];
        } else {
          subHitItem = subHit[i];
        }
        if (subHitItem.isEmpty()) {
          item = new MtasSpanMatchAllQuery(field);
        } else if (subHitItem.size() == 1) {
          Term term = new Term(field, subHitItem.get(0));
          item = new MtasSpanTermQuery(term);
        } else {
          MtasSpanQuery[] subList = new MtasSpanQuery[subHitItem.size()];
          for (int j = 0; j < subHitItem.size(); j++) {
            Term term = new Term(field, subHitItem.get(j));
            subList[j] = new MtasSpanTermQuery(term);
          }
          item = new MtasSpanAndQuery(subList);
        }
        items.add(new MtasSpanSequenceItem(item, false));
      }
      query = new MtasSpanSequenceQuery(items, null, null);
    }
    return query;
  }
15762
@Override
    protected Query parseQuery( TokenStream tokens,
                                TypeSystem typeSystem ) {
        Query query = super.parseQuery(tokens, typeSystem);
        // See if we have to rewrite the JCR-SQL-style join ...
        if (query.source() instanceof JoinableSources) {
            JoinableSources joinableSources = (JoinableSources)query.source();
            // Rewrite the joins ...
            Source newSource = rewrite(joinableSources);
            query = new Query(newSource, query.constraint(), query.orderings(), query.columns(), query.getLimits(),
                              query.isDistinct());
        }
        return query;
    }
917091
protected void appendClause(StringBuffer clause, Criteria crit, StringBuffer stmt)
    {
        /**
         * MBAIRD
         * when generating the "WHERE/HAVING" clause we need to append the criteria for multi-mapped
         * tables. We only need to do this for the root classdescriptor and not for joined tables
         * because we assume you cannot make a relation of the wrong type upon insertion. Of course,
         * you COULD mess the data up manually and this would cause a problem.
         */

        if (clause != null)
        {
            stmt.append(clause.toString());
        }
        if (crit != null)
        {
            if (clause == null)
            {
                stmt.append(asSQLStatement(crit));
            }
            else
            {
                stmt.append(" AND (");
                stmt.append(asSQLStatement(crit));
                stmt.append(")");
            }

        }
    }
192070
public SuperCfResult<K, SN, N> querySuperColumns(K key, HSlicePredicate<SN> predicate) {
    return doExecuteSlice(key,null,predicate);
  }
99788
private IntermediateQuery pushAboveUnions(IntermediateQuery query) throws EmptyQueryException {
        boolean fixPointReached;
        do {
            fixPointReached = true;
            for (QueryNode node : query.getNodesInTopDownOrder()) {
                if (node instanceof UnionNode) {
                    Optional<PushUpBooleanExpressionProposal> proposal = makeProposalForUnionNode((UnionNode) node, query);
                    if (proposal.isPresent()) {
                        query = ((PushUpBooleanExpressionResults) query.applyProposal(proposal.get())).getResultingQuery();
                        fixPointReached = false;
                    }
                }
            }
        }
        while (!fixPointReached);
        return query;
    }
386447
function runSubqueries (subQueries, callback, collection) {
        var i,
            responsesReceived = 0,
            length = subQueries.length,
            joinedSet = [];//The array where the results are going to get stuffed

        if (subQueries.length > 0) {
            for (i = 0; i < subQueries.length; i += 1) {

                collection.aggregate(subQueries[i], function (err, results) {
                    joinedSet = joinedSet.concat(results);
                    responsesReceived += 1;

                    if (responsesReceived === length) {
                        callback(joinedSet);
                    }
                });
            }
        } else {
            callback([]);
        }

        return joinedSet;
    }
710908
private void appendSubQuery(Query subQuery, StringBuffer buf)
    {
        buf.append(" (");
        buf.append(getSubQuerySQL(subQuery));
        buf.append(") ");
    }