use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class TwitterFeedOperatorTest method testWithMockClient.
/**
* Mock the TwitterConnector class and the BasicClient class inside it to test the TwitterFeedOperator alone.
* Use the pre-defined queue with a Json formatted tweet to generate a tuple.
* Check if the tuple is well-formatted.
*/
@Test
public void testWithMockClient() throws Exception {
TwitterConnector mockTwitterConnector = mock(TwitterConnector.class);
queue.add(inputStream);
TwitterFeedSourcePredicate predicate = new TwitterFeedSourcePredicate(1, keywordList, "", null, null, null, null, null);
TwitterFeedOperator operator = new TwitterFeedOperator(predicate, mockTwitterConnector);
operator.setTimeout(timeOut);
BasicClient mockClient = mock(BasicClient.class);
when(mockTwitterConnector.getClient()).thenReturn(mockClient);
when(mockTwitterConnector.getMsgQueue()).thenReturn(queue);
TupleSink tupleSink = new TupleSink();
tupleSink.setInputOperator(operator);
tupleSink.open();
List<Tuple> exactResults = tupleSink.collectAllTuples();
tupleSink.close();
JsonNode tweet = new ObjectMapper().readValue(inputStream, JsonNode.class);
Tuple expectedTuple = new Tuple(TwitterUtils.TwitterSchema.TWITTER_SCHEMA, 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)));
String exactID = exactResults.get(0).getFields().get(0).getValue().toString();
String expectedID = exactResults.get(0).getField(SchemaConstants._ID).getValue().toString();
Assert.assertEquals(exactResults.size(), 1);
Assert.assertEquals(exactID, expectedID);
Assert.assertTrue(TwitterFeedTestHelper.compareTuple(exactResults, expectedTuple));
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class LineChartSinkTestConstants method getTuples.
public static List<Tuple> getTuples() {
IField[] fields1 = { new IntegerField(1), new StringField("Tom"), new IntegerField(90), new StringField("M") };
IField[] fields2 = { new IntegerField(2), new StringField("Jerry"), new IntegerField(80), new StringField("M") };
IField[] fields3 = { new IntegerField(3), new StringField("Bob"), new IntegerField(70), new StringField("M") };
Tuple tuple1 = new Tuple(BAR_SCHEMA, fields1);
Tuple tuple2 = new Tuple(BAR_SCHEMA, fields2);
Tuple tuple3 = new Tuple(BAR_SCHEMA, fields3);
return Arrays.asList(tuple1, tuple2, tuple3);
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class WordCloudSinkTestConstants method getResultTuples.
public static List<Tuple> getResultTuples() {
IField[] fields1 = { new StringField("foo"), new IntegerField(200) };
IField[] fields2 = { new StringField("amy"), new IntegerField(100) };
IField[] fields3 = { new StringField("bob"), new IntegerField(50) };
Tuple tuple1 = new Tuple(WORD_CLOUD_RESULT_SCHEMA, fields1);
Tuple tuple2 = new Tuple(WORD_CLOUD_RESULT_SCHEMA, fields2);
Tuple tuple3 = new Tuple(WORD_CLOUD_RESULT_SCHEMA, fields3);
return Arrays.asList(tuple1, tuple2, tuple3);
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class CatalogConstants method getSchemaCatalogTuples.
/**
* Gets the tuples to be inserted to the schema catalog.
*
* @param tableName
* @param tableDirectory
* @param luceneAnalyzerStr
* @return
* @throws StorageException
*/
public static List<Tuple> getSchemaCatalogTuples(String tableName, Schema tableSchema) {
List<Tuple> schemaCatalogTuples = new ArrayList<>();
for (int i = 0; i < tableSchema.getAttributes().size(); i++) {
Attribute attr = tableSchema.getAttributes().get(i);
Tuple schemaTuple = new Tuple(SCHEMA_CATALOG_SCHEMA, new StringField(tableName), new StringField(attr.getName()), new StringField(attr.getType().toString().toLowerCase()), new IntegerField(i));
schemaCatalogTuples.add(schemaTuple);
}
return schemaCatalogTuples;
}
use of edu.uci.ics.texera.api.field.StringField in project textdb by TextDB.
the class WordCountIndexSource method computeNextMatchingTuple.
private Tuple computeNextMatchingTuple() throws TexeraException {
if (sortedWordCountMap == null) {
computeWordCount();
}
if (wordCountIterator.hasNext()) {
Entry<String, Integer> entry = wordCountIterator.next();
List<IField> tupleFieldList = new ArrayList<>();
// Generate the new UUID.
tupleFieldList.add(IDField.newRandomID());
tupleFieldList.add(new StringField(entry.getKey()));
tupleFieldList.add(new IntegerField(entry.getValue()));
cursor++;
return new Tuple(SCHEMA_WORD_COUNT, tupleFieldList);
}
return null;
}
Aggregations