@Override protected void doPrepare() { expressions = prepared.getExpressions(); if (prepared.isGroupQuery()) { ArrayList<Expression> selectExprs = New.arrayList(10); int[] groupIndex = prepared.getGroupIndex(); for (int i = 0; i < groupIndex.length; i++) { int idx = groupIndex[i]; Expression expr = expressions.get(idx); selectExprs.add(expr); } HashSet<Aggregate> aggregates = New.hashSet(); for (Expression expr : expressions) { expr.isEverything(ExpressionVisitor.getAggregateVisitor(aggregates)); } selectExprs.addAll(aggregates); expressions = selectExprs; } Expression[] exprList = expressions.toArray(new Expression[expressions.size()]); Integer limit = null, offset = null; Expression limitExpr = prepared.getLimit(); Expression offsetExpr = prepared.getOffset(); if (limitExpr != null) { limit = limitExpr.getValue(session).getInt(); } if (offsetExpr != null) { offset = offsetExpr.getValue(session).getInt(); } RoutingResult rr = doRoute(prepared); if (rr.isMultipleNode() && offset != null) { if (offset > database.getSettings().analyzeSample) { throw DbException.get( ErrorCode.INVALID_VALUE_2, "offset", offset + ", the max support offset " + database.getSettings().analyzeSample + " is defined by analyzeSample."); } offset = offset != null ? 0 : offset; } ObjectNode[] selectNodes = rr.getSelectNodes(); if (session.getDatabase().getSettings().optimizeMerging) { selectNodes = rr.group(); } workers = New.arrayList(selectNodes.length); for (ObjectNode node : selectNodes) { QueryWorker queryHandler = queryHandlerFactory.createQueryWorker( prepared, node, consistencyTableNodes, exprList, limit, offset); workers.add(queryHandler); } }