use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Operation method doArithmetic.
public static int doArithmetic(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
AMutableInt64 i1 = objectPool.int64Pool.get();
AMutableInt64 i2 = objectPool.int64Pool.get();
ClassAdTime t1 = objectPool.classAdTimePool.get();
AMutableDouble r1 = objectPool.doublePool.get();
MutableBoolean b1 = objectPool.boolPool.get();
// ensure the operands have arithmetic types
if ((!v1.isIntegerValue() && !v1.isRealValue() && !v1.isAbsoluteTimeValue() && !v1.isRelativeTimeValue() && !v1.isBooleanValue()) || (op != OpKind_UNARY_MINUS_OP && !v2.isBooleanValue() && !v2.isIntegerValue() && !v2.isRealValue() && !v2.isAbsoluteTimeValue() && !v2.isRelativeTimeValue())) {
result.setErrorValue();
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
// take care of the unary arithmetic operators
if (op == OpKind_UNARY_MINUS_OP) {
if (v1.isIntegerValue(i1)) {
result.setIntegerValue((-1L) * i1.getLongValue());
return SigValues.SIG_CHLD1.ordinal();
} else if (v1.isRealValue(r1)) {
result.setRealValue((-1) * r1.getDoubleValue());
return SigValues.SIG_CHLD1.ordinal();
} else if (v1.isRelativeTimeValue(t1)) {
t1.setValue((-1) * t1.getTimeInMillis());
result.setRelativeTimeValue(t1);
return (SigValues.SIG_CHLD1.ordinal());
} else if (v1.isBooleanValue(b1)) {
result.setBooleanValue(!b1.booleanValue());
} else if (v1.isExceptional()) {
// undefined or error --- same as operand
result.setValue(v1);
return SigValues.SIG_CHLD1.ordinal();
}
// unary minus not defined on any other operand type
result.setErrorValue();
return (SigValues.SIG_CHLD1.ordinal());
}
// perform type promotions and proceed with arithmetic
switch(coerceToNumber(v1, v2, objectPool)) {
case INTEGER_VALUE:
v1.isIntegerValue(i1);
v2.isIntegerValue(i2);
switch(op) {
case OpKind_ADDITION_OP:
result.setIntegerValue(i1.getLongValue() + i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_SUBTRACTION_OP:
result.setIntegerValue(i1.getLongValue() - i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_MULTIPLICATION_OP:
result.setIntegerValue(i1.getLongValue() * i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_DIVISION_OP:
if (i2.getLongValue() != 0L) {
result.setIntegerValue(i1.getLongValue() / i2.getLongValue());
} else {
result.setErrorValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_MODULUS_OP:
if (i2.getLongValue() != 0) {
result.setIntegerValue(i1.getLongValue() % i2.getLongValue());
} else {
result.setErrorValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
default:
// should not reach here
throw new HyracksDataException("Should not get here");
}
case REAL_VALUE:
{
return (doRealArithmetic(op, v1, v2, result, objectPool));
}
case ABSOLUTE_TIME_VALUE:
case RELATIVE_TIME_VALUE:
{
return (doTimeArithmetic(op, v1, v2, result, objectPool));
}
default:
// should not get here
throw new HyracksDataException("Should not get here");
}
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class Operation method compareIntegers.
public static void compareIntegers(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
AMutableInt64 i1 = objectPool.int64Pool.get();
AMutableInt64 i2 = objectPool.int64Pool.get();
boolean compResult = false;
v1.isIntegerValue(i1);
v2.isIntegerValue(i2);
switch(op) {
case OpKind_LESS_THAN_OP:
compResult = (i1.getLongValue() < i2.getLongValue());
break;
case OpKind_LESS_OR_EQUAL_OP:
compResult = (i1.getLongValue() <= i2.getLongValue());
break;
case OpKind_EQUAL_OP:
compResult = (i1.getLongValue() == i2.getLongValue());
break;
case OpKind_META_EQUAL_OP:
compResult = (i1.getLongValue() == i2.getLongValue());
break;
case OpKind_NOT_EQUAL_OP:
compResult = (i1.getLongValue() != i2.getLongValue());
break;
case OpKind_META_NOT_EQUAL_OP:
compResult = (i1.getLongValue() != i2.getLongValue());
break;
case OpKind_GREATER_THAN_OP:
compResult = (i1.getLongValue() > i2.getLongValue());
break;
case OpKind_GREATER_OR_EQUAL_OP:
compResult = (i1.getLongValue() >= i2.getLongValue());
break;
default:
// should not get here
throw new HyracksDataException("Should not get here");
}
result.setBooleanValue(compResult);
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class ExprTree method debugFormatValue.
public void debugFormatValue(Value value, double time) throws HyracksDataException {
MutableBoolean boolValue = objectPool.boolPool.get();
AMutableInt64 intValue = objectPool.int64Pool.get();
AMutableDouble doubleValue = objectPool.doublePool.get();
AMutableCharArrayString stringValue = objectPool.strPool.get();
if (NodeKind.CLASSAD_NODE == getKind()) {
return;
}
PrettyPrint unp = objectPool.prettyPrintPool.get();
AMutableCharArrayString buffer = objectPool.strPool.get();
unp.unparse(buffer, this);
String result = "Classad debug: ";
if (time != 0) {
String buf = String.format("%5.5fms", time * 1000);
result += "[";
result += buf;
result += "] ";
}
result += buffer;
result += " --> ";
switch(value.getType()) {
case NULL_VALUE:
result += "NULL\n";
break;
case ERROR_VALUE:
if ((NodeKind.FN_CALL_NODE == getKind()) && !((FunctionCall) (this)).functionIsDefined()) {
result += "ERROR (function is not defined)\n";
} else {
result += "ERROR\n";
}
break;
case UNDEFINED_VALUE:
result += "UNDEFINED\n";
break;
case BOOLEAN_VALUE:
if (value.isBooleanValue(boolValue)) {
result += boolValue.booleanValue() ? "TRUE\n" : "FALSE\n";
}
break;
case INTEGER_VALUE:
if (value.isIntegerValue(intValue)) {
result += String.format("%lld", intValue.getLongValue());
result += "\n";
}
break;
case REAL_VALUE:
if (value.isRealValue(doubleValue)) {
result += String.format("%lld", doubleValue.getDoubleValue());
result += "\n";
}
break;
case RELATIVE_TIME_VALUE:
result += "RELATIVE TIME\n";
break;
case ABSOLUTE_TIME_VALUE:
result += "ABSOLUTE TIME\n";
break;
case STRING_VALUE:
if (value.isStringValue(stringValue)) {
result += stringValue.toString();
result += "\n";
}
break;
case CLASSAD_VALUE:
result += "CLASSAD\n";
break;
case LIST_VALUE:
result += "LIST\n";
break;
case SLIST_VALUE:
result += "SLIST\n";
break;
}
debugPrint(result);
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class AbstractNumericArithmeticEval method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) throws AlgebricksException {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable argPtr0 = new VoidPointable();
private IPointable argPtr1 = new VoidPointable();
private IScalarEvaluator evalLeft = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalRight = args[1].createScalarEvaluator(ctx);
private double[] operandsFloating = new double[args.length];
private long[] operandsInteger = new long[args.length];
private int resultType;
protected static final int typeInt8 = 1;
protected static final int typeInt16 = 2;
protected static final int typeInt32 = 3;
protected static final int typeInt64 = 4;
protected static final int typeFloat = 5;
protected static final int typeDouble = 6;
protected AMutableFloat aFloat = new AMutableFloat(0);
protected AMutableDouble aDouble = new AMutableDouble(0);
protected AMutableInt64 aInt64 = new AMutableInt64(0);
protected AMutableInt32 aInt32 = new AMutableInt32(0);
protected AMutableInt16 aInt16 = new AMutableInt16((short) 0);
protected AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
protected AMutableDuration aDuration = new AMutableDuration(0, 0);
protected AMutableDate aDate = new AMutableDate(0);
protected AMutableTime aTime = new AMutableTime(0);
protected AMutableDateTime aDatetime = new AMutableDateTime(0);
private ATypeTag typeTag;
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde;
@SuppressWarnings("unchecked")
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
resultType = 0;
int currentType;
evalLeft.evaluate(tuple, argPtr0);
evalRight.evaluate(tuple, argPtr1);
for (int i = 0; i < args.length; i++) {
IPointable argPtr = i == 0 ? argPtr0 : argPtr1;
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
switch(typeTag) {
case TINYINT:
currentType = typeInt8;
operandsInteger[i] = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
operandsFloating[i] = operandsInteger[i];
break;
case SMALLINT:
currentType = typeInt16;
operandsInteger[i] = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
operandsFloating[i] = operandsInteger[i];
break;
case INTEGER:
currentType = typeInt32;
operandsInteger[i] = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
operandsFloating[i] = operandsInteger[i];
break;
case BIGINT:
currentType = typeInt64;
operandsInteger[i] = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
operandsFloating[i] = operandsInteger[i];
break;
case FLOAT:
currentType = typeFloat;
operandsFloating[i] = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
break;
case DOUBLE:
currentType = typeDouble;
operandsFloating[i] = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
break;
case DATE:
case TIME:
case DATETIME:
case DURATION:
case YEARMONTHDURATION:
case DAYTIMEDURATION:
evaluateTemporalArthmeticOperation(typeTag);
result.set(resultStorage);
return;
default:
throw new TypeMismatchException(getIdentifier(), i, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG, ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG);
}
if (resultType < currentType) {
resultType = currentType;
}
}
long lres;
double dres;
switch(resultType) {
case typeInt8:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
if (lres > Byte.MAX_VALUE) {
throw new OverflowException(getIdentifier());
}
if (lres < Byte.MIN_VALUE) {
throw new UnderflowException(getIdentifier());
}
aInt8.setValue((byte) lres);
serde.serialize(aInt8, out);
break;
case typeInt16:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
if (lres > Short.MAX_VALUE) {
throw new OverflowException(getIdentifier());
}
if (lres < Short.MIN_VALUE) {
throw new UnderflowException(getIdentifier());
}
aInt16.setValue((short) lres);
serde.serialize(aInt16, out);
break;
case typeInt32:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
if (lres > Integer.MAX_VALUE) {
throw new OverflowException(getIdentifier());
}
if (lres < Integer.MIN_VALUE) {
throw new UnderflowException(getIdentifier());
}
aInt32.setValue((int) lres);
serde.serialize(aInt32, out);
break;
case typeInt64:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
aInt64.setValue(lres);
serde.serialize(aInt64, out);
break;
case typeFloat:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
dres = evaluateDouble(operandsFloating[0], operandsFloating[1]);
if (dres > Float.MAX_VALUE) {
throw new OverflowException(getIdentifier());
}
if (dres < -Float.MAX_VALUE) {
throw new UnderflowException(getIdentifier());
}
aFloat.setValue((float) dres);
serde.serialize(aFloat, out);
break;
case typeDouble:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
aDouble.setValue(evaluateDouble(operandsFloating[0], operandsFloating[1]));
serde.serialize(aDouble, out);
break;
}
result.set(resultStorage);
}
@SuppressWarnings("unchecked")
private void evaluateTemporalArthmeticOperation(ATypeTag leftType) throws HyracksDataException {
byte[] bytes1 = argPtr1.getByteArray();
int offset1 = argPtr1.getStartOffset();
ATypeTag rightType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
byte[] bytes0 = argPtr0.getByteArray();
int offset0 = argPtr0.getStartOffset();
if (rightType == leftType) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
long leftChronon = 0, rightChronon = 0, dayTime = 0;
int yearMonth = 0;
switch(leftType) {
case DATE:
leftChronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
rightChronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
break;
case TIME:
leftChronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
rightChronon = ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case DATETIME:
leftChronon = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
rightChronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case YEARMONTHDURATION:
yearMonth = (int) evaluateTimeInstanceArithmetic(AYearMonthDurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1), AYearMonthDurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1));
break;
case DAYTIMEDURATION:
leftChronon = ADayTimeDurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1);
rightChronon = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
break;
default:
throw new UnsupportedTypeException(getIdentifier(), bytes1[offset1]);
}
dayTime = evaluateTimeInstanceArithmetic(leftChronon, rightChronon);
aDuration.setValue(yearMonth, dayTime);
serde.serialize(aDuration, out);
} else {
long chronon = 0, dayTime = 0;
int yearMonth = 0;
ATypeTag resultType = null;
boolean isTimeOnly = false;
switch(leftType) {
case TIME:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
chronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
isTimeOnly = true;
resultType = ATypeTag.TIME;
switch(rightType) {
case DAYTIMEDURATION:
dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
break;
case DURATION:
dayTime = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1);
break;
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
break;
case DATE:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
resultType = ATypeTag.DATE;
chronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
case DATETIME:
if (leftType == ATypeTag.DATETIME) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
resultType = ATypeTag.DATETIME;
chronon = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
}
switch(rightType) {
case DURATION:
yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1);
dayTime = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
break;
case YEARMONTHDURATION:
yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1);
break;
case DAYTIMEDURATION:
dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
break;
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
break;
case YEARMONTHDURATION:
yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1);
switch(rightType) {
case DATETIME:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
resultType = ATypeTag.DATETIME;
chronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case DATE:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
resultType = ATypeTag.DATE;
chronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
break;
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
break;
case DURATION:
yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1);
dayTime = ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1);
case DAYTIMEDURATION:
if (leftType == ATypeTag.DAYTIMEDURATION) {
dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1);
}
switch(rightType) {
case DATETIME:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
resultType = ATypeTag.DATETIME;
chronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case DATE:
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
resultType = ATypeTag.DATE;
chronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
break;
case TIME:
if (yearMonth == 0) {
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
resultType = ATypeTag.TIME;
chronon = ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
isTimeOnly = true;
break;
}
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
break;
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
chronon = evaluateTimeDurationArithmetic(chronon, yearMonth, dayTime, isTimeOnly);
switch(resultType) {
case DATE:
if (chronon < 0 && chronon % GregorianCalendarSystem.CHRONON_OF_DAY != 0) {
chronon = chronon / GregorianCalendarSystem.CHRONON_OF_DAY - 1;
} else {
chronon = chronon / GregorianCalendarSystem.CHRONON_OF_DAY;
}
aDate.setValue((int) chronon);
serde.serialize(aDate, out);
break;
case TIME:
aTime.setValue((int) chronon);
serde.serialize(aTime, out);
break;
case DATETIME:
aDatetime.setValue(chronon);
serde.serialize(aDatetime, out);
break;
default:
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
}
}
};
}
};
}
use of org.apache.asterix.om.base.AMutableInt64 in project asterixdb by apache.
the class AInt64ConstructorDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private long value;
private int offset;
private boolean positive;
private AMutableInt64 aInt64 = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int startOffset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, startOffset + 1, len - 1);
offset = utf8Ptr.getCharStartOffset();
//accumulating value in negative domain
//otherwise Long.MIN_VALUE = -(Long.MAX_VALUE + 1) would have caused overflow
value = 0;
positive = true;
long limit = -Long.MAX_VALUE;
if (serString[offset] == '+') {
offset++;
} else if (serString[offset] == '-') {
offset++;
positive = false;
limit = Long.MIN_VALUE;
}
int end = startOffset + len;
for (; offset < end; offset++) {
int digit;
if (serString[offset] >= '0' && serString[offset] <= '9') {
value *= 10;
digit = serString[offset] - '0';
} else if (serString[offset] == 'i' && serString[offset + 1] == '6' && serString[offset + 2] == '4' && offset + 3 == end) {
break;
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
if (value < limit + digit) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
value -= digit;
}
if (value > 0) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
if (value < 0 && positive) {
value *= -1;
}
aInt64.setValue(value);
int64Serde.serialize(aInt64, out);
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
}
}
};
}
};
}
Aggregations