Search in sources :

Example 6 with UnsupportedItemTypeException

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

Example 7 with UnsupportedItemTypeException

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);
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 8 with UnsupportedItemTypeException

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);
    }
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ATypeTag(org.apache.asterix.om.types.ATypeTag) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 9 with UnsupportedItemTypeException

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

Example 10 with UnsupportedItemTypeException

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);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ListAccessor(org.apache.asterix.runtime.evaluators.common.ListAccessor) UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Aggregations

UnsupportedItemTypeException (org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException)15 ATypeTag (org.apache.asterix.om.types.ATypeTag)14 IOException (java.io.IOException)8 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)7 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 IPointable (org.apache.hyracks.data.std.api.IPointable)7 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)7 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)6 IncompatibleTypeException (org.apache.asterix.runtime.exceptions.IncompatibleTypeException)5 DataOutput (java.io.DataOutput)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 ListAccessor (org.apache.asterix.runtime.evaluators.common.ListAccessor)4 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)4 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)4 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)4 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)4 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)2 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)2 AMutableBinary (org.apache.asterix.om.base.AMutableBinary)1