Given the results of a procedure, convert it into a sensible array of VoltTables.
@throws InvocationTargetException
329686
final static public VoltTable[] getResultsFromRawResults(String procedureName, Object result) throws InvocationTargetException {
        if (result == null) {
            return new VoltTable[0];
        }
        if (result instanceof VoltTable[]) {
            VoltTable[] retval = (VoltTable[]) result;
            for (VoltTable table : retval) {
                if (table == null) {
                    Exception e = new RuntimeException("VoltTable arrays with non-zero length cannot contain null values.");
                    throw new InvocationTargetException(e);
                }
                // Make sure this table does not use an ee cache buffer
                table.convertToHeapBuffer();
            }

            return retval;
        }
        if (result instanceof VoltTable) {
            VoltTable vt = (VoltTable) result;
            // Make sure this table does not use an ee cache buffer
            vt.convertToHeapBuffer();
            return new VoltTable[] { vt };
        }
        if (result instanceof Long) {
            VoltTable t = new VoltTable(new VoltTable.ColumnInfo("", VoltType.BIGINT));
            t.addRow(result);
            return new VoltTable[] { t };
        }
        throw new RuntimeException(String.format("Procedure %s unsupported procedure return type %s.",
                procedureName, result.getClass().getSimpleName()));
    }
938115
private Set<String> determineReturnTypes(final MethodResult result) {
        final List<Instruction> visitedInstructions = interpretRelevantInstructions(result.getInstructions());

        // find project defined methods in invoke occurrences
        final Set<ProjectMethod> projectMethods = findProjectMethods(visitedInstructions);

        // add project methods to global method pool
        projectMethods.forEach(MethodPool.getInstance()::addProjectMethod);

        final Element returnedElement = simulator.simulate(visitedInstructions);
        if (returnedElement == null) {
            // happens for abstract methods or if there is no return
            return singleton(result.getOriginalMethodSignature().getReturnType());
        }

        return returnedElement.getTypes();
    }
715226
public VoltTable[] run(SystemProcedureExecutionContext ctx) {
        createAndExecuteSysProcPlan(SysProcFragmentId.PF_shutdownSync, SysProcFragmentId.PF_shutdownSyncDone);

        SynthesizedPlanFragment pfs[] = new SynthesizedPlanFragment[] {
                new SynthesizedPlanFragment(SysProcFragmentId.PF_shutdownCommand, true) };

        executeSysProcPlanFragments(pfs, SysProcFragmentId.PF_procedureDone);
        return new VoltTable[0];
    }
951584
@Override
    public Iterator<T> iterator() {
        
        /*
         * We make a copy of the allResults list to iterate over in order to
         * avoid ConcurrentModificationExceptions caused by other methods
         * loading more results into the list while someone iterates over it.
         * This is a more severe problem than it might seem, because even
         * innocuous-seeming operations such as contains() can modify the
         * underlying result set.
         */
        final List<T> allResultsCopy = new ArrayList<T>();
        allResultsCopy.addAll(allResults);        
        final Iterator<T> iter = allResultsCopy.iterator();
        
        return new Iterator<T>() {
    
            Iterator<T> iterator = iter;
            int pos = 0;
            
            @Override
            public boolean hasNext() {
                return iterator.hasNext() || nextResultsAvailable();
            }
    
            @Override
            public T next() {
                if ( !iterator.hasNext() ) {
                    /*
                     * Our private copy of the result list may be out of date
                     * with the full one. If it is, we just need to update our
                     * private copy to get more results. If it's not, we need to
                     * fetch more results from the service.
                     */
                    if ( allResults.size() == allResultsCopy.size() ) {
                        if ( !nextResultsAvailable() ) {
                            throw new NoSuchElementException();
                        }
                        moveNextResults();
                    } 
                    
                    if ( allResults.size() > allResultsCopy.size() )
                        allResultsCopy.addAll(allResults.subList(allResultsCopy.size(), allResults.size()));
                    
                    iterator = allResultsCopy.listIterator(pos);
                }
                
                pos++;
                return iterator.next();
            }
            
            @Override
            public void remove() {
                throw new UnsupportedOperationException(UNMODIFIABLE_MESSAGE);
            }            
        };
    }
1014601
protected function processResults()
    {
        try {
            $this->log("Processing new result set.", Project::MSG_VERBOSE);

            $formatters = $this->getConfiguredFormatters();

            while ($row = $this->statement->fetch($this->fetchMode)) {
                foreach ($formatters as $formatter) {
                    $formatter->processRow($row);
                }
            }
        } catch (Exception $x) {
            $this->log("Error processing reults: " . $x->getMessage(), Project::MSG_ERR);
            foreach ($formatters as $formatter) {
                $formatter->close();
            }
            throw $x;
        }
    }
1135586
public function pagination(): array
	{
		if(empty($this->pagination))
		{
			if(empty($this->request))
			{
				throw new RuntimeException('A [ Request ] instance is required to generate the pagination array.');
			}

			if(empty($this->urlBuilder))
			{
				throw new RuntimeException('A [ URLBuilder ] instance is required to generate the pagination array.');
			}

			$pagination = $this->toArray();

			if($this->options['max_page_links'] !== 0)
			{
				if($this->pages > $this->options['max_page_links'])
				{
					$start = (int) max(($this->currentPage) - ceil($this->options['max_page_links'] / 2), 0);

					$end = $start + $this->options['max_page_links'];

					if($end > $this->pages)
					{
						$end = $this->pages;
					}

					if($start > ($end - $this->options['max_page_links']))
					{
						$start = $end - $this->options['max_page_links'];
					}
				}
				else
				{
					$start = 0;

					$end = $this->pages;
				}

				$pagination['pages'] = [];

				for($i = $start + 1; $i <= $end; $i++)
				{
					$pagination['pages'][] =
					[
						'url'        => $this->buildPageUrl($i),
						'number'     => $i,
						'is_current' => $i === $this->currentPage,
					];
				}
			}

			$this->pagination = $pagination;
		}

		return $this->pagination;
	}
1311849
public static <K, V> void forEach(Map<K, V> map, Procedure2<? super K, ? super V> procedure) {
		if (procedure == null)
			throw new NullPointerException("procedure");
		for (Map.Entry<K, V> entry : map.entrySet()) {
			procedure.apply(entry.getKey(), entry.getValue());
		}
	}
467950
public void each(VectorProcedure procedure) {
        VectorIterator it = iterator();

        while (it.hasNext()) {
            double x = it.next();
            int i = it.index();
            procedure.apply(i, x);
        }
    }
1144504
@Override
    public Object invoke(Object[] vals) throws InvocationTargetException {
        Object[] tmp;
        int i;

        try {
            if (isStatic()) {
                return meth.invoke(null, vals);
            } else {
                if (vals.length == 0) {
                    throw new IllegalArgumentException("invalid arguments");
                }

                tmp = new Object[vals.length - 1];
                for (i = 1; i < vals.length; i++) {
                    tmp[i-1] = vals[i];
                }

                return meth.invoke(vals[0], tmp);
            }
        } catch (InvocationTargetException | IllegalArgumentException e) {
            throw e;
        } catch (IllegalAccessException e) {
            // isValid should prevent this
            throw new RuntimeException("can't access method");
        }
    }
1060257
protected Object[] invoke(Object[] arguments)
	throws InvocationTargetException, IllegalAccessException {
		Object returnValue = invoke(method, arguments);

		if (! scatterOutput) {
			logger.trace("Using return as is");
			return new Object[] {returnValue};
		}

		if (returnValue instanceof Object[]) {
			logger.trace("Scatter array return");
			return (Object[]) returnValue;
		}

		if (returnValue instanceof Collection) {
			logger.trace("Scatter collection return");
			return ((Collection) returnValue).toArray();
		}

		logger.debug("Scatter singleton return");
		return returnValue == null ? EMPTY_ARRAY : new Object[] {returnValue};
	}
1148374
protected function initializeResult()
    {
        /** @var ProcessorResult $result */
        $this->result = app(ProcessorResult::class);

        $this->result->setSuccess(false);
        $this->result->setErrors( app(MessageBag::class) );
        $this->result->setWarnings( app(MessageBag::class) );
    }
1252391
public void eachNonZeroInRow(int i, VectorProcedure procedure) {
        VectorIterator it = nonZeroIteratorOfRow(i);

        while (it.hasNext()) {
            double x = it.next();
            int j = it.index();
            procedure.apply(j, x);
        }
    }
612504
public void each(MatrixProcedure procedure) {
        MatrixIterator it = iterator();

        while (it.hasNext()) {
            double x = it.next();
            int i = it.rowIndex();
            int j = it.columnIndex();
            procedure.apply(i, j, x);
        }
    }
106189
@Override
    public Object invoke(Object[] vals) throws InvocationTargetException {
        try {
            return constr.newInstance(vals);
        } catch (InvocationTargetException | IllegalArgumentException e) {
            throw e;
        } catch (IllegalAccessException e) {
            // runtime exception, isValid should prevent this case
            throw new RuntimeException("can't access constructor");
        } catch (InstantiationException e) {
            // runtime excpetion, because the constructor of constructor
            // has to prevent this situation.
            throw new RuntimeException("can't instantiate");
        }
    }
810830
public int[] executeBatch() throws SQLException {
        final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
        SQLExecuteCallback<int[]> callback = new SQLExecuteCallback<int[]>(getDatabaseType(), isExceptionThrown) {
            
            @Override
            protected int[] executeSQL(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) throws SQLException {
                return statement.executeBatch();
            }
        };
        List<int[]> results = executeCallback(callback);
        if (isAccumulate()) {
            return accumulate(results);
        } else {
            return results.get(0);
        }
    }
1204687
public Array listToArray() throws PageException {

	if (this.query instanceof QueryImpl) return ListUtil.listToArray(((QueryImpl) this.query).getColumnlist(false), ",");

	throw new ApplicationException("Query is not of type QueryImpl. Use instead Query.columnArray() or Query.columnList().listToArray().");
    }
584787
public void writeInvocation(StoredProcedureInvocation invocation) throws IOException {
        int len = invocation.getSerializedSize();
        growIfNeeded(len);
        invocation.flattenToBuffer(buffer.b());
    }