Skip to content

Commit c68b0e0

Browse files
committed
more agg queriers work
1 parent 9458645 commit c68b0e0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/combinatorics/EnumeratingIterable.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ static <T> EnumeratingIterable<T> singleIterable(@Nonnull final T singleElement)
4444
return new SingleIterable<>(singleElement);
4545
}
4646

47+
static <T> EnumeratingIterable<T> emptyOnEmptyIterable() {
48+
return new SingleIterable<>();
49+
}
50+
4751
/**
4852
* An implementation of {@link EnumeratingIterable} that is optimized to work for empty
4953
* input sets.
@@ -84,13 +88,17 @@ public EnumeratingIterator<T> iterator() {
8488
* @param <T> type
8589
*/
8690
class SingleIterable<T> implements EnumeratingIterable<T> {
87-
@Nonnull
91+
@Nullable
8892
private final T singleElement;
8993

9094
private SingleIterable(@Nonnull final T singleElement) {
9195
this.singleElement = singleElement;
9296
}
9397

98+
private SingleIterable() {
99+
this.singleElement = null;
100+
}
101+
94102
@Nonnull
95103
@Override
96104
public EnumeratingIterator<T> iterator() {
@@ -103,12 +111,12 @@ public EnumeratingIterator<T> iterator() {
103111
* @param <T> type of the element
104112
*/
105113
class SingleIterator<T> extends AbstractIterator<List<T>> implements EnumeratingIterator<T> {
106-
@Nonnull
114+
@Nullable
107115
private final T singleElement;
108116

109117
boolean atFirst = true;
110118

111-
private SingleIterator(@Nonnull final T singleElement) {
119+
private SingleIterator(@Nullable final T singleElement) {
112120
this.singleElement = singleElement;
113121
}
114122

@@ -128,6 +136,9 @@ protected List<T> computeNext() {
128136

129137
atFirst = false;
130138

139+
if (singleElement == null) {
140+
return ImmutableList.of();
141+
}
131142
return ImmutableList.of(singleElement);
132143
}
133144
}

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/combinatorics/TopologicalSort.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ public static <T, P> Iterable<List<T>> satisfyingPermutations(@Nonnull final Par
537537
@Nonnull final List<P> targetPermutation,
538538
@Nonnull final Function<T, P> domainMapper,
539539
@Nonnull final Function<List<T>, Integer> satisfiabilityFunction) {
540-
if (partiallyOrderedSet.isEmpty()) {
541-
return ImmutableList.of();
542-
}
540+
// if (partiallyOrderedSet.isEmpty()) {
541+
// return ImmutableList.of();
542+
// }
543543

544544
if (partiallyOrderedSet.size() < targetPermutation.size()) {
545545
return ImmutableList.of();
@@ -565,9 +565,11 @@ protected Iterator<T> domain(final int t) {
565565
}
566566
}
567567
};
568-
} else {
569-
Verify.verify(partiallyOrderedSet.size() == 1);
568+
} else if (partiallyOrderedSet.size() == 1) {
570569
enumeratingIterator = EnumeratingIterable.singleIterable(Iterables.getOnlyElement(partiallyOrderedSet.getSet())).iterator();
570+
} else {
571+
Verify.verify(partiallyOrderedSet.isEmpty());
572+
enumeratingIterator = EnumeratingIterable.<T>emptyOnEmptyIterable().iterator();
571573
}
572574

573575
return () -> new AbstractIterator<>() {

0 commit comments

Comments
 (0)