xiedeyantu commented on code in PR #4566:
URL: https://github.com/apache/calcite/pull/4566#discussion_r2401190551


##########
core/src/main/java/org/apache/calcite/rel/metadata/BuiltInMetadata.java:
##########
@@ -901,21 +901,70 @@ default RelDataTypeFactory getTypeFactory() {
     }
   }
 
-  /** Metadata about the functional dependency of columns. */
+  /** Metadata about the functional dependency of column ordinals. */
   public interface FunctionalDependency extends Metadata {
     MetadataDef<FunctionalDependency> DEF =
         MetadataDef.of(FunctionalDependency.class, 
FunctionalDependency.Handler.class,
-            BuiltInMethod.FUNCTIONAL_DEPENDENCY.method);
+            BuiltInMethod.FUNCTIONAL_DEPENDENCY.method,
+            BuiltInMethod.FUNCTIONAL_DEPENDENCY_SET.method,
+            BuiltInMethod.FUNCTIONAL_DEPENDENCY_CLOSURE.method,
+            
BuiltInMethod.FUNCTIONAL_DEPENDENCY_CANDIDATE_KEYS_OR_SUPER_KEYS.method);
 
     /**
-     * Returns whether column is functionally dependent on column.
+     * Returns whether column ordinal {@code determinant} functionally 
determines
+     * column ordinal {@code dependent}.
+     *
+     * @param determinant 0-based ordinal of determinant column
+     * @param dependent 0-based ordinal of dependent column
+     * @return {@code true} if determinant uniquely determines dependent;
+     *         {@code false} if not;
+     *         {@code null} if unknown
      */
-    @Nullable Boolean determines(int key, int column);
+    @Nullable Boolean determines(int determinant, int dependent);
+
+    /**
+     * Returns whether column ordinals in {@code determinants} functionally 
determine
+     * column ordinals in {@code dependents}.
+     *
+     * @param determinants 0-based ordinals of determinant columns
+     * @param dependents 0-based ordinals of dependent columns
+     * @return true if determinants uniquely determine dependents
+     */
+    Boolean determinesSet(ImmutableBitSet determinants, ImmutableBitSet 
dependents);
+
+    /**
+     * Returns the closure of {@code ordinals} under the functional dependency 
set.
+     * The closure is the set of column ordinals uniquely determined by {@code 
ordinals}.
+     *
+     * @param ordinals 0-based ordinals of determinant columns
+     * @return closure: columns functionally determined by {@code ordinals}
+     */
+    ImmutableBitSet computeClosure(ImmutableBitSet ordinals);
+
+    /**
+     * Finds candidate keys or superkeys in {@code ordinals} under the 
functional dependency set.

Review Comment:
   > If a table contains duplicates then NOTHING we know about functional 
dependencies will allow us to deduce keys. (To fix this, you could introduce a 
special attribute that represents row-identity.)
   
   I think this point can be interpreted more broadly. As long as a value in 
col1 can uniquely determine a value in col2, we should consider that col1 → 
col2 holds.
   For example:
   ((1, 'a'), (1, 'a'), (2, 'b')) as (col1, col2)
   In this case, I believe this dependency is acceptable:
   Value 1 in col1 always determines value 'a' in col2
   Value 2 in col1 always determines value 'b' in col2
   Therefore, the functional dependency col1 → col2 should be considered valid.



-- 
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]

Reply via email to