chunweilei commented on a change in pull request #1141: [CALCITE-2914] Improve 
how LatticeSuggester deduces foreign keys
URL: https://github.com/apache/calcite/pull/1141#discussion_r270787328
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/materialize/SqlStatisticProvider.java
 ##########
 @@ -16,16 +16,41 @@
  */
 package org.apache.calcite.materialize;
 
+import org.apache.calcite.plan.RelOptTable;
+
 import java.util.List;
 
 /**
  * Estimates row counts for tables and columns.
  *
  * <p>Unlike {@link LatticeStatisticProvider}, works on raw tables and columns
  * and does not need a {@link Lattice}.
+ *
+ * <p>It uses {@link org.apache.calcite.plan.RelOptTable} because that contains
+ * enough information to generate and execute SQL, while not being tied to a
+ * lattice.
  */
 public interface SqlStatisticProvider {
-  double tableCardinality(List<String> qualifiedTableName);
+  /** Returns an estimate of the number of rows in {@code table}. */
+  double tableCardinality(RelOptTable table);
+
+  /** Returns whether a join is a foreign key; that is, whether every row in
+   * the referencing table is matched by at least one row in the referenced
+   * table.
+   *
+   * <p>For example, {@code isForeignKey(EMP, [DEPTNO], DEPT, [DEPTNO])}
+   * returns true.
+   *
+   * <p>To change "at least one" to "exactly one", you also need to call
+   * {@link #isKey}. */
+  boolean isForeignKey(RelOptTable fromTable, List<Integer> fromColumns,
+      RelOptTable toTable, List<Integer> toColumns);
+
+  /** Returns whether a collection of columns is a unique key.
+   *
+   * <p>For example, {@code isKey(EMP, [DEPTNO]} returns true;
+   * <p>For example, {@code isKey(DEPT, [DEPTNO]} returns false. */
+  boolean isKey(RelOptTable table, List<Integer> columns);
 }
 
 Review comment:
   Got it.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to