Search in sources :

Example 1 with ResultSetMetaData

use of org.apache.hyracks.api.dataset.ResultSetMetaData in project asterixdb by apache.

the class Waiter method updatedRecords.

/**
     * Compares the records already known by the client for the given job's result set id with the records that the
     * dataset directory service knows and if there are any newly discovered records returns a whole array with the
     * new records filled in.
     *
     * @param jobId
     *            - Id of the job for which the directory records should be retrieved.
     * @param rsId
     *            - Id of the result set for which the directory records should be retrieved.
     * @param knownRecords
     *            - An array of directory records that the client is already aware of.
     * @return
     *         Returns the updated records if new record were discovered, null otherwise
     * @throws HyracksDataException
     *             TODO(madhusudancs): Think about caching (and still be stateless) instead of this ugly O(n) iterations for
     *             every check. This already looks very expensive.
     */
private DatasetDirectoryRecord[] updatedRecords(JobId jobId, ResultSetId rsId, DatasetDirectoryRecord[] knownRecords) throws HyracksDataException {
    DatasetJobRecord djr = getNonNullDatasetJobRecord(jobId);
    if (djr.getStatus().getState() == State.FAILED) {
        List<Exception> caughtExceptions = djr.getStatus().getExceptions();
        if (caughtExceptions != null && !caughtExceptions.isEmpty()) {
            final Exception cause = caughtExceptions.get(caughtExceptions.size() - 1);
            if (cause instanceof HyracksDataException) {
                throw (HyracksDataException) cause;
            }
            throw HyracksDataException.create(ErrorCode.RESULT_FAILURE_EXCEPTION, cause, rsId, jobId);
        } else {
            throw HyracksDataException.create(ErrorCode.RESULT_FAILURE_NO_EXCEPTION, rsId, jobId);
        }
    }
    final ResultSetMetaData resultSetMetaData = djr.getResultSetMetaData(rsId);
    if (resultSetMetaData == null) {
        return null;
    }
    DatasetDirectoryRecord[] records = resultSetMetaData.getRecords();
    return Arrays.equals(records, knownRecords) ? null : records;
}
Also used : ResultSetMetaData(org.apache.hyracks.api.dataset.ResultSetMetaData) DatasetJobRecord(org.apache.hyracks.api.dataset.DatasetJobRecord) DatasetDirectoryRecord(org.apache.hyracks.api.dataset.DatasetDirectoryRecord) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

DatasetDirectoryRecord (org.apache.hyracks.api.dataset.DatasetDirectoryRecord)1 DatasetJobRecord (org.apache.hyracks.api.dataset.DatasetJobRecord)1 ResultSetMetaData (org.apache.hyracks.api.dataset.ResultSetMetaData)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)1