Search in sources :

Example 1 with ArrayBackedValueStorage

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

the class InternalDatasetDetails method writeDatasetDetailsRecordType.

@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
    IARecordBuilder internalRecordBuilder = new RecordBuilder();
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    OrderedListBuilder primaryKeyListBuilder = new OrderedListBuilder();
    AOrderedListType stringList = new AOrderedListType(BuiltinType.ASTRING, null);
    AOrderedListType int8List = new AOrderedListType(BuiltinType.AINT8, null);
    AOrderedListType heterogeneousList = new AOrderedListType(BuiltinType.ANY, null);
    internalRecordBuilder.reset(MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
    @SuppressWarnings("unchecked") ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
    @SuppressWarnings("unchecked") ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    @SuppressWarnings("unchecked") ISerializerDeserializer<AInt8> int8Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
    // write field 0
    fieldValue.reset();
    aString.setValue(getFileStructure().toString());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_FILESTRUCTURE_FIELD_INDEX, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(getPartitioningStrategy().toString());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONSTRATEGY_FIELD_INDEX, fieldValue);
    // write field 2
    primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX]);
    for (List<String> field : partitioningKeys) {
        listBuilder.reset(stringList);
        for (String subField : field) {
            itemValue.reset();
            aString.setValue(subField);
            stringSerde.serialize(aString, itemValue.getDataOutput());
            listBuilder.addItem(itemValue);
        }
        itemValue.reset();
        listBuilder.write(itemValue.getDataOutput(), true);
        primaryKeyListBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
    internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PARTITIONKEY_FIELD_INDEX, fieldValue);
    // write field 3
    primaryKeyListBuilder.reset((AOrderedListType) MetadataRecordTypes.INTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX]);
    for (List<String> field : primaryKeys) {
        listBuilder.reset(stringList);
        for (String subField : field) {
            itemValue.reset();
            aString.setValue(subField);
            stringSerde.serialize(aString, itemValue.getDataOutput());
            listBuilder.addItem(itemValue);
        }
        itemValue.reset();
        listBuilder.write(itemValue.getDataOutput(), true);
        primaryKeyListBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    primaryKeyListBuilder.write(fieldValue.getDataOutput(), true);
    internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX, fieldValue);
    // write field 4
    fieldValue.reset();
    ABoolean b = isAutogenerated() ? ABoolean.TRUE : ABoolean.FALSE;
    booleanSerde.serialize(b, fieldValue.getDataOutput());
    internalRecordBuilder.addField(MetadataRecordTypes.INTERNAL_DETAILS_ARECORD_AUTOGENERATED_FIELD_INDEX, fieldValue);
    // write filter fields if any
    List<String> filterField = getFilterField();
    if (filterField != null) {
        listBuilder.reset(heterogeneousList);
        ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
        nameValue.reset();
        aString.setValue(FILTER_FIELD_NAME);
        stringSerde.serialize(aString, nameValue.getDataOutput());
        for (String field : filterField) {
            itemValue.reset();
            aString.setValue(field);
            stringSerde.serialize(aString, itemValue.getDataOutput());
            listBuilder.addItem(itemValue);
        }
        fieldValue.reset();
        listBuilder.write(fieldValue.getDataOutput(), true);
        internalRecordBuilder.addField(nameValue, fieldValue);
    }
    // write key source indicators if any
    List<Integer> keySourceIndicator = getKeySourceIndicator();
    boolean needSerialization = false;
    if (keySourceIndicator != null) {
        for (int source : keySourceIndicator) {
            if (source != 0) {
                needSerialization = true;
                break;
            }
        }
    }
    if (needSerialization) {
        listBuilder.reset(int8List);
        ArrayBackedValueStorage nameValue = new ArrayBackedValueStorage();
        nameValue.reset();
        aString.setValue(KEY_FILD_SOURCE_INDICATOR_FIELD_NAME);
        stringSerde.serialize(aString, nameValue.getDataOutput());
        for (int source : keySourceIndicator) {
            itemValue.reset();
            aInt8.setValue((byte) source);
            int8Serde.serialize(aInt8, itemValue.getDataOutput());
            listBuilder.addItem(itemValue);
        }
        fieldValue.reset();
        listBuilder.write(fieldValue.getDataOutput(), true);
        internalRecordBuilder.addField(nameValue, fieldValue);
    }
    internalRecordBuilder.write(out, true);
}
Also used : OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) AMutableInt8(org.apache.asterix.om.base.AMutableInt8) ABoolean(org.apache.asterix.om.base.ABoolean) RecordBuilder(org.apache.asterix.builders.RecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AInt8(org.apache.asterix.om.base.AInt8) AString(org.apache.asterix.om.base.AString)

Example 2 with ArrayBackedValueStorage

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

the class DatasetTupleTranslator method writeDatasetHintRecord.

@SuppressWarnings("unchecked")
protected void writeDatasetHintRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.DATASET_HINTS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 3 with ArrayBackedValueStorage

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

the class InternalDatasetDetails method writePropertyTypeRecord.

protected void writePropertyTypeRecord(String name, String value, DataOutput out, ARecordType recordType) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(recordType);
    AMutableString aString = new AMutableString("");
    @SuppressWarnings("unchecked") ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 4 with ArrayBackedValueStorage

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

the class TidRunningAggregateDescriptor method createRunningAggregateEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IRunningAggregateEvaluator() {

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final ISerializerDeserializer<AInt64> serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private final AMutableInt64 m = new AMutableInt64(0);

                private int cnt;

                @Override
                public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    m.setValue(cnt);
                    serde.serialize(m, resultStorage.getDataOutput());
                    result.set(resultStorage);
                    ++cnt;
                }

                @Override
                public void init() throws HyracksDataException {
                    cnt = 1;
                }
            };
        }
    };
}
Also used : IRunningAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 5 with ArrayBackedValueStorage

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

the class RangeDescriptor method createUnnestingEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

        @Override
        public IUnnestingEvaluator createUnnestingEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IUnnestingEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                @SuppressWarnings("rawtypes")
                private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private IPointable inputVal = new VoidPointable();

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

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

                private AMutableInt64 aInt64 = new AMutableInt64(0);

                private long current;

                private long max;

                @Override
                public void init(IFrameTupleReference tuple) throws HyracksDataException {
                    eval0.evaluate(tuple, inputVal);
                    current = ATypeHierarchy.getLongValue(getIdentifier().getName(), 0, inputVal.getByteArray(), inputVal.getStartOffset());
                    eval1.evaluate(tuple, inputVal);
                    max = ATypeHierarchy.getLongValue(getIdentifier().getName(), 1, inputVal.getByteArray(), inputVal.getStartOffset());
                }

                @SuppressWarnings("unchecked")
                @Override
                public boolean step(IPointable result) throws HyracksDataException {
                    if (current > max) {
                        return false;
                    }
                    aInt64.setValue(current);
                    resultStorage.reset();
                    serde.serialize(aInt64, resultStorage.getDataOutput());
                    result.set(resultStorage);
                    current++;
                    return true;
                }
            };
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IUnnestingEvaluator(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluator) 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) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) IUnnestingEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluatorFactory) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

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