Search in sources :

Example 21 with AOrderedListType

use of org.apache.asterix.om.types.AOrderedListType in project asterixdb by apache.

the class TweetParserTest method openRecordTypeTest.

@Test
public void openRecordTypeTest() throws IOException, URISyntaxException {
    String[] ids = { "720549057849114629", "668950503552864257", "668945640186101761", "263602997047730177", "668948268605403136", "741701526859567104" };
    // contruct type
    IAType geoFieldType = new ARecordType("GeoType", new String[] { "coordinates" }, new IAType[] { new AOrderedListType(AFLOAT, "point") }, true);
    List<IAType> unionTypeList = new ArrayList<>();
    unionTypeList.add(geoFieldType);
    unionTypeList.add(ANULL);
    unionTypeList.add(AMISSING);
    IAType geoUnionType = new AUnionType(unionTypeList, "GeoType?");
    ARecordType tweetRecordType = new ARecordType("TweetType", new String[] { "id", "geo" }, new IAType[] { AINT64, geoUnionType }, true);
    TweetParser parser = new TweetParser(tweetRecordType);
    List<String> lines = Files.readAllLines(Paths.get(getClass().getResource("/test_tweets.txt").toURI()));
    ByteArrayOutputStream is = new ByteArrayOutputStream();
    DataOutput output = new DataOutputStream(is);
    for (int iter1 = 0; iter1 < lines.size(); iter1++) {
        GenericRecord<String> record = new GenericRecord<>();
        record.set(lines.get(iter1));
        try {
            parser.parse(record, output);
        } catch (HyracksDataException e) {
            e.printStackTrace();
            Assert.fail("Unexpected failure in parser.");
        }
        Assert.assertTrue((PA.getValue(parser, "aInt64")).toString().equals(ids[iter1]));
    }
}
Also used : DataOutput(java.io.DataOutput) AUnionType(org.apache.asterix.om.types.AUnionType) DataOutputStream(java.io.DataOutputStream) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) TweetParser(org.apache.asterix.external.parser.TweetParser) GenericRecord(org.apache.asterix.external.input.record.GenericRecord) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test)

Example 22 with AOrderedListType

use of org.apache.asterix.om.types.AOrderedListType in project asterixdb by apache.

the class EditDistanceCheckEvaluator method writeResult.

@Override
protected void writeResult(int ed) throws IOException {
    listBuilder.reset(new AOrderedListType(BuiltinType.ANY, "list"));
    boolean matches = (ed < 0) ? false : true;
    listItemVal.reset();
    booleanSerde.serialize(matches ? ABoolean.TRUE : ABoolean.FALSE, listItemVal.getDataOutput());
    listBuilder.addItem(listItemVal);
    listItemVal.reset();
    aInt64.setValue((matches) ? ed : Integer.MAX_VALUE);
    int64Serde.serialize(aInt64, listItemVal.getDataOutput());
    listBuilder.addItem(listItemVal);
    listBuilder.write(out, true);
}
Also used : AOrderedListType(org.apache.asterix.om.types.AOrderedListType)

Example 23 with AOrderedListType

use of org.apache.asterix.om.types.AOrderedListType in project asterixdb by apache.

the class AOrderedListSerializerDeserializerTest method test.

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

Example 24 with AOrderedListType

use of org.apache.asterix.om.types.AOrderedListType 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 25 with AOrderedListType

use of org.apache.asterix.om.types.AOrderedListType in project asterixdb by apache.

the class AOrderedListSerializerDeserializer method deserialize.

@Override
public AOrderedList deserialize(DataInput in) throws HyracksDataException {
    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<IAObject> items = new ArrayList<IAObject>();
        // list size
        in.readInt();
        int numberOfitems;
        numberOfitems = in.readInt();
        if (numberOfitems > 0) {
            if (!NonTaggedFormatUtil.isFixedSizedCollection(currentItemType)) {
                for (int i = 0; i < numberOfitems; i++) in.readInt();
            }
            for (int i = 0; i < numberOfitems; i++) {
                IAObject v = (IAObject) currentDeserializer.deserialize(in);
                items.add(v);
            }
        }
        AOrderedListType type = new AOrderedListType(currentItemType, "orderedlist");
        return new AOrderedList(type, items);
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : AOrderedList(org.apache.asterix.om.base.AOrderedList) ATypeTag(org.apache.asterix.om.types.ATypeTag) IAObject(org.apache.asterix.om.base.IAObject) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) ArrayList(java.util.ArrayList) 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)

Aggregations

AOrderedListType (org.apache.asterix.om.types.AOrderedListType)26 IAType (org.apache.asterix.om.types.IAType)16 ARecordType (org.apache.asterix.om.types.ARecordType)13 ArrayList (java.util.ArrayList)9 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)8 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)7 DataOutput (java.io.DataOutput)6 AString (org.apache.asterix.om.base.AString)6 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)6 AOrderedList (org.apache.asterix.om.base.AOrderedList)5 AUnionType (org.apache.asterix.om.types.AUnionType)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ATypeTag (org.apache.asterix.om.types.ATypeTag)4 AUnorderedListType (org.apache.asterix.om.types.AUnorderedListType)4 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)4 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)4 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4 IPointable (org.apache.hyracks.data.std.api.IPointable)4