docs: @Override
  	protected String complete(final Criteria criteria, final Sort sort) {
  		if (tree.isDistinct() && !tree.isCountProjection()) {
  			LOGGER.debug("Use of 'Distinct' is meaningful only in count queries");
  		}
  		final StringBuilder query = new StringBuilder();
  
  		final String with = withCollections.stream().collect(Collectors.joining(", "));
  		if (!with.isEmpty()) {
  			query.append("WITH ").append(with).append(" ");
  		}
  
  		query.append("FOR ").append("e").append(" IN ").append(collectionName);
  
  		if (!criteria.getPredicate().isEmpty()) {
  			query.append(" FILTER ").append(criteria.getPredicate());
  		}
  
  		if (tree.isCountProjection() || tree.isExistsProjection()) {
  			if (tree.isDistinct()) {
  				query.append(" COLLECT entity = ").append("e");
  			}
  			query.append(" COLLECT WITH COUNT INTO length");
  		}
  
  		String sortString = " " + AqlUtils.buildSortClause(sort, "e");
  		if ((!this.geoFields.isEmpty() || isUnique != null && isUnique) && !tree.isDelete() && !tree.isCountProjection()
  				&& !tree.isExistsProjection()) {
  
  			final String distanceSortKey = " SORT " + Criteria
  					.distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1])).getPredicate();
  			if (sort.isUnsorted()) {
  				sortString = distanceSortKey;
  			} else {
  				sortString = distanceSortKey + ", " + sortString.substring(5, sortString.length());
  			}
  		}
  		query.append(sortString);
  
  		if (tree.isLimiting()) {
  			query.append(" LIMIT ").append(tree.getMaxResults());
  		}
  
  		final Pageable pageable = accessor.getPageable();
  		if (pageable != null && pageable.isPaged()) {
  			query.append(" ").append(AqlUtils.buildLimitClause(pageable));
  		}
  		if (tree.isDelete()) {
  			query.append(" REMOVE e IN ").append(collectionName);
  		} else if (tree.isCountProjection() || tree.isExistsProjection()) {
  			query.append(" RETURN length");
  		} else {
  			query.append(" RETURN ");
  			if (this.geoFields.isEmpty()) {
  				query.append("e");
  			} else {
  				query.append(format("MERGE(e, { '_distance': %s })",
  					Criteria.distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1]))
  							.getPredicate()));
  			}
  		}
  		return query.toString();
  	}