Search in sources :

Example 11 with IncompatibleTypeException

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);
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ATypeTag(org.apache.asterix.om.types.ATypeTag) IncompatibleTypeException(org.apache.asterix.runtime.exceptions.IncompatibleTypeException)

Example 12 with IncompatibleTypeException

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]);
            }
    }
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ATypeTag(org.apache.asterix.om.types.ATypeTag) IncompatibleTypeException(org.apache.asterix.runtime.exceptions.IncompatibleTypeException)

Example 13 with IncompatibleTypeException

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();
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ATypeTag(org.apache.asterix.om.types.ATypeTag) IncompatibleTypeException(org.apache.asterix.runtime.exceptions.IncompatibleTypeException)

Aggregations

IncompatibleTypeException (org.apache.asterix.runtime.exceptions.IncompatibleTypeException)13 ATypeTag (org.apache.asterix.om.types.ATypeTag)9 DataOutput (java.io.DataOutput)6 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)6 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)6 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)6 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)6 IPointable (org.apache.hyracks.data.std.api.IPointable)6 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)6 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)6 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)5 UnsupportedItemTypeException (org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException)5 AMutableInterval (org.apache.asterix.om.base.AMutableInterval)4 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)4 IOException (java.io.IOException)3 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)3 OverflowException (org.apache.asterix.runtime.exceptions.OverflowException)3 UnderflowException (org.apache.asterix.runtime.exceptions.UnderflowException)3 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)2 AIntervalPointable (org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable)2