use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class BinaryConcatDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new AbstractBinaryScalarEvaluator(ctx, args) {
private final ListAccessor listAccessor = new ListAccessor();
private final byte[] metaBuffer = new byte[5];
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
byte[] data = pointables[0].getByteArray();
int offset = pointables[0].getStartOffset();
byte typeTag = data[offset];
if (typeTag != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG && typeTag != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, typeTag, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG);
}
try {
listAccessor.reset(data, offset);
int concatLength = 0;
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
if (itemType != ATypeTag.BINARY) {
if (serializeUnknownIfAnyUnknown(itemType)) {
result.set(resultStorage);
return;
}
throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
}
concatLength += ByteArrayPointable.getContentLength(data, itemOffset);
}
dataOutput.writeByte(ATypeTag.SERIALIZED_BINARY_TYPE_TAG);
int metaLen = VarLenIntEncoderDecoder.encode(concatLength, metaBuffer, 0);
dataOutput.write(metaBuffer, 0, metaLen);
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
int length = ByteArrayPointable.getContentLength(data, itemOffset);
dataOutput.write(data, itemOffset + ByteArrayPointable.getNumberBytesToStoreMeta(length), length);
}
} catch (IOException e) {
throw new HyracksDataException(e);
} catch (AsterixException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
private boolean serializeUnknownIfAnyUnknown(ATypeTag... tags) throws HyracksDataException {
for (ATypeTag typeTag : tags) {
if (typeTag == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, dataOutput);
return true;
}
if (typeTag == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, dataOutput);
return true;
}
}
return false;
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class ParseBinaryDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new AbstractBinaryScalarEvaluator(ctx, args) {
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABinary> binarySerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABINARY);
private AMutableBinary aBinary = new AMutableBinary(new byte[0], 0, 0);
private final UTF8StringPointable stringPointable = new UTF8StringPointable();
private final UTF8StringPointable formatPointable = new UTF8StringPointable();
private final HexParser hexParser = new HexParser();
private final Base64Parser base64Parser = new Base64Parser();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
evaluators[1].evaluate(tuple, pointables[1]);
ATypeTag binaryTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
ATypeTag formatTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, binaryTag, formatTag);
stringPointable.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength());
formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1, pointables[1].getLength());
if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
hexParser.generateByteArrayFromHexString(stringPointable.getByteArray(), stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
aBinary.setValue(hexParser.getByteArray(), 0, hexParser.getLength());
} else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
base64Parser.generatePureByteArrayFromBase64String(stringPointable.getByteArray(), stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
aBinary.setValue(base64Parser.getByteArray(), 0, base64Parser.getLength());
} else {
throw new UnsupportedItemTypeException(getIdentifier(), formatTag.serialize());
}
binarySerde.serialize(aBinary, dataOutput);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AIntervalConstructorDescriptor 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 argPtr0 = new VoidPointable();
private IPointable argPtr1 = new VoidPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInterval> intervalSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINTERVAL);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
eval1.evaluate(tuple, argPtr1);
byte[] bytes0 = argPtr0.getByteArray();
int offset0 = argPtr0.getStartOffset();
byte[] bytes1 = argPtr1.getByteArray();
int offset1 = argPtr1.getStartOffset();
try {
if (bytes0[offset0] != bytes1[offset1]) {
throw new IncompatibleTypeException(getIdentifier(), bytes0[offset0], bytes1[offset1]);
}
long intervalStart, intervalEnd;
ATypeTag intervalType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
switch(intervalType) {
case DATE:
intervalStart = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1);
intervalEnd = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case TIME:
intervalStart = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
intervalEnd = ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
case DATETIME:
intervalStart = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
intervalEnd = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
break;
default:
throw new UnsupportedItemTypeException(getIdentifier(), bytes0[offset0]);
}
if (intervalEnd < intervalStart) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
aInterval.setValue(intervalStart, intervalEnd, intervalType.serialize());
intervalSerde.serialize(aInterval, out);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class CreatePolygonDescriptor 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 ListAccessor listAccessor = new ListAccessor();
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IScalarEvaluatorFactory listEvalFactory = args[0];
private final IPointable inputArgList = new VoidPointable();
private final IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
private final ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
evalList.evaluate(tuple, inputArgList);
byte[] listBytes = inputArgList.getByteArray();
int offset = inputArgList.getStartOffset();
if (listBytes[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && listBytes[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, listBytes[offset], ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
}
listAccessor.reset(listBytes, offset);
try {
// First check the list consists of a valid items
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
if (itemType != ATypeTag.DOUBLE) {
if (itemType == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, out);
return;
}
if (itemType == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, out);
return;
}
throw new UnsupportedItemTypeException(BuiltinFunctions.CREATE_POLYGON, itemType.serialize());
}
}
if (listAccessor.size() < 6) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
} else if (listAccessor.size() % 2 != 0) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
out.writeByte(ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
out.writeShort(listAccessor.size() / 2);
final int skipTypeTag = listAccessor.itemsAreSelfDescribing() ? 1 : 0;
for (int i = 0; i < listAccessor.size() / 2; i++) {
int firstDoubleOffset = listAccessor.getItemOffset(i * 2) + skipTypeTag;
int secondDobuleOffset = listAccessor.getItemOffset((i * 2) + 1) + skipTypeTag;
APointSerializerDeserializer.serialize(ADoubleSerializerDeserializer.getDouble(listBytes, firstDoubleOffset), ADoubleSerializerDeserializer.getDouble(listBytes, secondDobuleOffset), out);
}
result.set(resultStorage);
} catch (AsterixException ex) {
throw new HyracksDataException(ex);
}
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
};
}
};
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class StringConcatDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final ListAccessor listAccessor = new ListAccessor();
private final DataOutput out = resultStorage.getDataOutput();
private final IScalarEvaluatorFactory listEvalFactory = args[0];
private final IPointable inputArgList = new VoidPointable();
private final IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
private ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
private final byte[] tempLengthArray = new byte[5];
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
try {
evalList.evaluate(tuple, inputArgList);
byte[] listBytes = inputArgList.getByteArray();
int listOffset = inputArgList.getStartOffset();
if (listBytes[listOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && listBytes[listOffset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, listBytes[listOffset], ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
}
listAccessor.reset(listBytes, listOffset);
try {
// calculate length first
int utf8Len = 0;
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
// since the item itself has a typetag.
if (listAccessor.itemsAreSelfDescribing()) {
itemOffset += 1;
}
if (itemType != ATypeTag.STRING) {
if (itemType == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, out);
result.set(resultStorage);
return;
}
if (itemType == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, out);
result.set(resultStorage);
return;
}
throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
}
utf8Len += UTF8StringUtil.getUTFLength(listBytes, itemOffset);
}
out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
int cbytes = UTF8StringUtil.encodeUTF8Length(utf8Len, tempLengthArray, 0);
out.write(tempLengthArray, 0, cbytes);
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
if (listAccessor.itemsAreSelfDescribing()) {
itemOffset += 1;
}
utf8Len = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
out.write(listBytes, UTF8StringUtil.getNumBytesToStoreLength(utf8Len) + itemOffset, utf8Len);
}
} catch (AsterixException ex) {
throw new HyracksDataException(ex);
}
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations