You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/01/07 10:17:59 UTC

[GitHub] twalthr commented on a change in pull request #7328: [FLINK-11191][table] Check for ambiguous columns in MATCH_RECOGNIZE

twalthr commented on a change in pull request #7328: [FLINK-11191][table] Check for ambiguous columns in MATCH_RECOGNIZE
URL: https://github.com/apache/flink/pull/7328#discussion_r245604784
 
 

 ##########
 File path: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/rules/datastream/DataStreamMatchRule.scala
 ##########
 @@ -91,6 +95,47 @@ class DataStreamMatchRule
     expr.foreach(_.accept(validator))
   }
 
+  private def validateAmbiguousColumns(logicalMatch: FlinkLogicalMatch): Unit = {
+    if (logicalMatch.isAllRows) {
+      throw new TableException("All rows per match mode is not supported yet.")
+    } else {
+      val refNameFinder = new RefNameFinder(logicalMatch.getInput.getRowType)
+      validateAmbiguousColumnsOnRowPerMatch(
+        logicalMatch.getPartitionKeys,
+        logicalMatch.getMeasures.keySet().asScala,
+        logicalMatch.getRowType,
+        refNameFinder)
+    }
+  }
+
+  private def validateAmbiguousColumnsOnRowPerMatch(
+      partitionKeys: JList[RexNode],
+      measuresNames: mutable.Set[String],
+      expectedSchema: RelDataType,
+      refNameFinder: RefNameFinder)
+    : Unit = {
+    val actualSize = partitionKeys.size() + measuresNames.size
+    val expectedSize = expectedSchema.getFieldCount
+    if (actualSize != expectedSize) {
+      //try to find ambiguous column
+
+      val ambigousColumns = partitionKeys.asScala.map(_.accept(refNameFinder))
+        .filter(measuresNames.contains).mkString("{ ", ", ", " }")
+
+      throw new ValidationException(s"Columns ambiguously defined: $ambigousColumns")
+    }
+  }
+
+  class RefNameFinder(inputSchema: RelDataType) extends RexDefaultVisitor[String] {
 
 Review comment:
   declare the class (and the class below) as private

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services