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);
}
}
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);
}
}
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);
}
}
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);
}
}
};
}
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();
}
}
Aggregations