Search in sources :

Example 11 with IARecordBuilder

use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.

the class FeedPolicyTupleTranslator method writePropertyTypeRecord.

public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.POLICY_PARAMS_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 12 with IARecordBuilder

use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.

the class FeedTupleTranslator method writePropertyTypeRecord.

@SuppressWarnings("unchecked")
public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_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 13 with IARecordBuilder

use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.

the class DatatypeTupleTranslator method writeDerivedTypeRecord.

private void writeDerivedTypeRecord(Datatype type, AbstractComplexType derivedDatatype, DataOutput out) throws HyracksDataException {
    DerivedTypeTag tag = null;
    IARecordBuilder derivedRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    switch(derivedDatatype.getTypeTag()) {
        case ARRAY:
            tag = DerivedTypeTag.ORDEREDLIST;
            break;
        case MULTISET:
            tag = DerivedTypeTag.UNORDEREDLIST;
            break;
        case OBJECT:
            tag = DerivedTypeTag.RECORD;
            break;
        default:
            throw new UnsupportedOperationException("No metadata record Type for " + derivedDatatype.getDisplayName());
    }
    derivedRecordBuilder.reset(MetadataRecordTypes.DERIVEDTYPE_RECORDTYPE);
    // write field 0
    fieldValue.reset();
    aString.setValue(tag.toString());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_TAG_FIELD_INDEX, fieldValue);
    // write field 1
    fieldValue.reset();
    booleanSerde.serialize(type.getIsAnonymous() ? ABoolean.TRUE : ABoolean.FALSE, fieldValue.getDataOutput());
    derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_ISANONYMOUS_FIELD_INDEX, fieldValue);
    switch(tag) {
        case RECORD:
            fieldValue.reset();
            writeRecordType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_RECORD_FIELD_INDEX, fieldValue);
            break;
        case UNORDEREDLIST:
            fieldValue.reset();
            writeCollectionType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_UNORDEREDLIST_FIELD_INDEX, fieldValue);
            break;
        case ORDEREDLIST:
            fieldValue.reset();
            writeCollectionType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_ORDEREDLIST_FIELD_INDEX, fieldValue);
            break;
    }
    derivedRecordBuilder.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)

Example 14 with IARecordBuilder

use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.

the class RecordFieldsUtil method processListValue.

public void processListValue(IValueReference listArg, IAType fieldType, DataOutput out, int level) throws AsterixException, IOException {
    ArrayBackedValueStorage itemValue = getTempBuffer();
    IARecordBuilder listRecordBuilder = getRecordBuilder();
    AListPointable list = getListPointable();
    list.set(listArg);
    OrderedListBuilder innerListBuilder = getOrderedListBuilder();
    innerListBuilder.reset(listType);
    listRecordBuilder.reset(null);
    AbstractCollectionType act = (AbstractCollectionType) fieldType;
    int itemCount = list.getItemCount();
    for (int l = 0; l < itemCount; l++) {
        itemValue.reset();
        listRecordBuilder.init();
        byte tagId = list.getItemTag(act, l);
        addFieldType(tagId, listRecordBuilder);
        if (tagId == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
            ArrayBackedValueStorage tmpAbvs = getTempBuffer();
            list.getItemValue(act, l, tmpAbvs.getDataOutput());
            addNestedField(tmpAbvs, act.getItemType(), listRecordBuilder, level + 1);
        }
        listRecordBuilder.write(itemValue.getDataOutput(), true);
        innerListBuilder.addItem(itemValue);
    }
    innerListBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AListPointable(org.apache.asterix.om.pointables.nonvisitor.AListPointable) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType)

Example 15 with IARecordBuilder

use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.

the class RecordFieldsUtil method processRecord.

public void processRecord(ARecordPointable recordAccessor, ARecordType recType, DataOutput out, int level) throws IOException, AsterixException {
    if (level == 0) {
        // Resets pools for recycling objects before processing a top-level record.
        resetPools();
    }
    ArrayBackedValueStorage itemValue = getTempBuffer();
    ArrayBackedValueStorage fieldName = getTempBuffer();
    OrderedListBuilder orderedListBuilder = getOrderedListBuilder();
    orderedListBuilder.reset(listType);
    IARecordBuilder fieldRecordBuilder = getRecordBuilder();
    fieldRecordBuilder.reset(null);
    int schemeFieldCount = recordAccessor.getSchemeFieldCount(recType);
    for (int i = 0; i < schemeFieldCount; ++i) {
        itemValue.reset();
        fieldRecordBuilder.init();
        // write name
        fieldName.reset();
        recordAccessor.getClosedFieldName(recType, i, fieldName.getDataOutput());
        addNameField(fieldName, fieldRecordBuilder);
        // write type
        byte tag = recordAccessor.getClosedFieldTag(recType, i);
        addFieldType(tag, fieldRecordBuilder);
        // write open
        addIsOpenField(false, fieldRecordBuilder);
        // write nested or list types
        if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG || tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
            if (!recordAccessor.isClosedFieldNull(recType, i)) {
                IAType fieldType = recordAccessor.getClosedFieldType(recType, i);
                ArrayBackedValueStorage tmpValue = getTempBuffer();
                tmpValue.reset();
                recordAccessor.getClosedFieldValue(recType, i, tmpValue.getDataOutput());
                if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                    addNestedField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
                } else if (tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
                    addListField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
                }
            }
        }
        // write record
        fieldRecordBuilder.write(itemValue.getDataOutput(), true);
        // add item to the list of fields
        orderedListBuilder.addItem(itemValue);
    }
    for (int i = recordAccessor.getOpenFieldCount(recType) - 1; i >= 0; --i) {
        itemValue.reset();
        fieldRecordBuilder.init();
        // write name
        fieldName.reset();
        recordAccessor.getOpenFieldName(recType, i, fieldName.getDataOutput());
        addNameField(fieldName, fieldRecordBuilder);
        // write type
        byte tag = recordAccessor.getOpenFieldTag(recType, i);
        addFieldType(tag, fieldRecordBuilder);
        // write open
        addIsOpenField(true, fieldRecordBuilder);
        // write nested or list types
        if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG || tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
            IAType fieldType = null;
            ArrayBackedValueStorage tmpValue = getTempBuffer();
            tmpValue.reset();
            recordAccessor.getOpenFieldValue(recType, i, tmpValue.getDataOutput());
            if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                addNestedField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
            } else if (tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
                addListField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
            }
        }
        // write record
        fieldRecordBuilder.write(itemValue.getDataOutput(), true);
        // add item to the list of fields
        orderedListBuilder.addItem(itemValue);
    }
    orderedListBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IAType(org.apache.asterix.om.types.IAType)

Aggregations

IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)15 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)15 RecordBuilder (org.apache.asterix.builders.RecordBuilder)10 AMutableString (org.apache.asterix.om.base.AMutableString)7 AString (org.apache.asterix.om.base.AString)7 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)5 IAType (org.apache.asterix.om.types.IAType)5 ABoolean (org.apache.asterix.om.base.ABoolean)3 BitSet (java.util.BitSet)2 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 DataOutput (java.io.DataOutput)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)1 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)1 CaseInsensitiveString (org.apache.asterix.external.classad.CaseInsensitiveString)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 ADateTime (org.apache.asterix.om.base.ADateTime)1 AInt32 (org.apache.asterix.om.base.AInt32)1