Search in sources :

Example 41 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class UUIDDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

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

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

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput output = resultStorage.getDataOutput();

                private final AGeneratedUUID uuid = new AGeneratedUUID();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    uuid.nextUUID();
                    resultStorage.reset();
                    uuidSerDe.serialize(uuid, output);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AGeneratedUUID(org.apache.asterix.om.base.AGeneratedUUID) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 42 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class DateFromUnixTimeInDaysDescriptor 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 ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argPtr = new VoidPointable();

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

                private AMutableDate aDate = new AMutableDate(0);

                // possible returning types
                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ADate> dateSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    aDate.setValue(ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, argPtr.getByteArray(), argPtr.getStartOffset()));
                    dateSerde.serialize(aDate, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AMutableDate(org.apache.asterix.om.base.AMutableDate) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 43 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class RecordFieldsUtil method addIsOpenField.

public void addIsOpenField(boolean isOpen, IARecordBuilder fieldRecordBuilder) throws HyracksDataException, AsterixException {
    ArrayBackedValueStorage fieldAbvs = getTempBuffer();
    ArrayBackedValueStorage valueAbvs = getTempBuffer();
    // Name
    fieldAbvs.reset();
    stringSerde.serialize(isOpenName, fieldAbvs.getDataOutput());
    // Value
    valueAbvs.reset();
    if (isOpen) {
        booleanSerde.serialize(ABoolean.TRUE, valueAbvs.getDataOutput());
    } else {
        booleanSerde.serialize(ABoolean.FALSE, valueAbvs.getDataOutput());
    }
    fieldRecordBuilder.addField(fieldAbvs, valueAbvs);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage)

Example 44 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class IDataParser method writeRecord.

/*
     * The following two static methods are expensive. right now, they are used by RSSFeeds and
     * Twitter feed
     * TODO: Get rid of them
     */
public static void writeRecord(AMutableRecord record, DataOutput dataOutput, IARecordBuilder recordBuilder) throws HyracksDataException {
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    int numFields = record.getType().getFieldNames().length;
    for (int pos = 0; pos < numFields; pos++) {
        fieldValue.reset();
        IAObject obj = record.getValueByPos(pos);
        IDataParser.writeObject(obj, fieldValue.getDataOutput());
        recordBuilder.addField(pos, fieldValue);
    }
    recordBuilder.write(dataOutput, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IAObject(org.apache.asterix.om.base.IAObject)

Example 45 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class FirstElementEvalFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new IAggregateEvaluator() {

        private boolean first = true;

        // Needs to copy the bytes from inputVal to outputVal because the byte space of inputVal could be re-used
        // by consequent tuples.
        private ArrayBackedValueStorage outputVal = new ArrayBackedValueStorage();

        private IPointable inputVal = new VoidPointable();

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

        private final byte[] nullBytes = new byte[] { ATypeTag.SERIALIZED_NULL_TYPE_TAG };

        private final byte[] systemNullBytes = new byte[] { ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG };

        @Override
        public void init() throws HyracksDataException {
            first = true;
        }

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            if (!first) {
                return;
            }
            eval.evaluate(tuple, inputVal);
            byte typeTagByte = inputVal.getByteArray()[inputVal.getStartOffset()];
            if (typeTagByte == ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG) {
                // Ignores SYSTEM_NULLs generated by local-first-element.
                return;
            }
            outputVal.assign(inputVal);
            first = false;
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            if (first) {
                result.set(isLocal ? systemNullBytes : nullBytes, 0, 1);
                return;
            }
            result.set(outputVal);
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)

Aggregations

ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)190 IPointable (org.apache.hyracks.data.std.api.IPointable)144 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)144 DataOutput (java.io.DataOutput)140 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)138 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)131 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)129 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)129 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)110 IOException (java.io.IOException)90 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)78 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)25 ATypeTag (org.apache.asterix.om.types.ATypeTag)23 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)18 RecordBuilder (org.apache.asterix.builders.RecordBuilder)18 AString (org.apache.asterix.om.base.AString)18 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)17