Skip to content

Commit ad4b04f

Browse files
committed
adding tests
1 parent d5b001d commit ad4b04f

File tree

7 files changed

+440
-9
lines changed

7 files changed

+440
-9
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/AggregateIndexExpansionVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ protected NonnullPair<Quantifier, List<Placeholder>> constructGroupBy(@Nonnull f
250250
throw new RecordCoreException("unable to plan group by with non-field value")
251251
.addLogInfo(LogMessageKeys.VALUE, groupedValue);
252252
}
253-
final var aggregateValue = (Value)aggregateMap.get().get(index.getType()).encapsulate(ImmutableList.of(argument));
253+
final var aggregateValue =
254+
aggregateValue(index, argument).orElseThrow(() -> new RecordCoreException("unknown aggregation type"));
254255
// add an RCV column representing the grouping columns as the first result set column
255256
// also, make sure to set the field type names correctly for each field value in the grouping keys RCV.
256257

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/Compensation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public RelationalExpression applyFinal(@Nonnull final Memoizer memoizer,
162162
@Nonnull Function<CorrelationIdentifier, TranslationMap> matchedToRealizedTranslationMapFunction) {
163163
throw new RecordCoreException("this method should not be called");
164164
}
165+
166+
@Override
167+
public String toString() {
168+
return "no-compensation";
169+
}
165170
};
166171

167172
/**
@@ -369,7 +374,7 @@ default Compensation intersect(@Nonnull Compensation otherCompensation) {
369374
@Override
370375
public RelationalExpression apply(@Nonnull final Memoizer memoizer,
371376
@Nonnull final RelationalExpression relationalExpression,
372-
@Nonnull Function<CorrelationIdentifier, TranslationMap> matchedToRealizedTranslationMapFunction) {
377+
@Nonnull final Function<CorrelationIdentifier, TranslationMap> matchedToRealizedTranslationMapFunction) {
373378
return Compensation.this.apply(memoizer,
374379
otherCompensation.apply(memoizer, relationalExpression,
375380
matchedToRealizedTranslationMapFunction), matchedToRealizedTranslationMapFunction);
@@ -379,7 +384,7 @@ public RelationalExpression apply(@Nonnull final Memoizer memoizer,
379384
@Override
380385
public RelationalExpression applyFinal(@Nonnull final Memoizer memoizer,
381386
@Nonnull final RelationalExpression relationalExpression,
382-
@Nonnull Function<CorrelationIdentifier, TranslationMap> matchedToRealizedTranslationMapFunction) {
387+
@Nonnull final Function<CorrelationIdentifier, TranslationMap> matchedToRealizedTranslationMapFunction) {
383388
return Compensation.this.applyFinal(memoizer,
384389
otherCompensation.applyFinal(memoizer, relationalExpression,
385390
matchedToRealizedTranslationMapFunction), matchedToRealizedTranslationMapFunction);

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/Memoizer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ public Reference reference() {
198198
}
199199
};
200200
}
201+
202+
@Override
203+
public String toString() {
204+
return "no-memo";
205+
}
201206
};
202207
}
203208

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/PartialMatch.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,6 @@ public Map<QueryPredicate, PredicateMapping> getPulledUpPredicateMappings(@Nonnu
368368
return resultMap;
369369
}
370370

371-
@Nonnull
372-
public Compensation compensateCompleteMatch(@Nonnull final CorrelationIdentifier candidateTopAlias) {
373-
return compensateCompleteMatch(null, candidateTopAlias);
374-
}
375-
376371
@Nonnull
377372
public Compensation compensateCompleteMatch(@Nullable PullUp unificationPullUp,
378373
@Nonnull final CorrelationIdentifier candidateTopAlias) {

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/expressions/GroupByExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public Message toProto(@Nonnull final PlanSerializationContext serializationCont
767767
@Override
768768
public Value withChildren(final Iterable<? extends Value> newChildren) {
769769
Verify.verify(Iterables.isEmpty(newChildren));
770-
return new UnmatchedAggregateValue(getUnmatchedId());
770+
return this;
771771
}
772772

773773
@Nonnull

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/query/AggregateValueTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
package com.apple.foundationdb.record.provider.foundationdb.query;
2222

23+
import com.apple.foundationdb.record.PlanSerializationContext;
2324
import com.apple.foundationdb.record.RecordCoreArgumentException;
25+
import com.apple.foundationdb.record.query.plan.cascades.CorrelationIdentifier;
26+
import com.apple.foundationdb.record.query.plan.cascades.expressions.GroupByExpression;
2427
import com.apple.foundationdb.record.query.plan.cascades.typing.TypeRepository;
2528
import com.apple.foundationdb.record.query.plan.cascades.values.AggregateValue;
2629
import com.apple.foundationdb.record.query.plan.cascades.values.CountValue;
@@ -42,6 +45,7 @@
4245
import java.util.List;
4346
import java.util.function.Consumer;
4447

48+
import static com.apple.foundationdb.record.PlanHashable.CURRENT_FOR_CONTINUATION;
4549
import static com.apple.foundationdb.record.query.plan.cascades.values.LiteralValue.ofScalar;
4650

4751
/**
@@ -239,6 +243,18 @@ void testTupleSumCount() {
239243
});
240244
}
241245

246+
@Test
247+
void testUnmatchedAggregateValueTest() {
248+
final var value = new GroupByExpression.UnmatchedAggregateValue(CorrelationIdentifier.of("a"));
249+
Assertions.assertEquals("unmatched(a)", value.toString());
250+
251+
final var serializationContext = PlanSerializationContext.newForCurrentMode();
252+
Assertions.assertThrows(UnsupportedOperationException.class, () -> value.toValueProto(serializationContext));
253+
Assertions.assertThrows(UnsupportedOperationException.class, () -> value.planHash(CURRENT_FOR_CONTINUATION));
254+
Assertions.assertThrows(UnsupportedOperationException.class, () -> value.toProto(serializationContext));
255+
Assertions.assertEquals(value, value.withChildren(ImmutableList.of()));
256+
}
257+
242258
@Nullable
243259
public static List<Long> collectOnBits(@Nullable byte[] bitmap, int expectedArrayLength) {
244260
if (bitmap == null) {

0 commit comments

Comments
 (0)