Search in sources :

Example 16 with CorrelationIdentifier

use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.

the class TopologicalSortTest method testTopologicalSortSkip.

@Test
public void testTopologicalSortSkip() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final CorrelationIdentifier b = CorrelationIdentifier.of("b");
    final CorrelationIdentifier c = CorrelationIdentifier.of("c");
    final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of();
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
    final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutationIterable.iterator();
    final ImmutableList.Builder<List<CorrelationIdentifier>> builder = ImmutableList.builder();
    while (iterator.hasNext()) {
        final List<CorrelationIdentifier> next = iterator.next();
        builder.add(next);
        if (next.get(0).equals(b) && next.get(1).equals(a)) {
            iterator.skip(0);
        }
    }
    final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = builder.build();
    assertEquals(5, topologicalPermutations.size());
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(b, a, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, a)));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test)

Example 17 with CorrelationIdentifier

use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.

the class TopologicalSortTest method testTopologicalSortFullDependencies.

@Test
public void testTopologicalSortFullDependencies() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final CorrelationIdentifier b = CorrelationIdentifier.of("b");
    final CorrelationIdentifier c = CorrelationIdentifier.of("c");
    final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of(b, ImmutableSet.of(a), c, ImmutableSet.of(b));
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
    final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = ImmutableList.copyOf(topologicalPermutationIterable);
    assertEquals(1, topologicalPermutations.size());
    assertEquals(ImmutableList.of(a, b, c), topologicalPermutations.get(0));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test)

Example 18 with CorrelationIdentifier

use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.

the class TopologicalSortTest method testTopologicalSortSkipComplexError1.

@Test
public void testTopologicalSortSkipComplexError1() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final CorrelationIdentifier b = CorrelationIdentifier.of("b");
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutations = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b), id -> ImmutableSet.of());
    final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutations.iterator();
    Assertions.assertThrows(UnsupportedOperationException.class, () -> iterator.skip(0));
}
Also used : CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) Test(org.junit.jupiter.api.Test)

Example 19 with CorrelationIdentifier

use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.

the class TopologicalSortTest method testTopologicalSortSkip3.

@Test
public void testTopologicalSortSkip3() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final CorrelationIdentifier b = CorrelationIdentifier.of("b");
    final CorrelationIdentifier c = CorrelationIdentifier.of("c");
    final CorrelationIdentifier d = CorrelationIdentifier.of("d");
    final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of();
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c, d), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
    final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutationIterable.iterator();
    final ImmutableList.Builder<List<CorrelationIdentifier>> builder = ImmutableList.builder();
    while (iterator.hasNext()) {
        final List<CorrelationIdentifier> next = iterator.next();
        builder.add(next);
        if (next.get(0).equals(b) && next.get(1).equals(a)) {
            iterator.skip(0);
        }
    }
    final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = builder.build();
    assertEquals(19, topologicalPermutations.size());
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, c, d)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, d, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, b, d)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, d, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, d, b, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(a, d, c, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(b, a, c, d)));
    assertFalse(topologicalPermutations.contains(ImmutableList.of(b, a, d, c)));
    assertFalse(topologicalPermutations.contains(ImmutableList.of(b, c, a, d)));
    assertFalse(topologicalPermutations.contains(ImmutableList.of(b, c, d, a)));
    assertFalse(topologicalPermutations.contains(ImmutableList.of(b, d, a, c)));
    assertFalse(topologicalPermutations.contains(ImmutableList.of(b, d, c, a)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, b, d)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, d, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, a, d)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, d, a)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, d, a, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(c, d, b, a)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, a, b, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, a, c, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, b, a, c)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, b, c, a)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, c, a, b)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(d, c, b, a)));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test)

Example 20 with CorrelationIdentifier

use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.

the class TopologicalSortTest method testTopologicalSortSkipComplexError2.

@Test
public void testTopologicalSortSkipComplexError2() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final CorrelationIdentifier b = CorrelationIdentifier.of("b");
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutations = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b), id -> ImmutableSet.of());
    final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutations.iterator();
    iterator.next();
    Assertions.assertThrows(IndexOutOfBoundsException.class, () -> iterator.skip(2));
}
Also used : CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

CorrelationIdentifier (com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier)31 Set (java.util.Set)19 ImmutableSet (com.google.common.collect.ImmutableSet)18 Test (org.junit.jupiter.api.Test)17 List (java.util.List)15 ImmutableList (com.google.common.collect.ImmutableList)14 Nonnull (javax.annotation.Nonnull)11 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)10 API (com.apple.foundationdb.annotation.API)8 AliasMap (com.apple.foundationdb.record.query.plan.temp.AliasMap)8 Value (com.apple.foundationdb.record.query.predicates.Value)7 GroupExpressionRef (com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef)5 MatchInfo (com.apple.foundationdb.record.query.plan.temp.MatchInfo)5 PartialMatch (com.apple.foundationdb.record.query.plan.temp.PartialMatch)5 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)5 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)5 Verify (com.google.common.base.Verify)5 Optional (java.util.Optional)5 RecordQueryFetchFromPartialRecordPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryFetchFromPartialRecordPlan)4 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)4