Search in sources :

Example 1 with AUnorderedList

use of org.apache.asterix.om.base.AUnorderedList in project asterixdb by apache.

the class AUnorderedListSerializerDeserializerTest method test.

@Test
public void test() {
    // Generates types.
    ARecordType addrRecordType = SerializerDeserializerTestUtils.generateAddressRecordType();
    ARecordType employeeType = SerializerDeserializerTestUtils.generateEmployeeRecordType(addrRecordType);
    AUnorderedListType employeeListType = new AUnorderedListType(employeeType, "employee_list");
    //Generates records.
    ARecord[] records = SerializerDeserializerTestUtils.generateRecords(addrRecordType, employeeType);
    // Generates lists
    AUnorderedList[] lists = new AUnorderedList[4];
    for (int index = 0; index < lists.length; ++index) {
        lists[index] = new AUnorderedList(employeeListType, Arrays.asList(records));
    }
    AUnorderedListSerializerDeserializer serde = new AUnorderedListSerializerDeserializer(employeeListType);
    // Run four test threads to serialize/deserialize lists concurrently.
    SerializerDeserializerTestUtils.concurrentSerDeTestRun(serde, lists);
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) ARecordType(org.apache.asterix.om.types.ARecordType) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) Test(org.junit.Test)

Example 2 with AUnorderedList

use of org.apache.asterix.om.base.AUnorderedList in project asterixdb by apache.

the class FeedTupleTranslator method createFeedFromARecord.

private Feed createFeedFromARecord(ARecord feedRecord) {
    Feed feed;
    String dataverseName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String feedName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_FEED_NAME_FIELD_INDEX)).getStringValue();
    AUnorderedList feedConfig = (AUnorderedList) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_ADAPTOR_CONFIG_INDEX);
    String adapterName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_ADAPTOR_NAME_INDEX)).getStringValue();
    IACursor cursor = feedConfig.getCursor();
    // restore configurations
    String key;
    String value;
    Map<String, String> adaptorConfiguration = new HashMap<>();
    while (cursor.next()) {
        ARecord field = (ARecord) cursor.get();
        key = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_NAME_FIELD_INDEX)).getStringValue();
        value = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_VALUE_FIELD_INDEX)).getStringValue();
        adaptorConfiguration.put(key, value);
    }
    feed = new Feed(dataverseName, feedName, adapterName, adaptorConfiguration);
    return feed;
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) HashMap(java.util.HashMap) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IACursor(org.apache.asterix.om.base.IACursor) AString(org.apache.asterix.om.base.AString) Feed(org.apache.asterix.metadata.entities.Feed)

Example 3 with AUnorderedList

use of org.apache.asterix.om.base.AUnorderedList in project asterixdb by apache.

the class FeedPolicyTupleTranslator method createFeedPolicyFromARecord.

private FeedPolicyEntity createFeedPolicyFromARecord(ARecord feedPolicyRecord) {
    FeedPolicyEntity feedPolicy = null;
    String dataverseName = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String policyName = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_POLICY_NAME_FIELD_INDEX)).getStringValue();
    String description = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_DESCRIPTION_FIELD_INDEX)).getStringValue();
    IACursor cursor = ((AUnorderedList) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_PROPERTIES_FIELD_INDEX)).getCursor();
    Map<String, String> policyParamters = new HashMap<>();
    String key;
    String value;
    while (cursor.next()) {
        ARecord field = (ARecord) cursor.get();
        key = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_NAME_FIELD_INDEX)).getStringValue();
        value = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_VALUE_FIELD_INDEX)).getStringValue();
        policyParamters.put(key, value);
    }
    feedPolicy = new FeedPolicyEntity(dataverseName, policyName, description, policyParamters);
    return feedPolicy;
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) FeedPolicyEntity(org.apache.asterix.metadata.entities.FeedPolicyEntity) HashMap(java.util.HashMap) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IACursor(org.apache.asterix.om.base.IACursor) AString(org.apache.asterix.om.base.AString)

Example 4 with AUnorderedList

use of org.apache.asterix.om.base.AUnorderedList in project asterixdb by apache.

the class AUnorderedListSerializerDeserializer method deserialize.

@Override
public AUnorderedList deserialize(DataInput in) throws HyracksDataException {
    // TODO: schemaless unordered list deserializer
    try {
        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(in.readByte());
        IAType currentItemType = itemType;
        @SuppressWarnings("rawtypes") ISerializerDeserializer currentDeserializer = deserializer;
        if (itemType.getTypeTag() == ATypeTag.ANY && typeTag != ATypeTag.ANY) {
            currentItemType = TypeTagUtil.getBuiltinTypeByTag(typeTag);
            currentDeserializer = SerializerDeserializerProvider.INSTANCE.getNonTaggedSerializerDeserializer(currentItemType);
        }
        // list size
        in.readInt();
        int numberOfitems;
        numberOfitems = in.readInt();
        ArrayList<IAObject> items = new ArrayList<IAObject>();
        if (numberOfitems > 0) {
            if (!NonTaggedFormatUtil.isFixedSizedCollection(currentItemType)) {
                for (int i = 0; i < numberOfitems; i++) in.readInt();
            }
            for (int i = 0; i < numberOfitems; i++) {
                items.add((IAObject) currentDeserializer.deserialize(in));
            }
        }
        AUnorderedListType type = new AUnorderedListType(currentItemType, "unorderedlist");
        return new AUnorderedList(type, items);
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) IAObject(org.apache.asterix.om.base.IAObject) ArrayList(java.util.ArrayList) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IAType(org.apache.asterix.om.types.IAType)

Example 5 with AUnorderedList

use of org.apache.asterix.om.base.AUnorderedList in project asterixdb by apache.

the class NodeGroupTupleTranslator method getMetadataEntityFromTuple.

@Override
public NodeGroup getMetadataEntityFromTuple(ITupleReference frameTuple) throws HyracksDataException {
    byte[] serRecord = frameTuple.getFieldData(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
    int recordStartOffset = frameTuple.getFieldStart(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
    int recordLength = frameTuple.getFieldLength(NODEGROUP_PAYLOAD_TUPLE_FIELD_INDEX);
    ByteArrayInputStream stream = new ByteArrayInputStream(serRecord, recordStartOffset, recordLength);
    DataInput in = new DataInputStream(stream);
    ARecord nodeGroupRecord = recordSerDes.deserialize(in);
    String gpName = ((AString) nodeGroupRecord.getValueByPos(MetadataRecordTypes.NODEGROUP_ARECORD_GROUPNAME_FIELD_INDEX)).getStringValue();
    IACursor cursor = ((AUnorderedList) nodeGroupRecord.getValueByPos(MetadataRecordTypes.NODEGROUP_ARECORD_NODENAMES_FIELD_INDEX)).getCursor();
    List<String> nodeNames = new ArrayList<>();
    while (cursor.next()) {
        nodeNames.add(((AString) cursor.get()).getStringValue());
    }
    return new NodeGroup(gpName, nodeNames);
}
Also used : ArrayList(java.util.ArrayList) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor) DataInputStream(java.io.DataInputStream) DataInput(java.io.DataInput) ARecord(org.apache.asterix.om.base.ARecord) ByteArrayInputStream(java.io.ByteArrayInputStream) AString(org.apache.asterix.om.base.AString) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Aggregations

AUnorderedList (org.apache.asterix.om.base.AUnorderedList)6 ARecord (org.apache.asterix.om.base.ARecord)5 AString (org.apache.asterix.om.base.AString)4 IACursor (org.apache.asterix.om.base.IACursor)4 HashMap (java.util.HashMap)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 ArrayList (java.util.ArrayList)2 AUnorderedListType (org.apache.asterix.om.types.AUnorderedListType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 Feed (org.apache.asterix.metadata.entities.Feed)1 FeedPolicyEntity (org.apache.asterix.metadata.entities.FeedPolicyEntity)1 NodeGroup (org.apache.asterix.metadata.entities.NodeGroup)1 IAObject (org.apache.asterix.om.base.IAObject)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 ATypeTag (org.apache.asterix.om.types.ATypeTag)1 IAType (org.apache.asterix.om.types.IAType)1