use of edu.uci.ics.textdb.api.dataflow.IOperator 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);
}
use of edu.uci.ics.textdb.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();
ISink tupleSink = queryPlan.getRoot();
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);
}
use of edu.uci.ics.textdb.api.dataflow.IOperator 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);
}
use of edu.uci.ics.textdb.api.dataflow.IOperator in project textdb by TextDB.
the class LogicalPlan method findSinkOperator.
/*
* Finds the sink operator in the operator graph.
*
* This function assumes that the graph is valid and there is only one sink in the graph.
*/
private ISink findSinkOperator(HashMap<String, IOperator> operatorObjectMap) throws PlanGenException {
IOperator sinkOperator = adjacencyList.keySet().stream().filter(operator -> operatorPredicateMap.get(operator).getClass().toString().toLowerCase().contains("sink")).map(operator -> operatorObjectMap.get(operator)).findFirst().orElse(null);
PlanGenUtils.planGenAssert(sinkOperator != null, "Error: sink operator doesn't exist.");
PlanGenUtils.planGenAssert(sinkOperator instanceof ISink, "Error: sink operator's type doesn't match.");
return (ISink) sinkOperator;
}
use of edu.uci.ics.textdb.api.dataflow.IOperator 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(Paths.get(excelSink.getFilePath()));
}
Aggregations