Search in sources :

Example 16 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class RecordBuilder method writeRecord.

private void writeRecord(DataOutput out, boolean writeTypeTag, int headerSize, int recordLength) throws HyracksDataException {
    try {
        // write the record header
        if (writeTypeTag) {
            out.writeByte(ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
        }
        out.writeInt(recordLength);
        if (isOpen) {
            if (this.numberOfOpenFields > 0) {
                out.writeBoolean(true);
                out.writeInt(openPartOffset);
            } else {
                out.writeBoolean(false);
            }
        }
        // write the closed part
        if (numberOfSchemaFields > 0) {
            out.writeInt(numberOfClosedFields);
            if (containsOptionalField) {
                out.write(nullBitMap, 0, nullBitMapSize);
            }
            for (int i = 0; i < numberOfSchemaFields; i++) {
                out.writeInt(closedPartOffsets[i] + headerSize + (numberOfSchemaFields * 4));
            }
            out.write(closedPartOutputStream.getByteArray(), 0, closedPartOutputStream.getLength());
        }
        // write the open part
        if (numberOfOpenFields > 0) {
            out.writeInt(numberOfOpenFields);
            out.write(openPartOffsetArray, 0, openPartOffsetArraySize);
            out.write(openPartOutputStream.getByteArray(), 0, openPartOutputStream.getLength());
        }
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 17 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class PrintTools method printDayTimeDurationString.

public static void printDayTimeDurationString(byte[] b, int s, int l, PrintStream ps) throws HyracksDataException {
    boolean positive = true;
    long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);
    // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
    if (milliseconds < 0) {
        milliseconds *= -1;
        positive = false;
    }
    int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
    int second = gCalInstance.getDurationSecond(milliseconds);
    int minute = gCalInstance.getDurationMinute(milliseconds);
    int hour = gCalInstance.getDurationHour(milliseconds);
    int day = gCalInstance.getDurationDay(milliseconds);
    if (!positive) {
        ps.print("-");
    }
    try {
        ps.print("P");
        if (day != 0) {
            WriteValueTools.writeInt(day, ps);
            ps.print("D");
        }
        if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
            ps.print("T");
        }
        if (hour != 0) {
            WriteValueTools.writeInt(hour, ps);
            ps.print("H");
        }
        if (minute != 0) {
            WriteValueTools.writeInt(minute, ps);
            ps.print("M");
        }
        if (second != 0 || millisecond != 0) {
            WriteValueTools.writeInt(second, ps);
        }
        if (millisecond > 0) {
            ps.print(".");
            WriteValueTools.writeInt(millisecond, ps);
        }
        if (second != 0 || millisecond != 0) {
            ps.print("S");
        }
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 18 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class PrintTools method printYearMonthDurationString.

public static void printYearMonthDurationString(byte[] b, int s, int l, PrintStream ps) throws HyracksDataException {
    final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
    boolean positive = true;
    int months = AInt32SerializerDeserializer.getInt(b, s + 1);
    // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
    if (months < 0) {
        months *= -1;
        positive = false;
    }
    int month = gCalInstance.getDurationMonth(months);
    int year = gCalInstance.getDurationYear(months);
    if (!positive) {
        ps.print("-");
    }
    try {
        ps.print("P");
        if (year != 0) {
            WriteValueTools.writeInt(year, ps);
            ps.print("Y");
        }
        if (month != 0) {
            WriteValueTools.writeInt(month, ps);
            ps.print("M");
        }
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : GregorianCalendarSystem(org.apache.asterix.om.base.temporal.GregorianCalendarSystem) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 19 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class AObjectPrinterFactory method createPrinter.

@Override
public IPrinter createPrinter() {
    final ARecordVisitablePointable rPointable = new ARecordVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE);
    final AListVisitablePointable olPointable = new AListVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE);
    final AListVisitablePointable ulPointable = new AListVisitablePointable(DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE);
    final Pair<PrintStream, ATypeTag> streamTag = new Pair<>(null, null);
    final IPrintVisitor visitor = new APrintVisitor();
    return (byte[] b, int s, int l, PrintStream ps) -> {
        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b[s]);
        if (!printFlatValue(typeTag, b, s, l, ps)) {
            streamTag.first = ps;
            streamTag.second = typeTag;
            switch(typeTag) {
                case OBJECT:
                    rPointable.set(b, s, l);
                    visitor.visit(rPointable, streamTag);
                    break;
                case ARRAY:
                    olPointable.set(b, s, l);
                    visitor.visit(olPointable, streamTag);
                    break;
                case MULTISET:
                    ulPointable.set(b, s, l);
                    visitor.visit(ulPointable, streamTag);
                    break;
                default:
                    throw new HyracksDataException("No printer for type " + typeTag);
            }
        }
    };
}
Also used : PrintStream(java.io.PrintStream) ARecordVisitablePointable(org.apache.asterix.om.pointables.ARecordVisitablePointable) AListVisitablePointable(org.apache.asterix.om.pointables.AListVisitablePointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) IPrintVisitor(org.apache.asterix.om.pointables.printer.IPrintVisitor) APrintVisitor(org.apache.asterix.om.pointables.printer.adm.APrintVisitor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 20 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class CommitRuntime method nextFrame.

@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
    tAccess.reset(buffer);
    int nTuple = tAccess.getTupleCount();
    for (int t = 0; t < nTuple; t++) {
        if (isTemporaryDatasetWriteJob) {
            /**
                 * This "if branch" is for writes over temporary datasets. A temporary dataset does not require any lock
                 * and does not generate any write-ahead update and commit log but generates flush log and job commit
                 * log. However, a temporary dataset still MUST guarantee no-steal policy so that this notification call
                 * should be delivered to PrimaryIndexOptracker and used correctly in order to decrement number of
                 * active operation count of PrimaryIndexOptracker. By maintaining the count correctly and only allowing
                 * flushing when the count is 0, it can guarantee the no-steal policy for temporary datasets, too.
                 */
            // TODO: Fix this for upserts. an upsert tuple right now expect to notify the opTracker twice (one for
            // delete and one for insert)
            transactionContext.notifyOptracker(false);
        } else {
            tRef.reset(tAccess, t);
            try {
                formLogRecord(buffer, t);
                logMgr.log(logRecord);
                if (!isSink) {
                    appendTupleToFrame(t);
                }
            } catch (ACIDException e) {
                throw new HyracksDataException(e);
            }
        }
    }
    IFrame message = TaskUtil.get(HyracksConstants.KEY_MESSAGE, ctx);
    if (message != null && MessagingFrameTupleAppender.getMessageType(message) == MessagingFrameTupleAppender.MARKER_MESSAGE) {
        try {
            formMarkerLogRecords(message.getBuffer());
            logMgr.log(logRecord);
        } catch (ACIDException e) {
            throw new HyracksDataException(e);
        }
        message.reset();
        message.getBuffer().put(MessagingFrameTupleAppender.NULL_FEED_MESSAGE);
        message.getBuffer().flip();
    }
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)566 IOException (java.io.IOException)209 DataOutput (java.io.DataOutput)96 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)78 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)75 IPointable (org.apache.hyracks.data.std.api.IPointable)73 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)70 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)67 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)67 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)64 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)61 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)60 ArrayList (java.util.ArrayList)57 ACIDException (org.apache.asterix.common.exceptions.ACIDException)56 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)56 ATypeTag (org.apache.asterix.om.types.ATypeTag)39 AsterixException (org.apache.asterix.common.exceptions.AsterixException)36 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)32 ByteBuffer (java.nio.ByteBuffer)30 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)27