IndexedQueryPlanner { public QueryStrategy plan(OperatorNode<ExpressionOperator> filter) { return planInternal(ImmutableSet.<String>of(), filter, false); } IndexedQueryPlanner(Set<IndexKey> indexes);  IndexedQueryPlanner(Iterable<IndexDescriptor> indexes); QueryStrategy planExact(OperatorNode<ExpressionOperator> filter); QueryStrategy plan(OperatorNode<ExpressionOperator> filter); QueryStrategy planJoin(OperatorNode<PhysicalExprOperator> leftSide, OperatorNode<ExpressionOperator> joinExpression, OperatorNode<ExpressionOperator> filter);  }
@Test public void testIndexIdPants3() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); IndexKey PANTS_INDEX = IndexKey.of("id", "pants"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX, PANTS_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' AND pants IN ('2', '3', '4') OR id = '3'")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 2); Collection<IndexStrategy> q = strategy.indexes.get(PANTS_INDEX); Assert.assertEquals(q.size(), 1); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); Assert.assertEquals(strategyKey.indexFilter.get("pants").toString(), "(IN (READ_FIELD L13:1 row, pants), (ARRAY L23:1 [(LITERAL L23:1 2), (LITERAL L28:1 3), (LITERAL L33:1 4)]))"); q = strategy.indexes.get(ID_INDEX); Assert.assertEquals(q.size(), 1); strategyIterator = q.iterator(); strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L41:1 row, id), (LITERAL L46:1 3))"); }
@Test public void testIndexId() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1'")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 1); Collection<IndexStrategy> q = strategy.indexes.get(ID_INDEX); Assert.assertEquals(q.size(), 1); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); }
@Test public void testIndexId2() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' OR id = '2'")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 2); Collection<IndexStrategy> q = strategy.indexes.get(ID_INDEX); Assert.assertEquals(q.size(), 2); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L12:1 row, id), (LITERAL L17:1 2))"); }
@Test public void testIndexIdScan() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' OR pants = '2'")); Assert.assertTrue(strategy.scan); }
@Test public void testIndexIdExtra() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' AND pants = '2'")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 1); Collection<IndexStrategy> q = strategy.indexes.get(ID_INDEX); Assert.assertEquals(q.size(), 1); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertEquals(strategyKey.filter.toString(), "(EQ (READ_FIELD L13:1 row, pants), (LITERAL L21:1 2))"); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); }
@Test public void testIndexIdPants() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); IndexKey PANTS_INDEX = IndexKey.of("id", "pants"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX, PANTS_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' AND pants = '2'")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 1); Collection<IndexStrategy> q = strategy.indexes.get(PANTS_INDEX); Assert.assertEquals(q.size(), 1); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); Assert.assertEquals(strategyKey.indexFilter.get("pants").toString(), "(EQ (READ_FIELD L13:1 row, pants), (LITERAL L21:1 2))"); }
@Test public void testIndexIdPants2() throws Exception { IndexKey ID_INDEX = IndexKey.of("id"); IndexKey PANTS_INDEX = IndexKey.of("id", "pants"); Set<IndexKey> indexKeySet = Sets.newHashSet( ID_INDEX, PANTS_INDEX ); IndexedQueryPlanner planner = new IndexedQueryPlanner(indexKeySet); QueryStrategy strategy = planner.plan(parseFilter("id = '1' AND pants IN ('2', '3', '4')")); Assert.assertFalse(strategy.scan); Assert.assertEquals(strategy.indexes.size(), 1); Collection<IndexStrategy> q = strategy.indexes.get(PANTS_INDEX); Assert.assertEquals(q.size(), 1); Iterator<IndexStrategy> strategyIterator = q.iterator(); IndexStrategy strategyKey = strategyIterator.next(); Assert.assertNull(strategyKey.filter); Assert.assertEquals(strategyKey.indexFilter.get("id").toString(), "(EQ (READ_FIELD L0:1 row, id), (LITERAL L5:1 1))"); Assert.assertEquals(strategyKey.indexFilter.get("pants").toString(), "(IN (READ_FIELD L13:1 row, pants), (ARRAY L23:1 [(LITERAL L23:1 2), (LITERAL L28:1 3), (LITERAL L33:1 4)]))"); }