Search in sources :

Example 1 with Join

use of edu.uci.ics.textdb.exp.join.Join in project textdb by TextDB.

the class LogicalPlanTest method testLogicalPlan3.

/*
     * Test a valid operator graph.
     * 
     *                  --> RegexMatcher -->
     *                  |                    >-- Join1
     * KeywordSource --< -> NlpEntityOperator -->          >-- Join2 --> TupleSink
     *                  |                           /
     *                  --> FuzzyTokenMatcher ----->
     * 
     */
@Test
public void testLogicalPlan3() throws Exception {
    LogicalPlan logicalPlan = getLogicalPlan3();
    Plan queryPlan = logicalPlan.buildQueryPlan();
    ISink tupleSink = queryPlan.getRoot();
    Assert.assertTrue(tupleSink instanceof TupleSink);
    IOperator join2 = ((TupleSink) tupleSink).getInputOperator();
    Assert.assertTrue(join2 instanceof Join);
    IOperator join2Input1 = ((Join) join2).getOuterInputOperator();
    Assert.assertTrue(join2Input1 instanceof Join);
    IOperator join2Input2 = ((Join) join2).getInnerInputOperator();
    Assert.assertTrue(join2Input2 instanceof FuzzyTokenMatcher);
    IOperator join1Input1 = ((Join) join2Input1).getInnerInputOperator();
    Assert.assertTrue(join1Input1 instanceof RegexMatcher);
    IOperator join1Input2 = ((Join) join2Input1).getOuterInputOperator();
    Assert.assertTrue(join1Input2 instanceof NlpEntityOperator);
    IOperator connectorOut1 = ((RegexMatcher) join1Input1).getInputOperator();
    Assert.assertTrue(connectorOut1 instanceof ConnectorOutputOperator);
    IOperator connectorOut2 = ((NlpEntityOperator) join1Input2).getInputOperator();
    Assert.assertTrue(connectorOut2 instanceof ConnectorOutputOperator);
    IOperator connectorOut3 = ((FuzzyTokenMatcher) join2Input2).getInputOperator();
    Assert.assertTrue(connectorOut3 instanceof ConnectorOutputOperator);
    HashSet<Integer> connectorIndices = new HashSet<>();
    connectorIndices.add(((ConnectorOutputOperator) connectorOut1).getOutputIndex());
    connectorIndices.add(((ConnectorOutputOperator) connectorOut2).getOutputIndex());
    connectorIndices.add(((ConnectorOutputOperator) connectorOut3).getOutputIndex());
    Assert.assertEquals(connectorIndices.size(), 3);
    OneToNBroadcastConnector connector1 = ((ConnectorOutputOperator) connectorOut1).getOwnerConnector();
    OneToNBroadcastConnector connector2 = ((ConnectorOutputOperator) connectorOut2).getOwnerConnector();
    OneToNBroadcastConnector connector3 = ((ConnectorOutputOperator) connectorOut3).getOwnerConnector();
    Assert.assertSame(connector1, connector2);
    Assert.assertSame(connector1, connector3);
    IOperator keywordSource = connector1.getInputOperator();
    Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Join(edu.uci.ics.textdb.exp.join.Join) Plan(edu.uci.ics.textdb.api.engine.Plan) FuzzyTokenMatcher(edu.uci.ics.textdb.exp.fuzzytokenmatcher.FuzzyTokenMatcher) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) ISink(edu.uci.ics.textdb.api.dataflow.ISink) ConnectorOutputOperator(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator) NlpEntityOperator(edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator) RegexMatcher(edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher) OneToNBroadcastConnector(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Join

use of edu.uci.ics.textdb.exp.join.Join in project textdb by TextDB.

the class JoinDistanceTest method testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed.

// ------------------------<Test cases for cursor.>------------------------
/*
     * This case tests for the scenario when open and/or close is called twice 
     * and also when getNextTuple() is called when operator is closed.
     * Test result: Opening or closing the operator twice shouldn't result in 
     * any noticeable difference in operation. But, calling getNetTuple() when 
     * operator is closed should throw an exception.
     */
@Test(expected = DataFlowException.class)
public void testWhenOpenOrCloseIsCalledTwiceAndTryToGetNextTupleWhenClosed() throws Exception {
    List<Tuple> tuples = JoinTestConstants.bookGroup1.subList(1, 5);
    JoinTestHelper.insertToTable(BOOK_TABLE, tuples);
    KeywordMatcherSourceOperator keywordSourceOuter = JoinTestHelper.getKeywordSource(BOOK_TABLE, "typical", conjunction);
    KeywordMatcherSourceOperator keywordSourceInner = JoinTestHelper.getKeywordSource(BOOK_TABLE, "actually", conjunction);
    JoinDistancePredicate distancePredicate = new JoinDistancePredicate(JoinTestConstants.REVIEW, 90);
    Join join = new Join(distancePredicate);
    join.setOuterInputOperator(keywordSourceOuter);
    join.setInnerInputOperator(keywordSourceInner);
    Tuple tuple;
    List<Tuple> resultList = new ArrayList<>();
    join.open();
    join.open();
    while ((tuple = join.getNextTuple()) != null) {
        resultList.add(tuple);
    }
    join.close();
    join.close();
    Assert.assertEquals(4, resultList.size());
    // this line should throw an exception because operator is already closed
    if ((tuple = join.getNextTuple()) != null) {
        resultList.add(tuple);
    }
}
Also used : ArrayList(java.util.ArrayList) Join(edu.uci.ics.textdb.exp.join.Join) JoinDistancePredicate(edu.uci.ics.textdb.exp.join.JoinDistancePredicate) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Example 3 with Join

use of edu.uci.ics.textdb.exp.join.Join in project textdb by TextDB.

the class JoinTestHelper method getJoinDistanceResults.

/**
     * Wraps the logic of creating a Join Operator, getting all the results,
     *   and returning the result tuples in a list.
     * 
     * @param outerOp
     * @param innerOp
     * @param joinPredicate
     * @param limit
     * @param offset
     * @return
     * @throws TextDBException
     */
public static List<Tuple> getJoinDistanceResults(IOperator innerOp, IOperator outerOp, IJoinPredicate joinPredicate, int limit, int offset) throws TextDBException {
    Join join = new Join(joinPredicate);
    join.setInnerInputOperator(innerOp);
    join.setOuterInputOperator(outerOp);
    join.setLimit(limit);
    join.setOffset(offset);
    Tuple tuple;
    List<Tuple> results = new ArrayList<>();
    join.open();
    while ((tuple = join.getNextTuple()) != null) {
        results.add(tuple);
    }
    join.close();
    return results;
}
Also used : ArrayList(java.util.ArrayList) Join(edu.uci.ics.textdb.exp.join.Join) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 4 with Join

use of edu.uci.ics.textdb.exp.join.Join in project textdb by TextDB.

the class LogicalPlanTest method testLogicalPlan2.

/*
     * Test a valid operator graph.
     *                  -> RegexMatcher -->
     * KeywordSource --<                     >-- Join --> TupleSink
     *                  -> NlpEntityOperator -->
     * 
     */
@Test
public void testLogicalPlan2() throws Exception {
    LogicalPlan logicalPlan = getLogicalPlan2();
    Plan queryPlan = logicalPlan.buildQueryPlan();
    ISink tupleSink = queryPlan.getRoot();
    Assert.assertTrue(tupleSink instanceof TupleSink);
    IOperator join = ((TupleSink) tupleSink).getInputOperator();
    Assert.assertTrue(join instanceof Join);
    IOperator joinInput1 = ((Join) join).getInnerInputOperator();
    Assert.assertTrue(joinInput1 instanceof RegexMatcher);
    IOperator joinInput2 = ((Join) join).getOuterInputOperator();
    Assert.assertTrue(joinInput2 instanceof NlpEntityOperator);
    IOperator connectorOut1 = ((RegexMatcher) joinInput1).getInputOperator();
    Assert.assertTrue(connectorOut1 instanceof ConnectorOutputOperator);
    IOperator connectorOut2 = ((NlpEntityOperator) joinInput2).getInputOperator();
    Assert.assertTrue(connectorOut2 instanceof ConnectorOutputOperator);
    HashSet<Integer> connectorIndices = new HashSet<>();
    connectorIndices.add(((ConnectorOutputOperator) connectorOut1).getOutputIndex());
    connectorIndices.add(((ConnectorOutputOperator) connectorOut2).getOutputIndex());
    Assert.assertEquals(connectorIndices.size(), 2);
    OneToNBroadcastConnector connector1 = ((ConnectorOutputOperator) connectorOut1).getOwnerConnector();
    OneToNBroadcastConnector connector2 = ((ConnectorOutputOperator) connectorOut2).getOwnerConnector();
    Assert.assertSame(connector1, connector2);
    IOperator keywordSource = connector1.getInputOperator();
    Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator);
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Join(edu.uci.ics.textdb.exp.join.Join) Plan(edu.uci.ics.textdb.api.engine.Plan) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) ISink(edu.uci.ics.textdb.api.dataflow.ISink) ConnectorOutputOperator(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator) NlpEntityOperator(edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator) RegexMatcher(edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher) OneToNBroadcastConnector(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Join (edu.uci.ics.textdb.exp.join.Join)4 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)3 Test (org.junit.Test)3 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)2 ISink (edu.uci.ics.textdb.api.dataflow.ISink)2 Plan (edu.uci.ics.textdb.api.engine.Plan)2 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)2 OneToNBroadcastConnector (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)2 ConnectorOutputOperator (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator)2 NlpEntityOperator (edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator)2 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)2 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FuzzyTokenMatcher (edu.uci.ics.textdb.exp.fuzzytokenmatcher.FuzzyTokenMatcher)1 JoinDistancePredicate (edu.uci.ics.textdb.exp.join.JoinDistancePredicate)1