use of org.apache.asterix.runtime.exceptions.InvalidDataFormatException in project asterixdb by apache.
the class ADayTimeDurationConstructorDescriptor 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 AMutableDayTimeDuration aDayTimeDuration = new AMutableDayTimeDuration(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADayTimeDuration> dayTimeDurationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADAYTIMEDURATION);
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 offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
int startOffset = utf8Ptr.getCharStartOffset();
ADurationParserFactory.parseDuration(serString, startOffset, stringLength, aDayTimeDuration, ADurationParseOption.DAY_TIME);
dayTimeDurationSerde.serialize(aDayTimeDuration, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (Exception e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.InvalidDataFormatException in project asterixdb by apache.
the class ADoubleConstructorDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final byte[] POSITIVE_INF = UTF8StringUtil.writeStringToBytes("INF");
private final byte[] NEGATIVE_INF = UTF8StringUtil.writeStringToBytes("-INF");
private final byte[] NAN = UTF8StringUtil.writeStringToBytes("NaN");
IBinaryComparator utf8BinaryComparator = BinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE.createBinaryComparator();
private AMutableDouble aDouble = new AMutableDouble(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADouble> doubleSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
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 offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, POSITIVE_INF, 0, 5) == 0) {
aDouble.setValue(Double.POSITIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NEGATIVE_INF, 0, 6) == 0) {
aDouble.setValue(Double.NEGATIVE_INFINITY);
} else if (utf8BinaryComparator.compare(serString, offset + 1, len - 1, NAN, 0, 5) == 0) {
aDouble.setValue(Double.NaN);
} else {
utf8Ptr.set(serString, offset + 1, len - 1);
aDouble.setValue(Double.parseDouble(utf8Ptr.toString()));
}
doubleSerde.serialize(aDouble, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.InvalidDataFormatException in project asterixdb by apache.
the class ADurationConstructorDescriptor 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 AMutableDuration aDuration = new AMutableDuration(0, 0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);
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 offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
ADurationParserFactory.parseDuration(serString, utf8Ptr.getCharStartOffset(), stringLength, aDuration, ADurationParseOption.All);
durationSerde.serialize(aDuration, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.InvalidDataFormatException in project asterixdb by apache.
the class AStringConstructorDescriptor 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 UTF8StringBuilder builder = new UTF8StringBuilder();
private GrowableArray baaos = new GrowableArray();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
baaos.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
ATypeTag tt = ATypeTag.VALUE_TYPE_MAPPING[serString[offset]];
if (tt == ATypeTag.STRING) {
result.set(inputArg);
} else {
builder.reset(baaos, len);
int startOffset = offset + 1;
switch(tt) {
case TINYINT:
{
int i = AInt8SerializerDeserializer.getByte(serString, startOffset);
builder.appendString(String.valueOf(i));
break;
}
case SMALLINT:
{
int i = AInt16SerializerDeserializer.getShort(serString, startOffset);
builder.appendString(String.valueOf(i));
break;
}
case INTEGER:
{
int i = AInt32SerializerDeserializer.getInt(serString, startOffset);
builder.appendString(String.valueOf(i));
break;
}
case BIGINT:
{
long l = AInt64SerializerDeserializer.getLong(serString, startOffset);
builder.appendString(String.valueOf(l));
break;
}
case DOUBLE:
{
double d = ADoubleSerializerDeserializer.getDouble(serString, startOffset);
builder.appendString(String.valueOf(d));
break;
}
case FLOAT:
{
float f = AFloatSerializerDeserializer.getFloat(serString, startOffset);
builder.appendString(String.valueOf(f));
break;
}
case BOOLEAN:
{
boolean b = ABooleanSerializerDeserializer.getBoolean(serString, startOffset);
builder.appendString(String.valueOf(b));
break;
}
// NotYetImplemented
case CIRCLE:
case DATE:
case DATETIME:
case LINE:
case TIME:
case DURATION:
case YEARMONTHDURATION:
case DAYTIMEDURATION:
case INTERVAL:
case ARRAY:
case POINT:
case POINT3D:
case RECTANGLE:
case POLYGON:
case OBJECT:
case MULTISET:
case UUID:
default:
throw new UnsupportedTypeException(getIdentifier(), serString[offset]);
}
builder.finish();
out.write(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
out.write(baaos.getByteArray(), 0, baaos.getLength());
result.set(resultStorage);
}
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.InvalidDataFormatException in project asterixdb by apache.
the class ATimeConstructorDescriptor 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 AMutableTime aTime = new AMutableTime(0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ATime> timeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
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 offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
int stringLength = utf8Ptr.getUTF8Length();
int startOffset = utf8Ptr.getCharStartOffset();
// the string to be parsed should be at least 6 characters: hhmmss
if (stringLength < 6) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
int chrononTimeInMs = ATimeParserFactory.parseTimePart(serString, startOffset, stringLength);
if (chrononTimeInMs < 0) {
chrononTimeInMs += GregorianCalendarSystem.CHRONON_OF_DAY;
}
aTime.setValue(chrononTimeInMs);
timeSerde.serialize(aTime, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
}
};
}
};
}
Aggregations