Search in sources :

Example 11 with IOperator

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);
}
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) Schema(edu.uci.ics.texera.api.schema.Schema) RegexMatcher(edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher) Plan(edu.uci.ics.texera.api.engine.Plan) Test(org.junit.Test)

Example 12 with IOperator

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);
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) HashMap(java.util.HashMap) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) RegexPredicate(edu.uci.ics.texera.dataflow.regexmatcher.RegexPredicate) Schema(edu.uci.ics.texera.api.schema.Schema) Plan(edu.uci.ics.texera.api.engine.Plan) ISink(edu.uci.ics.texera.api.dataflow.ISink) RegexMatcher(edu.uci.ics.texera.dataflow.regexmatcher.RegexMatcher) Test(org.junit.Test)

Example 13 with IOperator

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());
}
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) Test(org.junit.Test)

Example 14 with IOperator

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();
}
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)

Example 15 with IOperator

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);
            }
        }
    }
}
Also used : IOperator(edu.uci.ics.texera.api.dataflow.IOperator) OneToNBroadcastConnector(edu.uci.ics.texera.dataflow.connector.OneToNBroadcastConnector)

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