LogicalPlan { public Plan buildQueryPlan() throws PlanGenException { buildOperators(); validateOperatorGraph(); connectOperators(operatorObjectMap); HashMap<String, ISink> sinkMap = findSinkOperators(operatorObjectMap); return new Plan(sinkMap); } LogicalPlan(); @JsonCreator  LogicalPlan(
            @JsonProperty(value = PropertyNameConstants.OPERATOR_LIST, required = true)
            List<PredicateBase> predicateList,
            @JsonProperty(value = PropertyNameConstants.OPERATOR_LINK_LIST, required = true)
            List<OperatorLink> operatorLinkList
            ); @JsonIgnore QueryContext getContext(); @JsonIgnore void setContext(QueryContext context); @JsonProperty(value = PropertyNameConstants.OPERATOR_LIST) List<PredicateBase> getPredicateList(); @JsonProperty(value = PropertyNameConstants.OPERATOR_LINK_LIST) List<OperatorLink> getOperatorLinkList(); Schema getOperatorOutputSchema(String operatorID); Optional<Schema> getOperatorOutputSchema(String operatorID, Map<String, List<Schema>> operatorInputSchemaMap); Map<String, List<Schema>> retrieveAllOperatorInputSchema(); void addOperator(PredicateBase operatorPredicate); void addLink(OperatorLink operatorLink); boolean hasOperator(String operatorID); Plan buildQueryPlan(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testLogicalPlan1() throws Exception { LogicalPlan logicalPlan = getLogicalPlan1(); Plan queryPlan = logicalPlan.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.assertTrue(tupleSink instanceof TupleSink); IOperator regexMatcher = ((TupleSink) tupleSink).getInputOperator(); Assert.assertTrue(regexMatcher instanceof RegexMatcher); IOperator keywordSource = ((RegexMatcher) regexMatcher).getInputOperator(); Assert.assertTrue(keywordSource instanceof KeywordMatcherSourceOperator); }
@Test public void testLogicalPlan2() throws Exception { LogicalPlan logicalPlan = getLogicalPlan2(); Plan queryPlan = logicalPlan.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.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); }
@Test public void testLogicalPlan3() throws Exception { LogicalPlan logicalPlan = getLogicalPlan3(); Plan queryPlan = logicalPlan.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.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); }