Search in sources :

Example 1 with IOperator

use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.

the class LogicalPlanTest method testLogicalPlan1.

/*
     * Test a valid operator graph.
     *
     * KeywordSource --> RegexMatcher --> TupleSink
     *
     */
@Test
public void testLogicalPlan1() throws Exception {
    LogicalPlan logicalPlan = getLogicalPlan1();
    Plan queryPlan = logicalPlan.buildQueryPlan();
    HashMap<String, ISink> sinkHashMap = queryPlan.getSinkMap();
    Assert.assertEquals(1, sinkHashMap.size());
    ISink tupleSink = null;
    for (HashMap.Entry<String, ISink> entry : sinkHashMap.entrySet()) {
        tupleSink = entry.getValue();
    }
    Assert.assertTrue(tupleSink instanceof TupleSink);
    IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator();
    Assert.assertTrue(regexMatcher instanceof RegexMatcher);
    IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator();
    Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
Also used : ISink(edu.uci.ics.texera.api.dataflow.ISink) TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) HashMap(java.util.HashMap) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) RegexMatcher(edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher) Plan(edu.uci.ics.texera.api.engine.Plan) KeywordMatcherSourceOperator(edu.uci.ics.texera.dataflow.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Example 2 with IOperator

use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.

the class ExcelSinkTest method attributeTypeTest.

@Test
public // writing 10000 tuples
void attributeTypeTest() 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 inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    // excel writing test
    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) 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) Test(org.junit.Test)

Example 3 with IOperator

use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.

the class MysqlSinkTest method test2TupleInsertion.

/**
 * Create two tuples, insert into mysql
 * @throws ParseException
 */
public void test2TupleInsertion() 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 localInputOperator = Mockito.mock(IOperator.class);
    Mockito.when(localInputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes)).thenReturn(null);
    Mockito.when(localInputOperator.getNextTuple()).thenReturn(tuple1).thenReturn(tuple2).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) 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)

Example 4 with IOperator

use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.

the class OneToNBroadcastConnectorTest method testTwoOutputsWithProjection.

/*
     * This test connects Connector with Projection
     */
@Test
public void testTwoOutputsWithProjection() throws TexeraException {
    IOperator sourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
    List<String> projectionFields = Arrays.asList(TestConstants.DESCRIPTION);
    Schema projectionSchema = new Schema(TestConstants.DESCRIPTION_ATTR);
    IField[] fields1 = { new TextField("Tall Angry") };
    IField[] fields2 = { new TextField("Short Brown") };
    IField[] fields3 = { new TextField("White Angry") };
    IField[] fields4 = { new TextField("Lin Clooney is Short and lin clooney is Angry") };
    IField[] fields5 = { new TextField("Tall Fair") };
    IField[] fields6 = { new TextField("Short angry") };
    Tuple tuple1 = new Tuple(projectionSchema, fields1);
    Tuple tuple2 = new Tuple(projectionSchema, fields2);
    Tuple tuple3 = new Tuple(projectionSchema, fields3);
    Tuple tuple4 = new Tuple(projectionSchema, fields4);
    Tuple tuple5 = new Tuple(projectionSchema, fields5);
    Tuple tuple6 = new Tuple(projectionSchema, fields6);
    List<Tuple> expectedResults = Arrays.asList(tuple1, tuple2, tuple3, tuple4, tuple5, tuple6);
    ProjectionPredicate projectionPredicate = new ProjectionPredicate(projectionFields);
    ProjectionOperator projection1 = new ProjectionOperator(projectionPredicate);
    ProjectionOperator projection2 = new ProjectionOperator(projectionPredicate);
    OneToNBroadcastConnector connector = new OneToNBroadcastConnector(2);
    connector.setInputOperator(sourceOperator);
    projection1.setInputOperator(connector.getOutputOperator(0));
    projection2.setInputOperator(connector.getOutputOperator(1));
    projection1.open();
    List<Tuple> projection1Results = new ArrayList<>();
    Tuple nextTuple = null;
    while ((nextTuple = projection1.getNextTuple()) != null) {
        projection1Results.add(nextTuple);
    }
    projection1.close();
    projection2.open();
    List<Tuple> projection2Results = new ArrayList<>();
    nextTuple = null;
    while ((nextTuple = projection2.getNextTuple()) != null) {
        projection2Results.add(nextTuple);
    }
    projection2.close();
    Assert.assertTrue(TestUtils.equals(expectedResults, projection1Results));
    Assert.assertTrue(TestUtils.equals(expectedResults, projection2Results));
    Assert.assertTrue(TestUtils.equals(projection1Results, projection2Results));
}
Also used : ProjectionOperator(edu.uci.ics.texera.dataflow.projection.ProjectionOperator) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) ArrayList(java.util.ArrayList) IField(edu.uci.ics.texera.api.field.IField) ProjectionPredicate(edu.uci.ics.texera.dataflow.projection.ProjectionPredicate) ScanBasedSourceOperator(edu.uci.ics.texera.dataflow.source.scan.ScanBasedSourceOperator) TextField(edu.uci.ics.texera.api.field.TextField) ScanSourcePredicate(edu.uci.ics.texera.dataflow.source.scan.ScanSourcePredicate) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Example 5 with IOperator

use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.

the class OneToNBroadcastConnectorTest method testThreeOutputsWithItself.

/*
     * This test tests if the connectors' three outputs are the same.
     */
@Test
public void testThreeOutputsWithItself() throws Exception {
    IOperator sourceOperator = new ScanBasedSourceOperator(new ScanSourcePredicate(PEOPLE_TABLE));
    OneToNBroadcastConnector connector = new OneToNBroadcastConnector(3);
    connector.setInputOperator(sourceOperator);
    IOperator output1 = connector.getOutputOperator(0);
    IOperator output2 = connector.getOutputOperator(1);
    IOperator output3 = connector.getOutputOperator(2);
    output1.open();
    output2.open();
    output3.open();
    List<Tuple> output1Results = new ArrayList<>();
    Tuple nextTuple = null;
    while ((nextTuple = output1.getNextTuple()) != null) {
        output1Results.add(nextTuple);
    }
    List<Tuple> output2Results = new ArrayList<>();
    nextTuple = null;
    while ((nextTuple = output2.getNextTuple()) != null) {
        output2Results.add(nextTuple);
    }
    List<Tuple> output3Results = new ArrayList<>();
    nextTuple = null;
    while ((nextTuple = output3.getNextTuple()) != null) {
        output3Results.add(nextTuple);
    }
    output1.close();
    output2.close();
    output3.close();
    List<Tuple> expectedResults = TestConstants.getSamplePeopleTuples();
    Assert.assertTrue(TestUtils.equals(expectedResults, output1Results));
    Assert.assertTrue(TestUtils.equals(expectedResults, output2Results));
    Assert.assertTrue(TestUtils.equals(expectedResults, output3Results));
}
Also used : IOperator(edu.uci.ics.texera.api.dataflow.IOperator) ArrayList(java.util.ArrayList) ScanBasedSourceOperator(edu.uci.ics.texera.dataflow.source.scan.ScanBasedSourceOperator) ScanSourcePredicate(edu.uci.ics.texera.dataflow.source.scan.ScanSourcePredicate) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

IOperator (edu.uci.ics.texera.api.dataflow.IOperator)18 Schema (edu.uci.ics.texera.api.schema.Schema)12 Test (org.junit.Test)11 ISink (edu.uci.ics.texera.api.dataflow.ISink)8 Plan (edu.uci.ics.texera.api.engine.Plan)8 HashMap (java.util.HashMap)8 RegexMatcher (edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher)7 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)7 ArrayList (java.util.ArrayList)7 Tuple (edu.uci.ics.texera.api.tuple.Tuple)6 IField (edu.uci.ics.texera.api.field.IField)5 TextField (edu.uci.ics.texera.api.field.TextField)5 OneToNBroadcastConnector (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector)5 DateField (edu.uci.ics.texera.api.field.DateField)4 DoubleField (edu.uci.ics.texera.api.field.DoubleField)4 IntegerField (edu.uci.ics.texera.api.field.IntegerField)4 StringField (edu.uci.ics.texera.api.field.StringField)4 Attribute (edu.uci.ics.texera.api.schema.Attribute)4 Join (edu.uci.ics.texera.dataflow.join.Join)4 ConnectorOutputOperator (edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector.ConnectorOutputOperator)3