Search in sources :

Example 11 with UnsupportedItemTypeException

use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException 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 UnsupportedItemTypeException

use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException 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 UnsupportedItemTypeException

use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.

the class AbstractSerializableAvgAggregateFunction method processPartialResults.

protected void processPartialResults(IFrameTupleReference tuple, byte[] state, int start, int len) throws HyracksDataException {
    if (skipStep(state, start)) {
        return;
    }
    double sum = BufferSerDeUtil.getDouble(state, start + SUM_OFFSET);
    long count = BufferSerDeUtil.getLong(state, start + COUNT_OFFSET);
    eval.evaluate(tuple, inputVal);
    byte[] serBytes = inputVal.getByteArray();
    int offset = inputVal.getStartOffset();
    ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[offset]);
    switch(typeTag) {
        case NULL:
            {
                processNull(state, start);
                break;
            }
        case SYSTEM_NULL:
            {
                // Ignore and return.
                break;
            }
        case OBJECT:
            {
                // Expected.
                ATypeTag 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);
                BufferSerDeUtil.writeDouble(sum, state, start + SUM_OFFSET);
                BufferSerDeUtil.writeLong(count, state, start + COUNT_OFFSET);
                state[start + AGG_TYPE_OFFSET] = aggType.serialize();
                break;
            }
        default:
            throw new UnsupportedItemTypeException(BuiltinFunctions.AVG, serBytes[offset]);
    }
}
Also used : UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ATypeTag(org.apache.asterix.om.types.ATypeTag)

Example 14 with UnsupportedItemTypeException

use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException 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)

Example 15 with UnsupportedItemTypeException

use of org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException in project asterixdb by apache.

the class PrintBinaryDescriptor 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 StringBuilder stringBuilder = new StringBuilder();

                private final ByteArrayPointable byteArrayPtr = new ByteArrayPointable();

                private final UTF8StringPointable formatPointable = new UTF8StringPointable();

                private final UTF8StringWriter writer = new UTF8StringWriter();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evaluators[0].evaluate(tuple, pointables[0]);
                    evaluators[1].evaluate(tuple, pointables[1]);
                    try {
                        ATypeTag arg0Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
                        ATypeTag arg1Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
                        checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, arg0Tag, arg1Tag);
                        byteArrayPtr.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength());
                        formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1, pointables[1].getLength());
                        int lengthBinary = byteArrayPtr.getContentLength();
                        stringBuilder.setLength(0);
                        if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
                            HexPrinter.printHexString(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
                        } else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
                            Base64Printer.printBase64Binary(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
                        } else {
                            throw new UnsupportedItemTypeException(getIdentifier(), arg1Tag.serialize());
                        }
                        dataOutput.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        writer.writeUTF8(stringBuilder.toString(), dataOutput);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) UnsupportedItemTypeException(org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException) ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable) ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) UTF8StringWriter(org.apache.hyracks.util.string.UTF8StringWriter)

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