Search in sources :

Example 11 with UTF8StringPointable

use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.

the class AIntervalStartFromTimeConstructorDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argPtr0 = new VoidPointable();

                private IPointable argPtr1 = new VoidPointable();

                private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);

                private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);

                private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);

                private AMutableDuration aDuration = new AMutableDuration(0, 0L);

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInterval> intervalSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINTERVAL);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, argPtr0);
                    eval1.evaluate(tuple, argPtr1);
                    byte[] bytes0 = argPtr0.getByteArray();
                    int offset0 = argPtr0.getStartOffset();
                    int len0 = argPtr0.getLength();
                    byte[] bytes1 = argPtr1.getByteArray();
                    int offset1 = argPtr1.getStartOffset();
                    int len1 = argPtr1.getLength();
                    try {
                        long intervalStart = 0, intervalEnd = 0;
                        if (bytes0[offset0] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
                            intervalStart = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
                        } else if (bytes0[offset0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(bytes0, offset0 + 1, len0 - 1);
                            int stringLength = utf8Ptr.getUTF8Length();
                            intervalStart = ATimeParserFactory.parseTimePart(bytes0, utf8Ptr.getCharStartOffset(), stringLength);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        if (intervalStart < 0) {
                            intervalStart += GregorianCalendarSystem.CHRONON_OF_DAY;
                        }
                        if (bytes1[offset1] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                            if (ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1) != 0) {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                            }
                            intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0, ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1), false);
                        } else if (bytes1[offset1] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
                            intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0, ADayTimeDurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1), false);
                        } else if (bytes1[offset1] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            // duration
                            utf8Ptr.set(bytes1, offset1 + 1, len1 - 1);
                            int stringLength = utf8Ptr.getUTF8Length();
                            ADurationParserFactory.parseDuration(bytes1, utf8Ptr.getCharStartOffset(), stringLength, aDuration, ADurationParseOption.All);
                            if (aDuration.getMonths() != 0) {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                            }
                            intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0, aDuration.getMilliseconds(), false);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        if (intervalEnd > GregorianCalendarSystem.CHRONON_OF_DAY) {
                            intervalEnd = intervalEnd % (int) (GregorianCalendarSystem.CHRONON_OF_DAY);
                        }
                        if (intervalEnd < intervalStart) {
                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                        }
                        aInterval.setValue(intervalStart, intervalEnd, ATypeTag.SERIALIZED_TIME_TYPE_TAG);
                        intervalSerde.serialize(aInterval, out);
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableDuration(org.apache.asterix.om.base.AMutableDuration) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) 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) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInterval(org.apache.asterix.om.base.AMutableInterval)

Example 12 with UTF8StringPointable

use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.

the class APolygonConstructorDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

                private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int offset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, offset + 1, len - 1);
                            String s = utf8Ptr.toString();
                            String[] points = WS.split(s.trim());
                            if (points.length <= 2) {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                            }
                            out.writeByte(ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                            out.writeShort(points.length);
                            for (int i = 0; i < points.length; i++) {
                                final String[] point = COMMA.split(points[i]);
                                APointSerializerDeserializer.serialize(Double.parseDouble(point[0]), Double.parseDouble(point[1]), out);
                            }
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) 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) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Example 13 with UTF8StringPointable

use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.

the class ARectangleConstructorDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

                private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

                private AMutableRectangle aRectangle = new AMutableRectangle(null, null);

                private AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ARectangle> rectangle2DSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ARECTANGLE);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int offset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, offset + 1, len - 1);
                            String s = utf8Ptr.toString();
                            int commaIndex = s.indexOf(',');
                            int spaceIndex = s.indexOf(' ', commaIndex + 1);
                            aPoint[0].setValue(Double.parseDouble(s.substring(0, commaIndex)), Double.parseDouble(s.substring(commaIndex + 1, spaceIndex)));
                            commaIndex = s.indexOf(',', spaceIndex + 1);
                            aPoint[1].setValue(Double.parseDouble(s.substring(spaceIndex + 1, commaIndex)), Double.parseDouble(s.substring(commaIndex + 1, s.length())));
                            if (aPoint[0].getX() > aPoint[1].getX() && aPoint[0].getY() > aPoint[1].getY()) {
                                aRectangle.setValue(aPoint[1], aPoint[0]);
                            } else if (aPoint[0].getX() < aPoint[1].getX() && aPoint[0].getY() < aPoint[1].getY()) {
                                aRectangle.setValue(aPoint[0], aPoint[1]);
                            } else {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
                            }
                            rectangle2DSerde.serialize(aRectangle, out);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableRectangle(org.apache.asterix.om.base.AMutableRectangle) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutablePoint(org.apache.asterix.om.base.AMutablePoint)

Example 14 with UTF8StringPointable

use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.

the class AUUIDFromStringConstructorDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

                private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

                private AMutableUUID uuid = new AMutableUUID();

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AUUID> uuidSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AUUID);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int start = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[start] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, start + 1, len - 1);
                            // first byte: tag, next x bytes: length
                            int offset = utf8Ptr.getCharStartOffset();
                            uuid.parseUUIDHexBytes(serString, offset);
                            uuidSerde.serialize(uuid, out);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[start], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_UUID_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) 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) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) AMutableUUID(org.apache.asterix.om.base.AMutableUUID) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Example 15 with UTF8StringPointable

use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.

the class AYearMonthDurationConstructorDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

                private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

                private AMutableYearMonthDuration aYearMonthDuration = new AMutableYearMonthDuration(0);

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AYearMonthDuration> yearMonthDurationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AYEARMONTHDURATION);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int offset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, offset + 1, len - 1);
                            int stringLength = utf8Ptr.getUTF8Length();
                            ADurationParserFactory.parseDuration(serString, utf8Ptr.getCharStartOffset(), stringLength, aYearMonthDuration, ADurationParseOption.YEAR_MONTH);
                            yearMonthDurationSerde.serialize(aYearMonthDuration, out);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (Exception e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) AMutableYearMonthDuration(org.apache.asterix.om.base.AMutableYearMonthDuration) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) 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

UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)44 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)40 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)40 IPointable (org.apache.hyracks.data.std.api.IPointable)37 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)37 DataOutput (java.io.DataOutput)35 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)35 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)35 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)35 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)33 IOException (java.io.IOException)31 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)27 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)26 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)13 UTF8StringWriter (org.apache.hyracks.util.string.UTF8StringWriter)5 AMutableDuration (org.apache.asterix.om.base.AMutableDuration)4 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)4 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)4 UTF8StringBuilder (org.apache.hyracks.data.std.util.UTF8StringBuilder)4 AMutableInterval (org.apache.asterix.om.base.AMutableInterval)3