use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class AggregatorTest method testMaxDOBMinNameMaxNameAggregation.
// TEST 10: Find max in DOB, min in Name (String) and max in Name (String) column
@Test
public void testMaxDOBMinNameMaxNameAggregation() throws Exception {
Attribute attribute1 = TestConstants.DATE_OF_BIRTH_ATTR;
String attributeName1 = attribute1.getName();
AggregationType aggType1 = AggregationType.MAX;
Attribute attribute2 = TestConstants.FIRST_NAME_ATTR;
String attributeName2 = attribute2.getName();
AggregationType aggType2 = AggregationType.MIN;
Attribute attribute3 = TestConstants.FIRST_NAME_ATTR;
String attributeName3 = attribute2.getName();
AggregationType aggType3 = AggregationType.MAX;
String resultAttributeName1 = AggregatorTestConstants.MAX_DATE_RESULT_ATTR_NAME;
String resultAttributeName2 = AggregatorTestConstants.MIN_FIRST_NAME_RESULT_ATTR_NAME;
String resultAttributeName3 = AggregatorTestConstants.MAX_FIRST_NAME_RESULT_ATTR_NAME;
AggregationAttributeAndResult aggEntity1 = new AggregationAttributeAndResult(attributeName1, aggType1, resultAttributeName1);
AggregationAttributeAndResult aggEntity2 = new AggregationAttributeAndResult(attributeName2, aggType2, resultAttributeName2);
AggregationAttributeAndResult aggEntity3 = new AggregationAttributeAndResult(attributeName3, aggType3, resultAttributeName3);
List<AggregationAttributeAndResult> aggEntitiesList = new ArrayList<>();
aggEntitiesList.add(aggEntity1);
aggEntitiesList.add(aggEntity2);
aggEntitiesList.add(aggEntity3);
IField[] row1 = { new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1974")), new StringField("Mary brown"), new StringField("tom hanks") };
Schema schema = new Schema(new Attribute(resultAttributeName1, AttributeType.DATE), new Attribute(resultAttributeName2, AttributeType.STRING), new Attribute(resultAttributeName3, AttributeType.STRING));
List<Tuple> expectedResults = new ArrayList<>();
expectedResults.add(new Tuple(schema, row1));
List<Tuple> returnedResults = getQueryResults(aggEntitiesList);
Assert.assertEquals(1, returnedResults.size());
Assert.assertTrue(TestUtils.equals(expectedResults, returnedResults));
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class AsterixSource method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED) {
throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
}
if (cursor < resultJsonArray.length()) {
Tuple tuple = new Tuple(this.outputSchema, IDField.newRandomID(), new StringField(resultJsonArray.getJSONObject(cursor).get("ds").toString()));
cursor++;
return tuple;
}
return null;
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class TwitterJsonConverter method generateFieldsFromJson.
/**
* Generates Fields from the raw JSON tweet.
* Returns Optional.Empty() if something goes wrong while parsing this tweet.
*/
private Optional<List<IField>> generateFieldsFromJson(String rawJsonData) {
try {
// read the JSON string into a JSON object
JsonNode tweet = new ObjectMapper().readTree(rawJsonData);
// extract fields from the JSON object
String text = tweet.get("text").asText();
Long id = tweet.get("id").asLong();
String tweetLink = "https://twitter.com/statuses/" + id;
JsonNode userNode = tweet.get("user");
String userScreenName = userNode.get("screen_name").asText();
String userLink = "https://twitter.com/" + userScreenName;
String userName = userNode.get("name").asText();
String userDescription = userNode.get("description").asText();
Integer userFollowersCount = userNode.get("followers_count").asInt();
Integer userFriendsCount = userNode.get("friends_count").asInt();
JsonNode geoTagNode = tweet.get("geo_tag");
String state = geoTagNode.get("stateName").asText();
String county = geoTagNode.get("countyName").asText();
String city = geoTagNode.get("cityName").asText();
String createAt = tweet.get("create_at").asText();
ZonedDateTime zonedCreateAt = ZonedDateTime.parse(createAt, DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
String isRetweet = tweet.get("is_retweet").asText();
return Optional.of(Arrays.asList(new StringField(id.toString()), new TextField(text), new StringField(tweetLink), new StringField(userLink), new TextField(userScreenName), new TextField(userName), new TextField(userDescription), new IntegerField(userFollowersCount), new IntegerField(userFriendsCount), new TextField(state), new TextField(county), new TextField(city), new DateTimeField(zonedCreateAt.toLocalDateTime()), new StringField(isRetweet)));
} catch (Exception e) {
return Optional.empty();
}
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class TwitterFeedOperator method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED || resultCursor >= limit - 1 || resultCursor >= predicate.getTweetNum() - 1) {
return null;
}
if (twitterConnector.getClient().isDone()) {
System.out.println("Client connection closed unexpectedly: " + twitterConnector.getClient().getExitEvent().getMessage());
return null;
}
try {
msg = twitterConnector.getMsgQueue().poll(timeout, TimeUnit.SECONDS);
if (msg == null || msg.length() == 0) {
System.out.println("Did not receive a message in " + timeout + " seconds");
return null;
}
JsonNode tweet = new ObjectMapper().readValue(msg, JsonNode.class);
sourceTuple = new Tuple(outputSchema, IDField.newRandomID(), new TextField(TwitterUtils.getText(tweet)), new StringField(TwitterUtils.getMediaLink(tweet)), new StringField(TwitterUtils.getTweetLink(tweet)), new StringField(TwitterUtils.getUserLink(tweet)), new TextField(TwitterUtils.getUserScreenName(tweet)), new TextField(TwitterUtils.getUserName(tweet)), new TextField(TwitterUtils.getUserDescription(tweet)), new IntegerField(TwitterUtils.getUserFollowerCnt(tweet)), new IntegerField(TwitterUtils.getUserFriendsCnt(tweet)), new TextField(TwitterUtils.getUserLocation(tweet)), new StringField(TwitterUtils.getCreateTime(tweet)), new TextField(TwitterUtils.getPlaceName(tweet)), new StringField(TwitterUtils.getCoordinates(tweet)), new StringField(TwitterUtils.getLanguage(tweet)));
resultCursor++;
return sourceTuple;
} catch (InterruptedException e) {
System.out.println(e);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class KeywordPhraseTest method testPhraseSearchForStringField.
/**
* Verifies List<ITuple> returned by Phrase Matcher on multiple word query
* on a String Field
*
* @throws Exception
*/
@Test
public void testPhraseSearchForStringField() throws Exception {
// Prepare Query
String query = "george lin lin";
ArrayList<String> attributeNames = new ArrayList<>();
attributeNames.add(TestConstants.FIRST_NAME);
attributeNames.add(TestConstants.LAST_NAME);
attributeNames.add(TestConstants.DESCRIPTION);
// Prepare expected result list
List<Span> list = new ArrayList<Span>();
Span span1 = new Span("firstName", 0, 14, "george lin lin", "george lin lin");
list.add(span1);
Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length + 1];
for (int count = 0; count < schemaAttributes.length - 1; count++) {
schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
}
schemaAttributes[schemaAttributes.length - 1] = new Attribute(RESULTS, AttributeType.LIST);
IField[] fields1 = { new StringField("george lin lin"), new StringField("lin clooney"), new IntegerField(43), new DoubleField(6.06), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-13-1973")), new TextField("Lin Clooney is Short and lin clooney is Angry"), new ListField<>(list) };
Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
List<Tuple> expectedResultList = new ArrayList<>();
expectedResultList.add(tuple1);
// Perform Query
List<Tuple> resultList = KeywordTestHelper.getQueryResults(PEOPLE_TABLE, query, attributeNames, phrase);
// Perform Check
boolean contains = TestUtils.equals(expectedResultList, resultList);
Assert.assertTrue(contains);
}
Aggregations