@Test public void writeQueriesForJoin1() throws Exception { CompositeMetadata umd = getCmd("U", projection("[{'field':'legalEntities.*.legalEntity'}]")); CompositeMetadata lmd = umd.getChildMetadata(new Path("legalEntities.*.legalEntity")); QueryPlanChooser chooser = new QueryPlanChooser(umd, new First(), new SimpleScorer(), query("{'field':'_id','op':'=','rvalue':1}"), null); QueryPlan qp = chooser.choose(); qp.flip(qp.getNode(umd), qp.getNode(lmd)); ExecutionBlock ublock = new ExecutionBlock(umd, qp.getNode(umd)); ExecutionBlock lblock = new ExecutionBlock(umd, qp.getNode(lmd)); QueryPlanData data = qp.getEdgeData(qp.getNode(umd), qp.getNode(lmd)); AssociationQuery a1 = new AssociationQuery(umd, umd, data.getReference(), data.getConjuncts()); ublock.setAssociationQuery(lblock, a1); ublock.addSourceBlock(lblock); ublock.linkBlocks(); lblock.linkBlocks(); ArrayList<ResultDocument> l = new ArrayList<>(); l.add(resultDoc(lblock, "{'_id':1,'name':'a'}")); JoinTuple tuple = new JoinTuple(null, null, l); List<QueryExpression> queries = Searches.writeQueriesForJoinTuple(tuple, ublock); System.out.println(queries); Assert.assertEquals(1, queries.size()); JSONAssert.assertEquals("{field:legalEntities.*.legalEntityId,op:$eq,rvalue:1}", queries.get(0).toString(), false); }
public static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock) { LOGGER.debug("writeQueriesForJoinTuples tuple:{}, child:{}", tuple, childBlock); Tuples<BindQuery> btuples = new Tuples<>(); if (tuple.getParentDocument() != null) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(tuple.getParentDocument().getBlock()); BindQuery parentb = tuple.getParentDocument().getBindersForSlot(tuple.getParentDocumentSlot(), aq); List<BindQuery> l = new ArrayList<>(1); l.add(parentb); btuples.add(l); } if (tuple.getChildTuple() != null) { for (ResultDocument childDoc : tuple.getChildTuple()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(childDoc.getBlock()); List<BindQuery> binders = childDoc.getBindersForParent(aq); btuples.add(binders); } } List<QueryExpression> queries = new ArrayList<>(); for (ExecutionBlock sourceBlock : tuple.getBlocks()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(sourceBlock); if (aq.getQuery() != null) { queries.add(aq.getQuery()); } } QueryExpression query = and(queries); ArrayList<QueryExpression> ret = new ArrayList<>(); if (query != null) { for (Iterator<List<BindQuery>> itr = btuples.tuples(); itr.hasNext();) { List<BindQuery> binders = itr.next(); BindQuery allBinders = BindQuery.combine(binders); ret.add(allBinders.iterate(query)); } } LOGGER.debug("queries={}", ret); return ret; }
Searches { public static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock) { LOGGER.debug("writeQueriesForJoinTuples tuple:{}, child:{}", tuple, childBlock); Tuples<BindQuery> btuples = new Tuples<>(); if (tuple.getParentDocument() != null) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(tuple.getParentDocument().getBlock()); BindQuery parentb = tuple.getParentDocument().getBindersForSlot(tuple.getParentDocumentSlot(), aq); List<BindQuery> l = new ArrayList<>(1); l.add(parentb); btuples.add(l); } if (tuple.getChildTuple() != null) { for (ResultDocument childDoc : tuple.getChildTuple()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(childDoc.getBlock()); List<BindQuery> binders = childDoc.getBindersForParent(aq); btuples.add(binders); } } List<QueryExpression> queries = new ArrayList<>(); for (ExecutionBlock sourceBlock : tuple.getBlocks()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(sourceBlock); if (aq.getQuery() != null) { queries.add(aq.getQuery()); } } QueryExpression query = and(queries); ArrayList<QueryExpression> ret = new ArrayList<>(); if (query != null) { for (Iterator<List<BindQuery>> itr = btuples.tuples(); itr.hasNext();) { List<BindQuery> binders = itr.next(); BindQuery allBinders = BindQuery.combine(binders); ret.add(allBinders.iterate(query)); } } LOGGER.debug("queries={}", ret); return ret; } }
Searches { public static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock) { LOGGER.debug("writeQueriesForJoinTuples tuple:{}, child:{}", tuple, childBlock); Tuples<BindQuery> btuples = new Tuples<>(); if (tuple.getParentDocument() != null) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(tuple.getParentDocument().getBlock()); BindQuery parentb = tuple.getParentDocument().getBindersForSlot(tuple.getParentDocumentSlot(), aq); List<BindQuery> l = new ArrayList<>(1); l.add(parentb); btuples.add(l); } if (tuple.getChildTuple() != null) { for (ResultDocument childDoc : tuple.getChildTuple()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(childDoc.getBlock()); List<BindQuery> binders = childDoc.getBindersForParent(aq); btuples.add(binders); } } List<QueryExpression> queries = new ArrayList<>(); for (ExecutionBlock sourceBlock : tuple.getBlocks()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(sourceBlock); if (aq.getQuery() != null) { queries.add(aq.getQuery()); } } QueryExpression query = and(queries); ArrayList<QueryExpression> ret = new ArrayList<>(); if (query != null) { for (Iterator<List<BindQuery>> itr = btuples.tuples(); itr.hasNext();) { List<BindQuery> binders = itr.next(); BindQuery allBinders = BindQuery.combine(binders); ret.add(allBinders.iterate(query)); } } LOGGER.debug("queries={}", ret); return ret; } private  Searches(); }
Searches { public static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock) { LOGGER.debug("writeQueriesForJoinTuples tuple:{}, child:{}", tuple, childBlock); Tuples<BindQuery> btuples = new Tuples<>(); if (tuple.getParentDocument() != null) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(tuple.getParentDocument().getBlock()); BindQuery parentb = tuple.getParentDocument().getBindersForSlot(tuple.getParentDocumentSlot(), aq); List<BindQuery> l = new ArrayList<>(1); l.add(parentb); btuples.add(l); } if (tuple.getChildTuple() != null) { for (ResultDocument childDoc : tuple.getChildTuple()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(childDoc.getBlock()); List<BindQuery> binders = childDoc.getBindersForParent(aq); btuples.add(binders); } } List<QueryExpression> queries = new ArrayList<>(); for (ExecutionBlock sourceBlock : tuple.getBlocks()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(sourceBlock); if (aq.getQuery() != null) { queries.add(aq.getQuery()); } } QueryExpression query = and(queries); ArrayList<QueryExpression> ret = new ArrayList<>(); if (query != null) { for (Iterator<List<BindQuery>> itr = btuples.tuples(); itr.hasNext();) { List<BindQuery> binders = itr.next(); BindQuery allBinders = BindQuery.combine(binders); ret.add(allBinders.iterate(query)); } } LOGGER.debug("queries={}", ret); return ret; } private  Searches(); static Map<ChildSlot, QueryExpression> writeChildQueriesFromParentDoc(AssociationQuery aq,
                                                                                 ResultDocument parentDocument); static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock); static QueryExpression and(QueryExpression... q); static QueryExpression and(List<QueryExpression> list); static QueryExpression combine(NaryLogicalOperator op, List<QueryExpression> list); }
Searches { public static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock) { LOGGER.debug("writeQueriesForJoinTuples tuple:{}, child:{}", tuple, childBlock); Tuples<BindQuery> btuples = new Tuples<>(); if (tuple.getParentDocument() != null) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(tuple.getParentDocument().getBlock()); BindQuery parentb = tuple.getParentDocument().getBindersForSlot(tuple.getParentDocumentSlot(), aq); List<BindQuery> l = new ArrayList<>(1); l.add(parentb); btuples.add(l); } if (tuple.getChildTuple() != null) { for (ResultDocument childDoc : tuple.getChildTuple()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(childDoc.getBlock()); List<BindQuery> binders = childDoc.getBindersForParent(aq); btuples.add(binders); } } List<QueryExpression> queries = new ArrayList<>(); for (ExecutionBlock sourceBlock : tuple.getBlocks()) { AssociationQuery aq = childBlock.getAssociationQueryForEdge(sourceBlock); if (aq.getQuery() != null) { queries.add(aq.getQuery()); } } QueryExpression query = and(queries); ArrayList<QueryExpression> ret = new ArrayList<>(); if (query != null) { for (Iterator<List<BindQuery>> itr = btuples.tuples(); itr.hasNext();) { List<BindQuery> binders = itr.next(); BindQuery allBinders = BindQuery.combine(binders); ret.add(allBinders.iterate(query)); } } LOGGER.debug("queries={}", ret); return ret; } private  Searches(); static Map<ChildSlot, QueryExpression> writeChildQueriesFromParentDoc(AssociationQuery aq,
                                                                                 ResultDocument parentDocument); static List<QueryExpression> writeQueriesForJoinTuple(JoinTuple tuple, ExecutionBlock childBlock); static QueryExpression and(QueryExpression... q); static QueryExpression and(List<QueryExpression> list); static QueryExpression combine(NaryLogicalOperator op, List<QueryExpression> list);  }