use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.
the class LogicalPlanTest method testGetOutputSchema4.
/*
* Test getOutputSchema on a operator graph without a sink operator
*
* KeywordSource --> RegexMatcher
*
*/
@Test
public void testGetOutputSchema4() throws Exception {
LogicalPlan validLogicalPlan = getLogicalPlan1();
Plan queryPlan = validLogicalPlan.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.assertNotNull(tupleSink);
IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator();
IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator();
regexMatcher.open();
Schema expectedSourceOutputSchema = keywordSource.getOutputSchema();
Schema expectedMatcherOutputSchema = regexMatcher.getOutputSchema();
regexMatcher.close();
LogicalPlan logicalPlan = new LogicalPlan();
logicalPlan.addOperator(keywordSourcePredicate);
logicalPlan.addOperator(regexPredicate);
logicalPlan.addLink(new OperatorLink(KEYWORD_SOURCE_ID, REGEX_ID));
Schema sourceOutputSchema = logicalPlan.getOperatorOutputSchema(KEYWORD_SOURCE_ID);
Schema matcherOutputSchema = logicalPlan.getOperatorOutputSchema(REGEX_ID);
Assert.assertEquals(expectedSourceOutputSchema, sourceOutputSchema);
Assert.assertEquals(expectedMatcherOutputSchema, matcherOutputSchema);
}
use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.
the class LogicalPlanTest method testGetOutputSchema5.
/*
* Test a operator graph with a disconnected component
*
* KeywordSource --> RegexMatcher --> TupleSink
* RegexMatcher --> NlpEntityOperator
* (a disconnected graph)
*
*/
@Test(expected = TexeraException.class)
public void testGetOutputSchema5() throws Exception {
LogicalPlan validLogicalPlan = getLogicalPlan1();
Plan queryPlan = validLogicalPlan.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.assertNotNull(tupleSink);
IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator();
IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator();
regexMatcher.open();
Schema expectedSourceOutputSchema = keywordSource.getOutputSchema();
Schema expectedMatcherOutputSchema = regexMatcher.getOutputSchema();
regexMatcher.close();
LogicalPlan logicalPlan = new LogicalPlan();
String REGEX_ID_2 = "regex 2";
RegexPredicate regexPredicate2 = new RegexPredicate("ca(lifornia)?", Arrays.asList("location", "content"), "regexResults");
regexPredicate2.setID(REGEX_ID_2);
logicalPlan.addOperator(keywordSourcePredicate);
logicalPlan.addOperator(regexPredicate);
logicalPlan.addOperator(tupleSinkPredicate);
logicalPlan.addOperator(regexPredicate2);
logicalPlan.addOperator(nlpEntityPredicate);
logicalPlan.addLink(new OperatorLink(KEYWORD_SOURCE_ID, REGEX_ID));
logicalPlan.addLink(new OperatorLink(REGEX_ID, TUPLE_SINK_ID));
logicalPlan.addLink(new OperatorLink(REGEX_ID_2, NLP_ENTITY_ID));
Schema sourceOutputSchema = logicalPlan.getOperatorOutputSchema(KEYWORD_SOURCE_ID);
Schema matcherOutputSchema = logicalPlan.getOperatorOutputSchema(REGEX_ID);
Assert.assertEquals(expectedSourceOutputSchema, sourceOutputSchema);
Assert.assertEquals(expectedMatcherOutputSchema, matcherOutputSchema);
Schema raiseExceptionSchema = logicalPlan.getOperatorOutputSchema(REGEX_ID_2);
}
use of edu.uci.ics.texera.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(excelSink.getFilePath());
}
use of edu.uci.ics.texera.api.dataflow.IOperator 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();
}
use of edu.uci.ics.texera.api.dataflow.IOperator in project textdb by TextDB.
the class LogicalPlan method connectOperators.
/*
* Connects IOperator objects together according to the operator graph.
*
* This function assumes that the operator graph is valid.
* It goes through every link, and invokes
* the corresponding "setInputOperator" function to connect operators.
*/
private void connectOperators(HashMap<String, IOperator> operatorObjectMap) throws PlanGenException {
for (String vertex : adjacencyList.keySet()) {
IOperator currentOperator = operatorObjectMap.get(vertex);
int outputArity = adjacencyList.get(vertex).size();
// automatically adds a OneToNBroadcastConnector if the output arity > 1
if (outputArity > 1) {
OneToNBroadcastConnector oneToNConnector = new OneToNBroadcastConnector(outputArity);
oneToNConnector.setInputOperator(currentOperator);
int counter = 0;
for (String adjacentVertex : adjacencyList.get(vertex)) {
IOperator adjacentOperator = operatorObjectMap.get(adjacentVertex);
handleSetInputOperator(oneToNConnector.getOutputOperator(counter), adjacentOperator);
counter++;
}
} else {
for (String adjacentVertex : adjacencyList.get(vertex)) {
IOperator adjacentOperator = operatorObjectMap.get(adjacentVertex);
handleSetInputOperator(currentOperator, adjacentOperator);
}
}
}
}
Aggregations