mihaibudiu commented on code in PR #5235:
URL: https://github.com/apache/calcite/pull/5235#discussion_r4000379017
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdFunctionalDependency.java:
##########
@@ -419,6 +422,41 @@ private ArrowSet getJoinFD(Join rel, RelMetadataQuery mq) {
}
}
+ /**
+ * Copies input dependencies into a join, optionally filtering dependencies
Review Comment:
I don't understand this javadoc. Can you please say what each parameter is
and what the function actually computes? There's no "join" to be seen of here.
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdFunctionalDependency.java:
##########
@@ -428,50 +466,93 @@ private ArrowSet getCalcFD(Calc rel, RelMetadataQuery mq)
{
}
/**
- * Shifts column indices in functional dependencies (for right table in
Joins).
- *
- * @param fdSet Functional dependency set
- * @param offset Index offset
- * @return Shifted functional dependency set
+ * Adds functional dependencies implied by a join condition.
Review Comment:
where does it add the dependencies?
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdFunctionalDependency.java:
##########
@@ -419,6 +422,41 @@ private ArrowSet getJoinFD(Join rel, RelMetadataQuery mq) {
}
}
+ /**
+ * Copies input dependencies into a join, optionally filtering dependencies
+ * that can be invalidated when the input is null-generated.
+ */
+ private static void addJoinInputFDs(ArrowSet inputFdSet, RelNode input,
+ int offset, boolean nullGenerated, ArrowSet.Builder fdBuilder) {
+ for (Arrow inputFd : inputFdSet.getArrows()) {
+ if (nullGenerated && !hasNonNullableDeterminant(inputFd, input)) {
+ continue;
+ }
+ fdBuilder.addArrow(inputFd.getDeterminants().shift(offset),
+ inputFd.getDependents().shift(offset));
+ }
+ }
+
+ /**
+ * Returns whether a dependency's determinant contains a non-nullable input
+ * field. Such a determinant cannot collide with the all-NULL determinant of
Review Comment:
why does this comment mention a LEFT JOIN? There is no left join here.
Please make the comment describe this function does.
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdFunctionalDependency.java:
##########
@@ -428,50 +466,93 @@ private ArrowSet getCalcFD(Calc rel, RelMetadataQuery mq)
{
}
/**
- * Shifts column indices in functional dependencies (for right table in
Joins).
- *
- * @param fdSet Functional dependency set
- * @param offset Index offset
- * @return Shifted functional dependency set
+ * Adds functional dependencies implied by a join condition.
*/
- private ArrowSet shiftFdSet(ArrowSet fdSet, int offset) {
- ArrowSet.Builder shiftedFdSetBuilder = new ArrowSet.Builder();
- for (Arrow fd : fdSet.getArrows()) {
- ImmutableBitSet shiftedDeterminants = fd.getDeterminants().shift(offset);
- ImmutableBitSet shiftedDependents = fd.getDependents().shift(offset);
- shiftedFdSetBuilder.addArrow(shiftedDeterminants, shiftedDependents);
+ private static void addFDsFromJoinCondition(Join rel, int leftFieldCount,
+ ArrowSet.Builder builder) {
+ final JoinRelType joinType = rel.getJoinType();
+ if (joinType == JoinRelType.INNER) {
+ addBidirectionalFDsFromEqualityCondition(rel.getCondition(), builder);
+ return;
}
- return shiftedFdSetBuilder.build();
+
+ if (joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT) {
+ final JoinInfo joinInfo = rel.analyzeCondition();
+ if (!joinInfo.isEqui() || joinInfo.leftKeys.isEmpty()
+ || !fieldsSupportEqualityInference(rel.getLeft(), joinInfo.leftSet())
+ || !fieldsSupportEqualityInference(rel.getRight(),
joinInfo.rightSet())) {
+ return;
+ }
+
+ final ImmutableBitSet leftKeys = joinInfo.leftSet();
+ final ImmutableBitSet rightKeys =
joinInfo.rightSet().shift(leftFieldCount);
+ if (joinType == JoinRelType.LEFT) {
+ builder.addArrow(leftKeys, rightKeys);
+ } else {
+ builder.addArrow(rightKeys, leftKeys);
+ }
+ return;
+ }
+
+ throw new AssertionError("unsupported join type: " + joinType);
}
/**
- * Extracts functional dependencies from equality and AND conditions.
- * Handles col1 = col2, col1 IS NOT DISTINCT FROM col2, and AND conditions.
+ * Adds bidirectional dependencies for input-reference equalities in a
+ * condition. Callers are responsible for ensuring that every output row
Review Comment:
every output row of what?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]