Search in sources :

Example 1 with TweetParser

use of org.apache.asterix.external.parser.TweetParser in project asterixdb by apache.

the class TweetParserTest method closedRecordTypeTest.

@Test
public void closedRecordTypeTest() throws IOException, URISyntaxException {
    // contruct type
    IAType geoFieldType = new ARecordType("GeoType", new String[] { "coordinates" }, new IAType[] { new AOrderedListType(AFLOAT, "point") }, true);
    ARecordType tweetRecordType = new ARecordType("TweetType", new String[] { "id", "geo" }, new IAType[] { AINT64, geoFieldType }, 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);
    int regularCount = 0;
    for (int iter1 = 0; iter1 < lines.size(); iter1++) {
        GenericRecord<String> record = new GenericRecord<>();
        record.set(lines.get(iter1));
        try {
            parser.parse(record, output);
            regularCount++;
        } catch (HyracksDataException e) {
            Assert.assertTrue(e.toString().contains("Non-null") && (iter1 == 0 || iter1 == 1));
        }
    }
    Assert.assertTrue(regularCount == 4);
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) 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 2 with TweetParser

use of org.apache.asterix.external.parser.TweetParser 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)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutput (java.io.DataOutput)2 DataOutputStream (java.io.DataOutputStream)2 GenericRecord (org.apache.asterix.external.input.record.GenericRecord)2 TweetParser (org.apache.asterix.external.parser.TweetParser)2 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)2 ARecordType (org.apache.asterix.om.types.ARecordType)2 IAType (org.apache.asterix.om.types.IAType)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 AUnionType (org.apache.asterix.om.types.AUnionType)1