Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,18 @@
*/
@Nonnull
private static Quantifier.ForEach constituentQuantifier(@Nonnull final Value ownerElementValue,
@Nonnull final KeyExpression nestingExpression) {

Check notice on line 416 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/metadata/UnnestedRecordType.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 97.4% (111/114 lines) | Changed lines: 100.0% (5/5 lines)
//
// The owner of a constituent nested in another constituent is a field of that constituent's struct. Fuse the
// path to the array into that field rather than accessing it on top of it, so that the collection is the same
// value a query navigating the same unnestings explodes, and the two explodes can be matched.
//
Value collectionValue = ownerElementValue;
for (final String fieldName : arrayFieldPath(nestingExpression)) {
collectionValue = FieldValue.ofFieldNameAndFuseIfPossible(collectionValue, fieldName);
}
final Quantifier.ForEach explodeQuantifier =
Quantifier.forEach(Reference.initialOf(new TableFunctionExpression(new ExplodeValue(
FieldValue.ofFieldNames(ownerElementValue, arrayFieldPath(nestingExpression)), true))));
Quantifier.forEach(Reference.initialOf(new TableFunctionExpression(new ExplodeValue(collectionValue, true))));
return Quantifier.forEach(Reference.initialOf(GraphExpansion.ofQuantifier(explodeQuantifier)
.seal()
.buildSimpleSelectOverQuantifier(explodeQuantifier)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@
*
* <p>The key's values are written over {@code baseQuantifier}, which does not survive into the merged graph, so
* each is re-expressed over the record the base expansion assembles and simplified:
* {@code base.unnesting_0.reviewer} over {@code (parent AS parent, explode._0 AS unnesting_0, ...)} becomes

Check notice on line 101 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/ValueIndexExpansionVisitor.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 99.2% (124/125 lines) | Changed lines: 100.0% (5/5 lines)
* {@code explode._0.reviewer}, the very value a query navigating the same unnesting flows.
* {@code explode._0.reviewer}, the very value a query navigating the same unnesting flows. The same holds for the
* graphs the key's quantifiers range over: the explode of a scalar array fanned out in the key, such as
* {@code explode(base.parent.labels)}, becomes {@code explode(parent.labels)}, the explode a query writes.
*
* <p>Predicates and placeholders are translated separately because a placeholder is held in both lists and
* {@link GraphExpansion#seal()} pairs them up by value; translating one alone would leave a parameter whose
Expand All @@ -124,6 +126,11 @@
return GraphExpansion.ofOthers(
baseExpansion.toBuilder().removeAllResultColumns().build(),
keyExpansion.toBuilder()
.removeAllQuantifiers()
.addAllQuantifiers(keyExpansion.getQuantifiers().stream()
.map(quantifier -> quantifier.overNewReference(quantifier.getRangesOver()
.translateGraph(Memoizer.noMemoization(PlannerStage.INITIAL), ontoBaseRecord, true)))
.collect(ImmutableList.toImmutableList()))
.removeAllPredicates()
.addAllPredicates(keyExpansion.getPredicates().stream()
.map(predicate -> predicate.translateCorrelations(ontoBaseRecord, true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ void expandChainsNestedConstituentsOntoTheirOwner() {
assertEquals(FieldValue.ofFieldNames(parentQuantifier.getFlowedObjectValue(), List.of("inner")),
assertSelectOverExplode(expansion.getQuantifiers().get(3)).getCollectionValue());

// ... while `inner` hangs off the element `middle` flows, which is what makes this a chain rather than a fan.
// ... while `inner` hangs off the element `middle` flows, which is what makes this a chain rather than a fan. The
// path to the array is fused into the access of that element, as a query over the same unnestings writes it.
final Value innerCollectionValue = assertSelectOverExplode(expansion.getQuantifiers().get(2))
.getCollectionValue();
assertEquals(FieldValue.ofFieldNames(
FieldValue.ofOrdinalNumber(middleQuantifier.getFlowedObjectValue(), 0), List.of("inner")),
assertEquals(FieldValue.ofFieldNameAndFuseIfPossible(
FieldValue.ofOrdinalNumber(middleQuantifier.getFlowedObjectValue(), 0), "inner"),
innerCollectionValue);
assertEquals(middleQuantifier.getAlias(), Iterables.getOnlyElement(innerCollectionValue.getCorrelatedTo()));

Expand Down
Binary file not shown.
Loading
Loading