Search in sources :

Example 1 with IOperator

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

the class LogicalPlan method buildQueryPlan.

/**
     * Builds and returns the query plan from the operator graph.
     * 
     * @return the plan generated from the operator graph
     * @throws PlanGenException, if the operator graph is invalid.
     */
public Plan buildQueryPlan() throws PlanGenException {
    HashMap<String, IOperator> operatorObjectMap = buildOperators();
    validateOperatorGraph();
    connectOperators(operatorObjectMap);
    ISink sink = findSinkOperator(operatorObjectMap);
    Plan queryPlan = new Plan(sink);
    return queryPlan;
}
Also used : ISink(edu.uci.ics.textdb.api.dataflow.ISink) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Plan(edu.uci.ics.textdb.api.engine.Plan)

Example 2 with IOperator

use of edu.uci.ics.textdb.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.textdb.api.dataflow.IOperator) OneToNBroadcastConnector(edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)

Example 3 with IOperator

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

the class LogicalPlan method buildOperators.

/*
     * Build the operator objects from operator properties.
     */
private HashMap<String, IOperator> buildOperators() throws PlanGenException {
    HashMap<String, IOperator> operatorObjectMap = new HashMap<>();
    for (String operatorID : operatorPredicateMap.keySet()) {
        IOperator operator = operatorPredicateMap.get(operatorID).newOperator();
        operatorObjectMap.put(operatorID, operator);
    }
    return operatorObjectMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator)

Example 4 with IOperator

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

the class ExcelSinkTest method attributeTypeTest.

@Test
public // writing 10000 tuples
void attributeTypeTest() 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 inputOperator = Mockito.mock(IOperator.class);
    Mockito.when(inputOperator.getOutputSchema()).thenReturn(new Schema(schemaAttributes));
    OngoingStubbing<Tuple> stubbing = Mockito.when(inputOperator.getNextTuple());
    for (Tuple t : tupleList) {
        stubbing = stubbing.thenReturn(t);
    }
    stubbing = stubbing.thenReturn(null);
    // excel writing test
    excelSink = new ExcelSink(new ExcelSinkPredicate());
    excelSink.setInputOperator(inputOperator);
    excelSink.open();
    excelSink.collectAllTuples();
    excelSink.close();
    Files.deleteIfExists(Paths.get(excelSink.getFilePath()));
}
Also used : Attribute(edu.uci.ics.textdb.api.schema.Attribute) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Schema(edu.uci.ics.textdb.api.schema.Schema) ArrayList(java.util.ArrayList) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) IField(edu.uci.ics.textdb.api.field.IField) Random(java.util.Random) StringField(edu.uci.ics.textdb.api.field.StringField) TextField(edu.uci.ics.textdb.api.field.TextField) DateField(edu.uci.ics.textdb.api.field.DateField) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) Test(org.junit.Test)

Example 5 with IOperator

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

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