@Test public void overlappingFilterIndex() { String q5 = "" + "SELECT ?s ?t " + "{" + " ?s a \"Person\" ." + " ?t a \"Student\" ." + "}"; String q4 = "" + "SELECT ?s ?t " + "{" + " ?s a ?t ." + " ?s <uri:talksTo> ?t . " + "}"; String q3 = "" + "SELECT ?s ?t " + "{" + " Filter(?s > 5). " + " ?s a ?t ." + " ?s <uri:talksTo> ?t . " + "}"; String q2 = "" + "SELECT ?s ?t " + "{" + " Filter(?s > 5). " + " ?s a \"Person\" ." + " ?t a \"Student\" ." + "}"; String q1 = "" + "SELECT ?s ?t " + "{" + " Filter(?s > 5). " + " ?s a ?t ." + " ?s <uri:talksTo> ?t . " + " ?s a \"Person\" ." + " ?t a \"Student\" ." + "}"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; ParsedQuery pq2 = null; ParsedQuery pq3 = null; ParsedQuery pq4 = null; ParsedQuery pq5 = null; try { pq1 = parser.parseQuery(q1, null); pq2 = parser.parseQuery(q2, null); pq3 = parser.parseQuery(q3, null); pq4 = parser.parseQuery(q4, null); pq5 = parser.parseQuery(q5, null); } catch (Exception e) { e.printStackTrace(); } SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet( (Projection) pq2.getTupleExpr()); SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet( (Projection) pq3.getTupleExpr()); SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet( (Projection) pq4.getTupleExpr()); SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet( (Projection) pq5.getTupleExpr()); List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); list.add(extTup2); list.add(extTup1); list.add(extTup3); list.add(extTup4); IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator( pq1.getTupleExpr(), list); List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); Assert.assertEquals(4, indexSet.size()); ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator( pq1.getTupleExpr()); Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists .newArrayList(indexSet)); int size = 0; while (eSet.hasNext()) { size++; Assert.assertTrue(eSet.hasNext()); List<ExternalTupleSet> eList = eSet.next(); } Assert.assertTrue(!eSet.hasNext()); Assert.assertEquals(7, size); }
public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException( "Cannot delete from iterator!"); } }; }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException( "Cannot delete from iterator!"); } }; } }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException( "Cannot delete from iterator!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException( "Cannot delete from iterator!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); Iterator<List<ExternalTupleSet>> getValidIndexCombos(
			List<ExternalTupleSet> indexSet); }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException( "Cannot delete from iterator!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); Iterator<List<ExternalTupleSet>> getValidIndexCombos(
			List<ExternalTupleSet> indexSet);  }