wuchong commented on a change in pull request #8629: 
[FLINK-12088][table-runtime-blink] Introduce unbounded streaming 
inner/left/right/full join operator
URL: https://github.com/apache/flink/pull/8629#discussion_r292270945
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecJoin.scala
 ##########
 @@ -123,7 +137,109 @@ class StreamExecJoin(
 
   override protected def translateToPlanInternal(
       tableEnv: StreamTableEnvironment): StreamTransformation[BaseRow] = {
-    throw new TableException("Implements this")
+
+    val tableConfig = tableEnv.getConfig
+    val returnType = FlinkTypeFactory.toInternalRowType(getRowType).toTypeInfo
+
+    val leftTransform = getInputNodes.get(0).translateToPlan(tableEnv)
+      .asInstanceOf[StreamTransformation[BaseRow]]
+    val rightTransform = getInputNodes.get(1).translateToPlan(tableEnv)
+      .asInstanceOf[StreamTransformation[BaseRow]]
+
+    val leftType = leftTransform.getOutputType.asInstanceOf[BaseRowTypeInfo]
+    val rightType = rightTransform.getOutputType.asInstanceOf[BaseRowTypeInfo]
+
+    val (leftJoinKey, rightJoinKey) =
+      JoinUtil.checkAndGetJoinKeys(keyPairs, getLeft, getRight, allowEmptyKey 
= true)
+
+    val leftSelect = KeySelectorUtil.getBaseRowSelector(leftJoinKey, leftType)
+    val rightSelect = KeySelectorUtil.getBaseRowSelector(rightJoinKey, 
rightType)
+
+    val leftInputSpec = analyzeJoinInput(left)
+    val rightInputSpec = analyzeJoinInput(right)
+
+    val generatedCondition = JoinUtil.generateConditionFunction(
+      tableConfig,
+      cluster.getRexBuilder,
+      getJoinInfo,
+      TypeConverters.createInternalTypeFromTypeInfo(leftType),
+      TypeConverters.createInternalTypeFromTypeInfo(rightType))
+
+    if (joinType == JoinRelType.ANTI || joinType == JoinRelType.SEMI) {
+      throw new TableException("SEMI/ANTI Join is not supported yet.")
+    }
+
+    val leftIsOuter = joinType == JoinRelType.LEFT || joinType == 
JoinRelType.FULL
+    val rightIsOuter = joinType == JoinRelType.RIGHT || joinType == 
JoinRelType.FULL
+    val minRetentionTime = tableConfig.getMinIdleStateRetentionTime
+
+    val operator = new StreamingJoinOperator(
+      leftType,
+      rightType,
+      generatedCondition,
+      leftInputSpec,
+      rightInputSpec,
+      leftIsOuter,
+      rightIsOuter,
+      filterNulls,
+      minRetentionTime)
+
+    val ret = new TwoInputTransformation[BaseRow, BaseRow, BaseRow](
+      leftTransform,
+      rightTransform,
+      "Join",
+      operator,
+      returnType,
+      leftTransform.getParallelism)
+
+    if (leftJoinKey.isEmpty) {
+      ret.setParallelism(1)
+      ret.setMaxParallelism(1)
+    }
+
+    // set KeyType and Selector for state
+    ret.setStateKeySelectors(leftSelect, rightSelect)
+    
ret.setStateKeyType(leftSelect.asInstanceOf[ResultTypeQueryable[_]].getProducedType)
+    ret
   }
 
+  private def analyzeJoinInput(input: RelNode): JoinInputSideSpec = {
 
 Review comment:
   `analyzeJoinInput` is a little different with `needsUpdatesAsRetraction`.  
`needsUpdatesAsRetraction` computes unique keys which contains join key, 
however `analyzeJoinInput` computes unique keys which is contained by join key.
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to