Search in sources :

Example 11 with IOperator

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

the class OneToNBroadcastConnectorTest method testTwoOutputsWithProjection.

/*
     * This test connects Connector with Projection
     */
@Test
public void testTwoOutputsWithProjection() throws TextDBException {
    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.textdb.exp.projection.ProjectionOperator) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IField(edu.uci.ics.textdb.api.field.IField) ProjectionPredicate(edu.uci.ics.textdb.exp.projection.ProjectionPredicate) ScanBasedSourceOperator(edu.uci.ics.textdb.exp.source.scan.ScanBasedSourceOperator) TextField(edu.uci.ics.textdb.api.field.TextField) ScanSourcePredicate(edu.uci.ics.textdb.exp.source.scan.ScanSourcePredicate) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Aggregations

IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)11 Test (org.junit.Test)7 ISink (edu.uci.ics.textdb.api.dataflow.ISink)5 Plan (edu.uci.ics.textdb.api.engine.Plan)5 ArrayList (java.util.ArrayList)5 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)4 OneToNBroadcastConnector (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)4 IField (edu.uci.ics.textdb.api.field.IField)3 TextField (edu.uci.ics.textdb.api.field.TextField)3 Schema (edu.uci.ics.textdb.api.schema.Schema)3 Join (edu.uci.ics.textdb.exp.join.Join)3 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)3 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)3 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)3 HashSet (java.util.HashSet)3 DateField (edu.uci.ics.textdb.api.field.DateField)2 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)2 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)2 StringField (edu.uci.ics.textdb.api.field.StringField)2 Attribute (edu.uci.ics.textdb.api.schema.Attribute)2