Search in sources :

Example 76 with IntegerField

use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.

the class BarChartSinkTestConstants method getResultTuples.

public static List<Tuple> getResultTuples() {
    IField[] fields1 = { new StringField("Tom"), new IntegerField(90) };
    IField[] fields2 = { new StringField("Jerry"), new IntegerField(80) };
    IField[] fields3 = { new StringField("Bob"), new IntegerField(70) };
    Tuple tuple1 = new Tuple(BAR_RESULT_SCHEMA, fields1);
    Tuple tuple2 = new Tuple(BAR_RESULT_SCHEMA, fields2);
    Tuple tuple3 = new Tuple(BAR_RESULT_SCHEMA, fields3);
    return Arrays.asList(tuple1, tuple2, tuple3);
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 77 with IntegerField

use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.

the class ExcelSinkTest method writeSampleExcelFile.

/**
 * Create two tuples, write into a excel file. Need to manually delete the generated file.
 * @throws ParseException
 */
@Test
public void writeSampleExcelFile() throws Exception {
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare the expected result list
    List<Span> list = new ArrayList<>();
    Span span1 = new Span("firstName", 0, 5, "bruce", "bruce");
    Span span2 = new Span("lastnName", 0, 5, "jacki", "jacki");
    list.add(span1);
    list.add(span2);
    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] = SchemaConstants.SPAN_LIST_ATTRIBUTE;
    IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("01-14-1970")), new TextField("Tall Angry"), new ListField<>(list) };
    IField[] fields2 = { new StringField("test"), new StringField("jackie chan"), new IntegerField(0), new DoubleField(6.0), new DateField(new SimpleDateFormat("MM-dd-yyyy").parse("09-18-1994")), new TextField("Angry Bird"), new ListField<>(list) };
    Tuple tuple1 = new Tuple(new Schema(schemaAttributes), fields1);
    Tuple tuple2 = new Tuple(new Schema(schemaAttributes), fields2);
    IOperator inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes)).thenReturn(null);
    Mockito.when(inputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).thenReturn(null);
    excelSink = new ExcelSink(new ExcelSinkPredicate());
    excelSink.setInputOperator(inputOperator);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    Files.deleteIfExists(excelSink.getFilePath());
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Span(edu.uci.ics.texera.api.span.Span) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) SimpleDateFormat(java.text.SimpleDateFormat) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 78 with IntegerField

use of edu.uci.ics.texera.api.field.IntegerField in project textdb by TextDB.

the class MysqlSinkTest method testTupleListInsertion.

/**
 * Create 10000 tuples with all regular fields
 * Insert into mysql database
 */
public void testTupleListInsertion() throws Exception {
    ArrayList<String> attributeNames = new ArrayList<>();
    attributeNames.add(TestConstants.FIRST_NAME);
    attributeNames.add(TestConstants.LAST_NAME);
    attributeNames.add(TestConstants.AGE);
    attributeNames.add(TestConstants.HEIGHT);
    attributeNames.add(TestConstants.DATE_OF_BIRTH);
    attributeNames.add(TestConstants.DESCRIPTION);
    // Prepare Schema
    Attribute[] schemaAttributes = new Attribute[TestConstants.ATTRIBUTES_PEOPLE.length];
    for (int count = 0; count < schemaAttributes.length; count++) {
        schemaAttributes[count] = TestConstants.ATTRIBUTES_PEOPLE[count];
    }
    // Prepare 10000 tuples as a tupleList
    int testSize = 10000;
    Random rand = new Random();
    List<Tuple> tupleList = new ArrayList<Tuple>();
    for (int i = 0; i < testSize; i++) {
        IField[] fields = { new StringField(getRandomString()), new StringField(getRandomString()), new IntegerField(rand.nextInt()), new DoubleField(rand.nextDouble() * rand.nextInt()), new DateField(getRandomDate()), new TextField(getRandomString()) };
        tupleList.add(new Tuple(new Schema(schemaAttributes), fields));
    }
    assert (tupleList.size() == testSize);
    IOperator localInputOperator = Mockito.mock(IOperator.class);
    Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(localInputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    mysqlSink.setInputOperator(localInputOperator);
    mysqlSink.open();
    mysqlSink.processTuples();
    mysqlSink.close();
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Random(java.util.Random) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) DateField(edu.uci.ics.texera.api.field.DateField) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DoubleField(edu.uci.ics.texera.api.field.DoubleField)

Example 79 with IntegerField

use of edu.uci.ics.texera.api.field.IntegerField 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));
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.texera.api.field.IntegerField) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) BasicClient(com.twitter.hbc.httpclient.BasicClient) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 80 with IntegerField

use of edu.uci.ics.texera.api.field.IntegerField 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);
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) IntegerField(edu.uci.ics.texera.api.field.IntegerField) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Aggregations

IntegerField (edu.uci.ics.texera.api.field.IntegerField)98 Tuple (edu.uci.ics.texera.api.tuple.Tuple)90 IField (edu.uci.ics.texera.api.field.IField)88 StringField (edu.uci.ics.texera.api.field.StringField)87 TextField (edu.uci.ics.texera.api.field.TextField)79 ArrayList (java.util.ArrayList)75 Schema (edu.uci.ics.texera.api.schema.Schema)72 Test (org.junit.Test)70 Span (edu.uci.ics.texera.api.span.Span)66 DoubleField (edu.uci.ics.texera.api.field.DoubleField)65 DateField (edu.uci.ics.texera.api.field.DateField)59 SimpleDateFormat (java.text.SimpleDateFormat)57 Attribute (edu.uci.ics.texera.api.schema.Attribute)56 Dictionary (edu.uci.ics.texera.dataflow.dictionarymatcher.Dictionary)29 JoinDistancePredicate (edu.uci.ics.texera.dataflow.join.JoinDistancePredicate)9 KeywordMatcherSourceOperator (edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)4 DateTimeField (edu.uci.ics.texera.api.field.DateTimeField)3