Search in sources :

Example 6 with CorrelationIdentifier

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

the class PartialOrderTest method testEligibleSetsNoDependencies.

@Test
void testEligibleSetsNoDependencies() {
    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 var partialOrder = PartialOrder.of(ImmutableSet.of(a, b, c), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
    var eligibleSet = partialOrder.eligibleSet();
    assertEquals(ImmutableSet.of(a, b, c), eligibleSet.eligibleElements());
    eligibleSet = eligibleSet.removeEligibleElements(eligibleSet.eligibleElements());
    assertTrue(eligibleSet.eligibleElements().isEmpty());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) Test(org.junit.jupiter.api.Test)

Example 7 with CorrelationIdentifier

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

the class TopologicalSortTest method testTopologicalSortSomeDependencies.

@Test
public void testTopologicalSortSomeDependencies() {
    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(c, ImmutableSet.of(a));
    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(3, 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)));
}
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 8 with CorrelationIdentifier

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

the class TopologicalSortTest method testTopologicalSortSkipSingleError.

@Test
public void testTopologicalSortSkipSingleError() {
    final CorrelationIdentifier a = CorrelationIdentifier.of("a");
    final EnumeratingIterable<CorrelationIdentifier> topologicalPermutations = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a), 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 9 with CorrelationIdentifier

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

the class TopologicalSortTest method testTopologicalSortNoDependencies.

@Test
public void testTopologicalSortNoDependencies() {
    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 ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = ImmutableList.copyOf(topologicalPermutationIterable);
    assertEquals(6, 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(b, c, a)));
    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) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test)

Example 10 with CorrelationIdentifier

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

the class TopologicalSortTest method testTopologicalSortSkip2.

@Test
public void testTopologicalSortSkip2() {
    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(1);
        }
    }
    final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = builder.build();
    assertEquals(23, 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)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(b, c, a, d)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(b, c, d, a)));
    assertTrue(topologicalPermutations.contains(ImmutableList.of(b, d, a, c)));
    assertTrue(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)

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