use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSumAggregateFunction method step.
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
if (skipStep()) {
return;
}
eval.evaluate(tuple, inputVal);
byte[] data = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull();
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.SUM, typeTag.serialize(), aggType.serialize());
}
if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
sum += val;
break;
}
case SYSTEM_NULL:
{
processSystemNull();
break;
}
default:
{
throw new UnsupportedItemTypeException(BuiltinFunctions.SUM, aggType.serialize());
}
}
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSumAggregateFunction method finish.
@SuppressWarnings("unchecked")
@Override
public void finish(IPointable result) throws HyracksDataException {
resultStorage.reset();
try {
switch(aggType) {
case TINYINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
aInt8.setValue((byte) sum);
serde.serialize(aInt8, resultStorage.getDataOutput());
break;
}
case SMALLINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
aInt16.setValue((short) sum);
serde.serialize(aInt16, resultStorage.getDataOutput());
break;
}
case INTEGER:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
aInt32.setValue((int) sum);
serde.serialize(aInt32, resultStorage.getDataOutput());
break;
}
case BIGINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
aInt64.setValue((long) sum);
serde.serialize(aInt64, resultStorage.getDataOutput());
break;
}
case FLOAT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
aFloat.setValue((float) sum);
serde.serialize(aFloat, resultStorage.getDataOutput());
break;
}
case DOUBLE:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
aDouble.setValue(sum);
serde.serialize(aDouble, resultStorage.getDataOutput());
break;
}
case NULL:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
serde.serialize(ANull.NULL, resultStorage.getDataOutput());
break;
}
case SYSTEM_NULL:
{
finishSystemNull();
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.SUM, aggType.serialize());
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractSerializableSumAggregateFunction method finish.
@SuppressWarnings("unchecked")
@Override
public void finish(byte[] state, int start, int len, DataOutput out) throws HyracksDataException {
ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
try {
switch(aggType) {
case TINYINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
aInt8.setValue((byte) sum);
serde.serialize(aInt8, out);
break;
}
case SMALLINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
aInt16.setValue((short) sum);
serde.serialize(aInt16, out);
break;
}
case INTEGER:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
aInt32.setValue((int) sum);
serde.serialize(aInt32, out);
break;
}
case BIGINT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
aInt64.setValue((long) sum);
serde.serialize(aInt64, out);
break;
}
case FLOAT:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
aFloat.setValue((float) sum);
serde.serialize(aFloat, out);
break;
}
case DOUBLE:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
aDouble.setValue(sum);
serde.serialize(aDouble, out);
break;
}
case NULL:
{
serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
serde.serialize(ANull.NULL, out);
break;
}
case SYSTEM_NULL:
{
finishSystemNull(out);
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.SUM, aggType.serialize());
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class AbstractAvgAggregateFunction method processPartialResults.
protected void processPartialResults(IFrameTupleReference tuple) throws HyracksDataException {
if (skipStep()) {
return;
}
eval.evaluate(tuple, inputVal);
byte[] serBytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[offset]);
switch(typeTag) {
case NULL:
{
processNull();
break;
}
case SYSTEM_NULL:
{
// Ignore and return.
break;
}
case OBJECT:
{
// Expected.
aggType = ATypeTag.DOUBLE;
int nullBitmapSize = 0;
int offset1 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, SUM_FIELD_ID, nullBitmapSize, false);
sum += ADoubleSerializerDeserializer.getDouble(serBytes, offset1);
int offset2 = ARecordSerializerDeserializer.getFieldOffsetById(serBytes, offset, COUNT_FIELD_ID, nullBitmapSize, false);
count += AInt64SerializerDeserializer.getLong(serBytes, offset2);
break;
}
default:
{
throw new UnsupportedItemTypeException("intermediate/global-Avg", serBytes[offset]);
}
}
}
use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.
the class StringJoinDescriptor 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 IScalarEvaluatorFactory sepEvalFactory = args[1];
private final IPointable inputArgList = new VoidPointable();
private final IPointable inputArgSep = new VoidPointable();
private final IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
private final IScalarEvaluator evalSep = sepEvalFactory.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();
evalList.evaluate(tuple, inputArgList);
evalSep.evaluate(tuple, inputArgSep);
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);
}
byte[] sepBytes = inputArgSep.getByteArray();
int sepOffset = inputArgSep.getStartOffset();
if (sepBytes[sepOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, sepBytes[sepOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
int sepLen = UTF8StringUtil.getUTFLength(sepBytes, sepOffset + 1);
int sepMetaLen = UTF8StringUtil.getNumBytesToStoreLength(sepLen);
listAccessor.reset(listBytes, listOffset);
try {
// calculate length first
int utf8Len = 0;
int size = listAccessor.size();
for (int i = 0; i < 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());
}
int currentSize = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
if (i != size - 1 && currentSize != 0) {
utf8Len += sepLen;
}
utf8Len += currentSize;
}
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);
for (int j = 0; j < sepLen; j++) {
out.writeByte(sepBytes[sepOffset + 1 + sepMetaLen + j]);
}
}
} catch (IOException | AsterixException ex) {
throw new HyracksDataException(ex);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations