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]));
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations