Search in sources :

Example 21 with ARecord

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

the class ARecordSerializerDeserializerTest method test.

@Test
public void test() {
    // Generates types.
    ARecordType addrRecordType = SerializerDeserializerTestUtils.generateAddressRecordType();
    ARecordType employeeType = SerializerDeserializerTestUtils.generateEmployeeRecordType(addrRecordType);
    //Generates records.
    ARecord[] records = SerializerDeserializerTestUtils.generateRecords(addrRecordType, employeeType);
    ARecordSerializerDeserializer serde = new ARecordSerializerDeserializer(employeeType);
    // Run four test threads to serialize/deserialize records concurrently.
    SerializerDeserializerTestUtils.concurrentSerDeTestRun(serde, records);
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) ARecordType(org.apache.asterix.om.types.ARecordType) Test(org.junit.Test)

Example 22 with ARecord

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

the class SerializerDeserializerTestUtils method generateRecords.

public static ARecord[] generateRecords(ARecordType addrRecordType, ARecordType employeeType) {
    AOrderedListType addrListType = new AOrderedListType(addrRecordType, "address_history");
    ARecord addr11 = new ARecord(addrRecordType, new IAObject[] { new AString("120 San Raman Street"), new AString("Irvine"), new AString("CA"), new AInt16((short) 95051), new AInterval(0, 100, (byte) 0) });
    ARecord addr12 = new ARecord(addrRecordType, new IAObject[] { new AString("210 University Drive"), new AString("Philadelphia"), new AString("PA"), new AInt16((short) 10086), new AInterval(100, 300, (byte) 0) });
    ARecord addr21 = new ARecord(addrRecordType, new IAObject[] { new AString("1 College Street"), new AString("Seattle"), new AString("WA"), new AInt16((short) 20012), new AInterval(400, 500, (byte) 0) });
    ARecord addr22 = new ARecord(addrRecordType, new IAObject[] { new AString("20 Lindsay Avenue"), new AString("Columbus"), new AString("OH"), new AInt16((short) 30120), new AInterval(600, 900, (byte) 0) });
    ARecord addr31 = new ARecord(addrRecordType, new IAObject[] { new AString("200 14th Avenue"), new AString("Long Island"), new AString("NY"), new AInt16((short) 95011), new AInterval(12000, 14000, (byte) 0) });
    // With nested open field addr31.
    ARecord addr32 = new ARecord(addrRecordType, new IAObject[] { new AString("51 8th Street"), new AString("Orlando"), new AString("FL"), new AInt16((short) 49045), new AInterval(190000, 200000, (byte) 0) });
    ARecord record1 = new ARecord(employeeType, new IAObject[] { new AInt64(0L), new AString("Tom"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr11, addr12 })) });
    ARecord record2 = new ARecord(employeeType, new IAObject[] { new AInt64(1L), new AString("John"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr21, addr22 })) });
    ARecord record3 = new ARecord(employeeType, new IAObject[] { new AInt64(2L), new AString("Lindsay"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] { addr31, addr32 })) });
    // With nested open field addr41.
    ARecord record4 = new ARecord(employeeType, new IAObject[] { new AInt64(3L), new AString("Joshua"), new AOrderedList(addrListType, Arrays.asList(new IAObject[] {})) });
    ARecord[] records = new ARecord[] { record1, record2, record3, record4 };
    return records;
}
Also used : AInt16(org.apache.asterix.om.base.AInt16) ARecord(org.apache.asterix.om.base.ARecord) AOrderedList(org.apache.asterix.om.base.AOrderedList) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) AInterval(org.apache.asterix.om.base.AInterval) AString(org.apache.asterix.om.base.AString) AInt64(org.apache.asterix.om.base.AInt64)

Example 23 with ARecord

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

the class ARecordSerializerDeserializer method deserialize.

@Override
public ARecord deserialize(DataInput in) throws HyracksDataException {
    try {
        boolean isExpanded = isExpandedRecord(in);
        IAObject[] schemaFields = getValuesForSchemaFields(in);
        if (isExpanded) {
            int numberOfOpenFields = in.readInt();
            String[] fieldNames = new String[numberOfOpenFields];
            IAType[] fieldTypes = new IAType[numberOfOpenFields];
            IAObject[] openFields = new IAObject[numberOfOpenFields];
            for (int i = 0; i < numberOfOpenFields; i++) {
                in.readInt();
                in.readInt();
            }
            for (int i = 0; i < numberOfOpenFields; i++) {
                fieldNames[i] = AStringSerializerDeserializer.INSTANCE.deserialize(in).getStringValue();
                openFields[i] = AObjectSerializerDeserializer.INSTANCE.deserialize(in);
                fieldTypes[i] = openFields[i].getType();
            }
            ARecordType openPartRecType = new ARecordType(null, fieldNames, fieldTypes, true);
            if (numberOfSchemaFields > 0) {
                ARecordType mergedRecordType = mergeRecordTypes(this.recordType, openPartRecType);
                IAObject[] mergedFields = mergeFields(schemaFields, openFields);
                return new ARecord(mergedRecordType, mergedFields);
            } else {
                return new ARecord(openPartRecType, openFields);
            }
        } else {
            return new ARecord(this.recordType, schemaFields);
        }
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString) IOException(java.io.IOException) ARecordType(org.apache.asterix.om.types.ARecordType) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IAType(org.apache.asterix.om.types.IAType)

Example 24 with ARecord

use of org.apache.asterix.om.base.ARecord 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

ARecord (org.apache.asterix.om.base.ARecord)24 ByteArrayInputStream (java.io.ByteArrayInputStream)14 DataInput (java.io.DataInput)14 DataInputStream (java.io.DataInputStream)14 AString (org.apache.asterix.om.base.AString)9 IACursor (org.apache.asterix.om.base.IACursor)7 AUnorderedList (org.apache.asterix.om.base.AUnorderedList)6 ARecordType (org.apache.asterix.om.types.ARecordType)6 HashMap (java.util.HashMap)4 AMutableString (org.apache.asterix.om.base.AMutableString)4 AOrderedList (org.apache.asterix.om.base.AOrderedList)4 ArrayList (java.util.ArrayList)3 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)3 IAType (org.apache.asterix.om.types.IAType)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Dataset (org.apache.asterix.metadata.entities.Dataset)2 ABoolean (org.apache.asterix.om.base.ABoolean)2 AInt32 (org.apache.asterix.om.base.AInt32)2 AUnorderedListType (org.apache.asterix.om.types.AUnorderedListType)2