swuferhong commented on code in PR #20822:
URL: https://github.com/apache/flink/pull/20822#discussion_r1288332224


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdColumnUniquenessTest.scala:
##########
@@ -54,6 +60,45 @@ class FlinkRelMdColumnUniquenessTest extends 
FlinkRelMdHandlerTestBase {
           idx => assertNull(mq.areColumnsUnique(scan, ImmutableBitSet.of(idx)))
         }
     }
+
+    // Test intermediate table scan.
+    relBuilder.clear()
+    val studentRel = relBuilder
+      .scan("student")
+      .build()
+    val flinkLogicalIntermediateTableScan: FlinkLogicalIntermediateTableScan =
+      createIntermediateScan(
+        studentRel,
+        flinkLogicalTraits,
+        Set(ImmutableBitSet.of(0)),
+        new FlinkStatistic(new TableStats(1000L), 
Set(Set("name").asJava).asJava))
+    val batchPhysicalIntermediateTableScan: BatchPhysicalIntermediateTableScan 
=
+      createIntermediateScan(
+        studentRel,
+        batchPhysicalTraits,
+        Set(ImmutableBitSet.of(0)),
+        new FlinkStatistic(new TableStats(1000L), 
Set(Set("name").asJava).asJava))
+    val streamPhysicalIntermediateTableScan: 
StreamPhysicalIntermediateTableScan =
+      createIntermediateScan(
+        studentRel,
+        streamPhysicalTraits,
+        Set(ImmutableBitSet.of(0)),
+        new FlinkStatistic(new TableStats(1000L), 
Set(Set("name").asJava).asJava))
+    Array(
+      flinkLogicalIntermediateTableScan,
+      batchPhysicalIntermediateTableScan,
+      streamPhysicalIntermediateTableScan).foreach {
+      scan =>
+        assertFalse(mq.areColumnsUnique(scan, ImmutableBitSet.of()))
+        assertTrue(mq.areColumnsUnique(scan, ImmutableBitSet.of(0)))

Review Comment:
   > It's very strange. If the intermediate table has the upsert key, I think 
we should respect this.
   > 
   > In this case, if you treat the column `name` as the upsert keys, I think 
`id` should not be unique. For example, the intermediate table represents the 
query
   > 
   > ```
   > SELECT 1 AS id, name FROM STUDENTS GROUP BY name
   > ```
   > 
   > In this case, I think we can not have the promise.
   
   I agree with you. We need not to override 
`FlinkPreparingTableBase.getKeys()`.



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