Github user wuchong commented on a diff in the pull request:
https://github.com/apache/flink/pull/3715#discussion_r127113760
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/rules/datastream/DataStreamWindowJoinRule.scala
---
@@ -20,28 +20,60 @@ package org.apache.flink.table.plan.rules.datastream
import org.apache.calcite.plan.{RelOptRule, RelOptRuleCall, RelTraitSet}
import org.apache.calcite.rel.RelNode
+import org.apache.calcite.rel.`type`.RelDataType
import org.apache.calcite.rel.convert.ConverterRule
+import org.apache.calcite.rex.RexNode
+import org.apache.flink.table.api.{TableConfig, TableException}
import org.apache.flink.table.plan.nodes.FlinkConventions
-import org.apache.flink.table.plan.nodes.datastream.DataStreamRowStreamJoin
+import org.apache.flink.table.plan.nodes.datastream.DataStreamWindowJoin
import org.apache.flink.table.plan.nodes.logical.FlinkLogicalJoin
import org.apache.flink.table.plan.schema.RowSchema
-import org.apache.flink.table.runtime.join.JoinUtil
+import org.apache.flink.table.runtime.join.WindowJoinUtil
-class DataStreamRowStreamJoinRule
+class DataStreamWindowJoinRule
extends ConverterRule(
classOf[FlinkLogicalJoin],
FlinkConventions.LOGICAL,
FlinkConventions.DATASTREAM,
"DataStreamJoinRule") {
+ /** Time indicator type **/
+ private var timeType: RelDataType = _
+
+ /** left input lower boudary **/
+ private var leftLowerBoundary: Long = _
+
+ /** left input upper boudary **/
+ private var leftUpperBoundary: Long = _
+
+ /** remain join condition exclude equal condition and time condition **/
+ private var remainCondition: Option[RexNode] = _
+
override def matches(call: RelOptRuleCall): Boolean = {
val join: FlinkLogicalJoin = call.rel(0).asInstanceOf[FlinkLogicalJoin]
val joinInfo = join.analyzeCondition
- JoinUtil.isStreamStreamJoin(
- joinInfo.getRemaining(join.getCluster.getRexBuilder),
- join.getRowType)
+ try {
+ val leftRowSchema = new RowSchema(join.getLeft.getRowType)
+
+ val result =
+ WindowJoinUtil.analyzeTimeBoundary(
+ joinInfo.getRemaining(join.getCluster.getRexBuilder),
+ leftRowSchema.logicalType.getFieldCount,
+ leftRowSchema.physicalType.getFieldCount,
+ join.getRowType,
+ join.getCluster.getRexBuilder,
+ TableConfig.DEFAULT)
+ timeType = result._1
+ leftLowerBoundary = result._2
+ leftUpperBoundary = result._3
+ remainCondition = result._4
+ true
--- End diff --
Hi @fhueske , I think a good reason to put the check in `translateToPlan`
is for throwing a proper exception message, such as `Left join is not
supported...`. If we put the check in rule's matches or throw the exception in
rule's matches, it will throw a obscure message with the logical plan.
IMO, a meaningful message is important for users.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---