Search in sources :

Example 1 with Plan

use of edu.uci.ics.textdb.api.engine.Plan 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 Plan

use of edu.uci.ics.textdb.api.engine.Plan 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 3 with Plan

use of edu.uci.ics.textdb.api.engine.Plan 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);
}
Also used : ISink(edu.uci.ics.textdb.api.dataflow.ISink) TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) RegexMatcher(edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher) Plan(edu.uci.ics.textdb.api.engine.Plan) KeywordMatcherSourceOperator(edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator) Test(org.junit.Test)

Example 4 with Plan

use of edu.uci.ics.textdb.api.engine.Plan in project textdb by TextDB.

the class PlanTest method setUp.

@Before
public void setUp() {
    root = getSampleSink();
    plan = new Plan(root);
}
Also used : Plan(edu.uci.ics.textdb.api.engine.Plan) Before(org.junit.Before)

Example 5 with Plan

use of edu.uci.ics.textdb.api.engine.Plan in project textdb by TextDB.

the class NewQueryPlanResource method executeQueryPlan.

/**
     * This is the edu.uci.ics.textdb.web.request handler for the execution of a Query Plan.
     * @param logicalPlanJson, the json representation of the logical plan
     * @return - Generic TextdbWebResponse object
     */
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
TextdbWebResponse executeQueryPlan(String logicalPlanJson) {
    try {
        LogicalPlan logicalPlan = new ObjectMapper().readValue(logicalPlanJson, LogicalPlan.class);
        Plan plan = logicalPlan.buildQueryPlan();
        ISink sink = plan.getRoot();
        // send response back to frontend
        if (sink instanceof TupleSink) {
            TupleSink tupleSink = (TupleSink) sink;
            tupleSink.open();
            List<Tuple> results = tupleSink.collectAllTuples();
            tupleSink.close();
            ArrayNode arrayNode = new ObjectMapper().createArrayNode();
            for (Tuple tuple : results) {
                arrayNode.add(tuple.getReadableJson());
            }
            return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(arrayNode));
        } else {
            // execute the plan and return success message
            Engine.getEngine().evaluate(plan);
            ObjectNode objectNode = new ObjectMapper().createObjectNode();
            objectNode.put("status", "plan sucessfully executed");
            return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(objectNode));
        }
    } catch (IOException | RuntimeException e) {
        // TODO remove RuntimeException after the exception refactor
        e.printStackTrace();
        throw new TextdbWebException(e.getMessage());
    }
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TextdbWebResponse(edu.uci.ics.textdb.web.response.TextdbWebResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) Plan(edu.uci.ics.textdb.api.engine.Plan) ISink(edu.uci.ics.textdb.api.dataflow.ISink) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Plan (edu.uci.ics.textdb.api.engine.Plan)6 ISink (edu.uci.ics.textdb.api.dataflow.ISink)5 IOperator (edu.uci.ics.textdb.api.dataflow.IOperator)4 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)4 KeywordMatcherSourceOperator (edu.uci.ics.textdb.exp.keywordmatcher.KeywordMatcherSourceOperator)3 RegexMatcher (edu.uci.ics.textdb.exp.regexmatcher.RegexMatcher)3 Test (org.junit.Test)3 OneToNBroadcastConnector (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector)2 ConnectorOutputOperator (edu.uci.ics.textdb.exp.connector.OneToNBroadcastConnector.ConnectorOutputOperator)2 Join (edu.uci.ics.textdb.exp.join.Join)2 NlpEntityOperator (edu.uci.ics.textdb.exp.nlp.entity.NlpEntityOperator)2 HashSet (java.util.HashSet)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1 FuzzyTokenMatcher (edu.uci.ics.textdb.exp.fuzzytokenmatcher.FuzzyTokenMatcher)1 LogicalPlan (edu.uci.ics.textdb.exp.plangen.LogicalPlan)1 TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)1 TextdbWebResponse (edu.uci.ics.textdb.web.response.TextdbWebResponse)1