pnowojski commented on a change in pull request #6299: [FLINK-9713][table][sql] 
Support processing time versioned joins
URL: https://github.com/apache/flink/pull/6299#discussion_r208831842
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/logical/rel/LogicalVersionedJoin.scala
 ##########
 @@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.plan.logical.rel
+
+import java.util.Collections
+
+import org.apache.calcite.plan.{RelOptCluster, RelTraitSet}
+import org.apache.calcite.rel.RelNode
+import org.apache.calcite.rel.core._
+import org.apache.calcite.rex.{RexBuilder, RexNode}
+import org.apache.calcite.sql.`type`.{OperandTypes, ReturnTypes}
+import org.apache.calcite.sql.{SqlFunction, SqlFunctionCategory, SqlKind}
+import org.apache.flink.util.Preconditions.checkArgument
+
+/**
+  * Represents a join between a table and 
[[org.apache.flink.table.functions.TableVersionFunction]]
+  *
+  * @param cluster
+  * @param traitSet
+  * @param left stream
+  * @param right table scan of underlying 
[[org.apache.flink.table.functions.TableVersionFunction]]
+  * @param condition must contain 
[[LogicalVersionedJoin#VERSIONING_JOIN_CONDITION()]] with
+  *                  correctly defined references to rightVersioneExpression,
+  *                  rightPrimaryKeyExpression and leftVersionExpression. We 
can not implement
+  *                  those references as separate fields, because of problems 
with Calcite's
+  *                  optimization rules like projections push downs, column
+  *                  pruning/renaming/reordering, etc. Later 
rightVersioneExpression,
+  *                  rightPrimaryKeyExpression and leftVersionExpression will 
be extracted from
+  *                  the condition.
+  */
+class LogicalVersionedJoin private (
+    cluster: RelOptCluster,
+    traitSet: RelTraitSet,
+    left: RelNode,
+    right: RelNode,
+    condition: RexNode)
+  extends Join(
+    cluster,
+    traitSet,
+    left,
+    right,
+    condition,
+    Collections.emptySet().asInstanceOf[java.util.Set[CorrelationId]],
+    JoinRelType.INNER) {
+
+  override def copy(
+       traitSet: RelTraitSet,
+       condition: RexNode,
+       left: RelNode,
+       right: RelNode,
+       joinType: JoinRelType,
+       semiJoinDone: Boolean): LogicalVersionedJoin = {
+    checkArgument(joinType == this.getJoinType,
+      "Can not change join type".asInstanceOf[Object])
+    checkArgument(semiJoinDone == this.isSemiJoinDone,
+      "Can not change semiJoinDone".asInstanceOf[Object])
+    new LogicalVersionedJoin(
+      cluster,
+      traitSet,
+      left,
+      right,
+      condition)
+  }
+}
+
+object LogicalVersionedJoin {
+  /**
+    * See [[LogicalVersionedJoin#condition]]
+    */
+  val VERSIONING_JOIN_CONDITION = new SqlFunction(
 
 Review comment:
   We want and need to use Calcite's optimisations for joins (like pushing down 
predicate, column pruning, predicate pushdown etc). To enable that, 
`LogicalVersionedJoin` extends calcite's `Join`. However there is no way to 
expand `Join`'s semantic, that beside actual join condition we need some extra 
fields to handle versioning. The only way to do this, is to expose 
`leftVersionExpression`, `rightVersionExpression` and 
`rightPrimaryKeyExpression` via this `VERSIONING_JOIN_CONDITION`. Otherwise, if 
we kept those expressions on some hidden state, they could be 
pruned/renamed/reordered/... .

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


With regards,
Apache Git Services

Reply via email to