use of org.apache.asterix.runtime.exceptions.IncompatibleTypeException in project asterixdb by apache.
the class AbstractSerializableSumAggregateFunction method step.
@Override
public void step(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
if (skipStep(state, start)) {
return;
}
ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
eval.evaluate(tuple, inputVal);
byte[] bytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull(state, start);
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.SUM, bytes[offset], aggType.serialize());
}
if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
sum += val;
break;
}
case NULL:
{
aggType = typeTag;
break;
}
case SYSTEM_NULL:
{
processSystemNull();
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.SUM, bytes[offset]);
}
state[start + AGG_TYPE_OFFSET] = aggType.serialize();
BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
}
use of org.apache.asterix.runtime.exceptions.IncompatibleTypeException in project asterixdb by apache.
the class AbstractAvgAggregateFunction method processDataValues.
protected void processDataValues(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.AVG, data[offset], aggType.serialize());
} else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
++count;
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;
}
default:
{
throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, data[offset]);
}
}
}
use of org.apache.asterix.runtime.exceptions.IncompatibleTypeException in project asterixdb by apache.
the class AbstractSerializableAvgAggregateFunction method processDataValues.
protected void processDataValues(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
if (skipStep(state, start)) {
return;
}
eval.evaluate(tuple, inputVal);
byte[] bytes = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
ATypeTag aggType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(state[start + AGG_TYPE_OFFSET]);
if (typeTag == ATypeTag.MISSING || typeTag == ATypeTag.NULL) {
processNull(state, start);
return;
} else if (aggType == ATypeTag.SYSTEM_NULL) {
aggType = typeTag;
} else if (typeTag != ATypeTag.SYSTEM_NULL && !ATypeHierarchy.isCompatible(typeTag, aggType)) {
throw new IncompatibleTypeException(BuiltinFunctions.AVG, bytes[offset], aggType.serialize());
} else if (ATypeHierarchy.canPromote(aggType, typeTag)) {
aggType = typeTag;
}
++count;
switch(typeTag) {
case TINYINT:
{
byte val = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
sum += val;
break;
}
case SMALLINT:
{
short val = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
sum += val;
break;
}
case INTEGER:
{
int val = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
sum += val;
break;
}
case BIGINT:
{
long val = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
sum += val;
break;
}
case FLOAT:
{
float val = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
sum += val;
break;
}
case DOUBLE:
{
double val = ADoubleSerializerDeserializer.getDouble(bytes, offset + 1);
sum += val;
break;
}
default:
throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, bytes[offset]);
}
BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
BufferSerDeUtil.writeLong(count, state, start + COUNT_OFFSET);
state[start + AGG_TYPE_OFFSET] = aggType.serialize();
}
Aggregations