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());
}
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)));
}
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));
}
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)));
}
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)));
}
Aggregations