You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ja...@apache.org on 2019/06/13 12:51:30 UTC
[flink] branch master updated: [FLINK-12088][table-runtime-blink]
Introduce unbounded streaming inner/left/right/full join operator
This is an automated email from the ASF dual-hosted git repository.
jark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new da6d93c [FLINK-12088][table-runtime-blink] Introduce unbounded streaming inner/left/right/full join operator
da6d93c is described below
commit da6d93cf299125e70e7195068118fa63bc359bf4
Author: Jark Wu <im...@gmail.com>
AuthorDate: Fri May 24 22:00:36 2019 +0800
[FLINK-12088][table-runtime-blink] Introduce unbounded streaming inner/left/right/full join operator
This closes #8629
---
.../physical/batch/BatchExecSortMergeJoin.scala | 7 +-
.../nodes/physical/stream/StreamExecJoin.scala | 138 ++-
.../apache/flink/table/plan/util/JoinUtil.scala | 38 +-
.../apache/flink/table/api/stream/ExplainTest.xml | 200 +++-
.../table/plan/stream/sql/DagOptimizationTest.xml | 24 +-
.../table/plan/stream/sql/SetOperatorsTest.xml | 6 +-
.../flink/table/plan/stream/sql/SinkTest.xml | 4 +-
.../table/plan/stream/sql/SubplanReuseTest.xml | 40 +-
.../table/plan/stream/sql/agg/GroupingSetsTest.xml | 2 +-
.../plan/stream/sql/agg/WindowAggregateTest.xml | 2 +-
.../flink/table/plan/stream/sql/join/JoinTest.xml | 94 +-
.../plan/stream/sql/join/SemiAntiJoinTest.xml | 248 ++---
.../table/plan/stream/sql/join/WindowJoinTest.xml | 4 +-
.../flink/table/api/stream/ExplainTest.scala | 4 +-
.../table/plan/stream/sql/join/JoinTest.scala | 7 -
.../plan/stream/sql/join/WindowJoinTest.scala | 2 +
.../table/runtime/stream/sql/JoinITCase.scala | 1109 ++++++++++++++++++++
.../runtime/join/stream/StreamingJoinOperator.java | 504 +++++++++
.../join/stream/state/JoinInputSideSpec.java | 128 +++
.../join/stream/state/JoinRecordStateView.java | 47 +
.../join/stream/state/JoinRecordStateViews.java | 253 +++++
.../stream/state/OuterJoinRecordStateView.java | 56 +
.../stream/state/OuterJoinRecordStateViews.java | 329 ++++++
23 files changed, 2942 insertions(+), 304 deletions(-)
diff --git a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecSortMergeJoin.scala b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecSortMergeJoin.scala
index e2212b1..4450c09 100644
--- a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecSortMergeJoin.scala
+++ b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/batch/BatchExecSortMergeJoin.scala
@@ -226,7 +226,12 @@ class BatchExecSortMergeJoin(
val keyType = RowType.of(leftAllKey.map(leftType.getChildren.get(_)): _*)
- val condFunc = generateCondition(config, leftType, rightType)
+ val condFunc = JoinUtil.generateConditionFunction(
+ config,
+ cluster.getRexBuilder,
+ getJoinInfo,
+ leftType,
+ rightType)
val externalBufferMemory = config.getConf.getInteger(
TableConfigOptions.SQL_RESOURCE_EXTERNAL_BUFFER_MEM) * NodeResourceConfig.SIZE_IN_MB
diff --git a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecJoin.scala b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecJoin.scala
index 628fd0e..edd4756 100644
--- a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecJoin.scala
+++ b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/nodes/physical/stream/StreamExecJoin.scala
@@ -18,19 +18,23 @@
package org.apache.flink.table.plan.nodes.physical.stream
-import org.apache.flink.streaming.api.transformations.StreamTransformation
-import org.apache.flink.table.api.{StreamTableEnvironment, TableException}
-import org.apache.flink.table.dataformat.BaseRow
-import org.apache.flink.table.plan.nodes.common.CommonPhysicalJoin
-import org.apache.flink.table.plan.nodes.exec.{ExecNode, StreamExecNode}
-import org.apache.flink.table.runtime.join.FlinkJoinType
-
import org.apache.calcite.plan._
import org.apache.calcite.plan.hep.HepRelVertex
-import org.apache.calcite.rel.RelNode
import org.apache.calcite.rel.core.{Join, JoinRelType}
import org.apache.calcite.rel.metadata.RelMetadataQuery
+import org.apache.calcite.rel.{RelNode, RelWriter}
import org.apache.calcite.rex.RexNode
+import org.apache.flink.streaming.api.transformations.{StreamTransformation, TwoInputTransformation}
+import org.apache.flink.table.api.{StreamTableEnvironment, TableException}
+import org.apache.flink.table.calcite.FlinkTypeFactory
+import org.apache.flink.table.dataformat.BaseRow
+import org.apache.flink.table.plan.nodes.common.CommonPhysicalJoin
+import org.apache.flink.table.plan.nodes.exec.{ExecNode, StreamExecNode}
+import org.apache.flink.table.plan.util.{JoinUtil, KeySelectorUtil, RelExplainUtil}
+import org.apache.flink.table.runtime.join.FlinkJoinType
+import org.apache.flink.table.runtime.join.stream.StreamingJoinOperator
+import org.apache.flink.table.runtime.join.stream.state.JoinInputSideSpec
+import org.apache.flink.table.typeutils.BaseRowTypeInfo
import java.util
@@ -104,6 +108,13 @@ class StreamExecJoin(
new StreamExecJoin(cluster, traitSet, left, right, conditionExpr, joinType)
}
+ override def explainTerms(pw: RelWriter): RelWriter = {
+ super
+ .explainTerms(pw)
+ .item("leftInputSpec", analyzeJoinInput(left))
+ .item("rightInputSpec", analyzeJoinInput(right))
+ }
+
override def computeSelfCost(planner: RelOptPlanner, metadata: RelMetadataQuery): RelOptCost = {
val elementRate = 100.0d * 2 // two input stream
planner.getCostFactory.makeCost(elementRate, elementRate, 0)
@@ -123,7 +134,116 @@ class StreamExecJoin(
override protected def translateToPlanInternal(
tableEnv: StreamTableEnvironment): StreamTransformation[BaseRow] = {
- throw new TableException("Implements this")
+
+ val tableConfig = tableEnv.getConfig
+ val returnType = BaseRowTypeInfo.of(FlinkTypeFactory.toLogicalRowType(getRowType))
+
+ 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,
+ leftType.toRowType,
+ rightType.toRowType)
+
+ 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,
+ getJoinOperatorName(),
+ 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.getProducedType)
+ ret
+ }
+
+ private def analyzeJoinInput(input: RelNode): JoinInputSideSpec = {
+ val uniqueKeys = cluster.getMetadataQuery.getUniqueKeys(input)
+ if (uniqueKeys == null || uniqueKeys.isEmpty) {
+ JoinInputSideSpec.withoutUniqueKey()
+ } else {
+ val inRowType = BaseRowTypeInfo.of(FlinkTypeFactory.toLogicalRowType(input.getRowType))
+ val joinKeys = if (input == left) {
+ keyPairs.map(_.source).toArray
+ } else {
+ keyPairs.map(_.target).toArray
+ }
+ val uniqueKeysContainedByJoinKey = uniqueKeys
+ .filter(uk => uk.toArray.forall(joinKeys.contains(_)))
+ .map(_.toArray)
+ .toArray
+ if (uniqueKeysContainedByJoinKey.nonEmpty) {
+ // join key contains unique key
+ val smallestUniqueKey = getSmallestKey(uniqueKeysContainedByJoinKey)
+ val uniqueKeySelector = KeySelectorUtil.getBaseRowSelector(smallestUniqueKey, inRowType)
+ val uniqueKeyTypeInfo = uniqueKeySelector.getProducedType
+ JoinInputSideSpec.withUniqueKeyContainedByJoinKey(uniqueKeyTypeInfo, uniqueKeySelector)
+ } else {
+ val smallestUniqueKey = getSmallestKey(uniqueKeys.map(_.toArray).toArray)
+ val uniqueKeySelector = KeySelectorUtil.getBaseRowSelector(smallestUniqueKey, inRowType)
+ val uniqueKeyTypeInfo = uniqueKeySelector.getProducedType
+ JoinInputSideSpec.withUniqueKey(uniqueKeyTypeInfo, uniqueKeySelector)
+ }
+ }
}
+ private def getSmallestKey(keys: Array[Array[Int]]): Array[Int] = {
+ var smallest = keys.head
+ for (key <- keys) {
+ if (key.length < smallest.length) {
+ smallest = key
+ }
+ }
+ smallest
+ }
+
+ private def getJoinOperatorName(): String = {
+ val where = RelExplainUtil.expressionToString(getCondition, inputRowType, getExpressionString)
+ val select = getRowType.getFieldNames.mkString(", ")
+ s"${flinkJoinType.toString}(where: ($where), select: ($select), " +
+ s"leftInputSpec: ${analyzeJoinInput(left)}, rightInputSpec: ${analyzeJoinInput(right)})"
+ }
}
diff --git a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/util/JoinUtil.scala b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/util/JoinUtil.scala
index a78f20e..479be12 100644
--- a/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/util/JoinUtil.scala
+++ b/flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/plan/util/JoinUtil.scala
@@ -18,14 +18,16 @@
package org.apache.flink.table.plan.util
-import org.apache.flink.table.api.TableException
-
+import org.apache.flink.table.api.{TableConfig, TableException}
+import org.apache.flink.table.codegen.{CodeGeneratorContext, ExprCodeGenerator, FunctionCodeGenerator}
+import org.apache.flink.table.generated.GeneratedJoinCondition
import org.apache.calcite.plan.RelOptUtil
import org.apache.calcite.rel.RelNode
import org.apache.calcite.rel.core.{Join, JoinInfo}
-import org.apache.calcite.rex.RexNode
+import org.apache.calcite.rex.{RexBuilder, RexNode}
import org.apache.calcite.util.ImmutableIntList
import org.apache.calcite.util.mapping.IntPair
+import org.apache.flink.table.types.logical.LogicalType
import java.util
@@ -105,4 +107,34 @@ object JoinUtil {
JoinInfo.of(left, right, condition)
}
}
+
+ def generateConditionFunction(
+ config: TableConfig,
+ rexBuilder: RexBuilder,
+ joinInfo: JoinInfo,
+ leftType: LogicalType,
+ rightType: LogicalType): GeneratedJoinCondition = {
+ val ctx = CodeGeneratorContext(config)
+ // should consider null fields
+ val exprGenerator = new ExprCodeGenerator(ctx, false)
+ .bindInput(leftType)
+ .bindSecondInput(rightType)
+
+ val body = if (joinInfo.isEqui) {
+ // only equality condition
+ "return true;"
+ } else {
+ val nonEquiPredicates = joinInfo.getRemaining(rexBuilder)
+ val condition = exprGenerator.generateExpression(nonEquiPredicates)
+ s"""
+ |${condition.code}
+ |return ${condition.resultTerm};
+ |""".stripMargin
+ }
+
+ FunctionCodeGenerator.generateJoinCondition(
+ ctx,
+ "ConditionFunction",
+ body)
+ }
}
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/api/stream/ExplainTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/api/stream/ExplainTest.xml
index fc4e019..ce22393 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/api/stream/ExplainTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/api/stream/ExplainTest.xml
@@ -216,6 +216,124 @@ Calc(select=[a, b, c], where=[=(MOD(a, 2), 0)], updateAsRetraction=[false], accM
]]>
</Resource>
</TestCase>
+ <TestCase name="testExplainWithJoin[extended=false]">
+ <Resource name="explain">
+ <![CDATA[== Abstract Syntax Tree ==
+LogicalProject(a=[$0], b=[$1], c=[$2], e=[$4], f=[$5])
++- LogicalFilter(condition=[=($0, $3)])
+ +- LogicalJoin(condition=[true], joinType=[inner])
+ :- LogicalTableScan(table=[[MyTable1]])
+ +- LogicalTableScan(table=[[MyTable2]])
+
+== Optimized Logical Plan ==
+Calc(select=[a, b, c, e, f])
++- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
+ :- Exchange(distribution=[hash[a]])
+ : +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c])
+ +- Exchange(distribution=[hash[d]])
+ +- DataStreamScan(table=[[_DataStreamTable_1]], fields=[d, e, f])
+
+== Physical Execution Plan ==
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_0), fields:(a, b, c))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_1), fields:(d, e, f))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : InnerJoin(where: (=(a, d)), select: (a, b, c, d, e, f), leftInputSpec: NoUniqueKey, rightInputSpec: NoUniqueKey)
+ ship_strategy : HASH
+
+ : Operator
+ content : Calc(select: (a, b, c, e, f))
+ ship_strategy : FORWARD
+
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testExplainWithUnion[extended=true]">
+ <Resource name="explain">
+ <![CDATA[== Abstract Syntax Tree ==
+LogicalUnion(all=[true])
+:- LogicalProject(a=[$0], b=[$1], c=[$2])
+: +- LogicalTableScan(table=[[MyTable1]])
++- LogicalProject(d=[$0], e=[$1], f=[$2])
+ +- LogicalTableScan(table=[[MyTable2]])
+
+== Optimized Logical Plan ==
+Union(all=[true], union=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+:- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
++- DataStreamScan(table=[[_DataStreamTable_1]], fields=[d, e, f], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+
+== Physical Execution Plan ==
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_0), fields:(a, b, c))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_1), fields:(d, e, f))
+ ship_strategy : FORWARD
+
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testExplainWithJoin[extended=true]">
+ <Resource name="explain">
+ <![CDATA[== Abstract Syntax Tree ==
+LogicalProject(a=[$0], b=[$1], c=[$2], e=[$4], f=[$5])
++- LogicalFilter(condition=[=($0, $3)])
+ +- LogicalJoin(condition=[true], joinType=[inner])
+ :- LogicalTableScan(table=[[MyTable1]])
+ +- LogicalTableScan(table=[[MyTable2]])
+
+== Optimized Logical Plan ==
+Calc(select=[a, b, c, e, f], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
++- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+ :- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+ : +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+ +- Exchange(distribution=[hash[d]], updateAsRetraction=[true], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+ +- DataStreamScan(table=[[_DataStreamTable_1]], fields=[d, e, f], updateAsRetraction=[true], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+
+== Physical Execution Plan ==
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Data Source
+ content : collect elements with CollectionInputFormat
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_0), fields:(a, b, c))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : SourceConversion(table:Buffer(_DataStreamTable_1), fields:(d, e, f))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : InnerJoin(where: (=(a, d)), select: (a, b, c, d, e, f), leftInputSpec: NoUniqueKey, rightInputSpec: NoUniqueKey)
+ ship_strategy : HASH
+
+ : Operator
+ content : Calc(select: (a, b, c, e, f))
+ ship_strategy : FORWARD
+
+]]>
+ </Resource>
+ </TestCase>
<TestCase name="testExplainWithMultiSinks[extended=false]">
<Resource name="explain">
<![CDATA[== Abstract Syntax Tree ==
@@ -416,42 +534,6 @@ Sink(fields=[a, b, c])
]]>
</Resource>
</TestCase>
- <TestCase name="testExplainWithSingleSink[extended=true]">
- <Resource name="explain">
- <![CDATA[== Abstract Syntax Tree ==
-LogicalSink(fields=[a, b, c])
-+- LogicalProject(a=[$0], b=[$1], c=[$2])
- +- LogicalFilter(condition=[>($0, 10)])
- +- LogicalTableScan(table=[[MyTable1]])
-
-== Optimized Logical Plan ==
-Sink(fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
-+- Calc(select=[a, b, c], where=[>(a, 10)], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
- +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
-
-== Physical Execution Plan ==
- : Data Source
- content : collect elements with CollectionInputFormat
-
- : Operator
- content : SourceConversion(table:Buffer(_DataStreamTable_0), fields:(a, b, c))
- ship_strategy : FORWARD
-
- : Operator
- content : Calc(where: (a > 10), select: (a, b, c))
- ship_strategy : FORWARD
-
- : Operator
- content : SinkConversionToRow
- ship_strategy : FORWARD
-
- : Data Sink
- content : Sink: TestingAppendTableSink
- ship_strategy : FORWARD
-
-]]>
- </Resource>
- </TestCase>
<TestCase name="testExplainWithSort[extended=false]">
<Resource name="explain">
<![CDATA[== Abstract Syntax Tree ==
@@ -479,48 +561,44 @@ SortLimit(orderBy=[a ASC], offset=[0], fetch=[5])
]]>
</Resource>
</TestCase>
- <TestCase name="testExplainWithUnion[extended=true]">
+ <TestCase name="testExplainWithSort[extended=true]">
<Resource name="explain">
<![CDATA[== Abstract Syntax Tree ==
-LogicalUnion(all=[true])
-:- LogicalProject(a=[$0], b=[$1], c=[$2])
-: +- LogicalTableScan(table=[[MyTable1]])
-+- LogicalProject(d=[$0], e=[$1], f=[$2])
- +- LogicalTableScan(table=[[MyTable2]])
+LogicalSort(sort0=[$0], dir0=[ASC-nulls-first], fetch=[5])
++- LogicalProject(a=[$0], b=[$1], c=[$2])
+ +- LogicalTableScan(table=[[MyTable1]])
== Optimized Logical Plan ==
-Union(all=[true], union=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
-:- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
-+- DataStreamScan(table=[[_DataStreamTable_1]], fields=[d, e, f], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+SortLimit(orderBy=[a ASC], offset=[0], fetch=[5], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
++- Exchange(distribution=[single], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+ +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
== Physical Execution Plan ==
: Data Source
content : collect elements with CollectionInputFormat
- : Data Source
- content : collect elements with CollectionInputFormat
-
: Operator
content : SourceConversion(table:Buffer(_DataStreamTable_0), fields:(a, b, c))
ship_strategy : FORWARD
: Operator
- content : SourceConversion(table:Buffer(_DataStreamTable_1), fields:(d, e, f))
- ship_strategy : FORWARD
+ content : SortLimit(orderBy: [a ASC], offset: 0, fetch: 5)
+ ship_strategy : GLOBAL
]]>
</Resource>
</TestCase>
- <TestCase name="testExplainWithSort[extended=true]">
+ <TestCase name="testExplainWithSingleSink[extended=true]">
<Resource name="explain">
<![CDATA[== Abstract Syntax Tree ==
-LogicalSort(sort0=[$0], dir0=[ASC-nulls-first], fetch=[5])
+LogicalSink(fields=[a, b, c])
+- LogicalProject(a=[$0], b=[$1], c=[$2])
- +- LogicalTableScan(table=[[MyTable1]])
+ +- LogicalFilter(condition=[>($0, 10)])
+ +- LogicalTableScan(table=[[MyTable1]])
== Optimized Logical Plan ==
-SortLimit(orderBy=[a ASC], offset=[0], fetch=[5], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
-+- Exchange(distribution=[single], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+Sink(fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
++- Calc(select=[a, b, c], where=[>(a, 10)], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
+- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc]): rowcount = , cumulative cost = {rows, cpu, io, network, memory}
== Physical Execution Plan ==
@@ -532,8 +610,16 @@ SortLimit(orderBy=[a ASC], offset=[0], fetch=[5], updateAsRetraction=[false], ac
ship_strategy : FORWARD
: Operator
- content : SortLimit(orderBy: [a ASC], offset: 0, fetch: 5)
- ship_strategy : GLOBAL
+ content : Calc(where: (a > 10), select: (a, b, c))
+ ship_strategy : FORWARD
+
+ : Operator
+ content : SinkConversionToRow
+ ship_strategy : FORWARD
+
+ : Data Sink
+ content : Sink: TestingAppendTableSink
+ ship_strategy : FORWARD
]]>
</Resource>
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/DagOptimizationTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/DagOptimizationTest.xml
index 03c13dc..7c15d6a 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/DagOptimizationTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/DagOptimizationTest.xml
@@ -164,7 +164,7 @@ Calc(select=[a AS a1, b AS b1], where=[<=(a, 10)], updateAsRetraction=[false], a
Union(all=[true], union=[a1, b1], updateAsRetraction=[false], accMode=[Acc], reuse_id=[2])
:- Reused(reference_id=[1])
+- Calc(select=[a, b1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a, a1)], select=[a1, b1, a, b, c, d, e], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a, a1)], select=[a1, b1, a, b, c, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
+- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc])
@@ -212,7 +212,7 @@ Calc(select=[a, b], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc],
+- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc])
Calc(select=[a0 AS a, b AS b1], updateAsRetraction=[false], accMode=[Acc], reuse_id=[2])
-+- Join(joinType=[InnerJoin], where=[=(a0, a)], select=[a, b, a0, b0, c, d, e], updateAsRetraction=[false], accMode=[Acc])
++- Join(joinType=[InnerJoin], where=[=(a0, a)], select=[a, b, a0, b0, c, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
+- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc])
@@ -274,7 +274,7 @@ Calc(select=[a, b, c], where=[>=(a, 0)], updateAsRetraction=[true], accMode=[Acc
+- Reused(reference_id=[1])
Calc(select=[a1, b, c AS c2], updateAsRetraction=[true], accMode=[Acc], reuse_id=[3])
-+- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], updateAsRetraction=[true], accMode=[Acc])
++- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a1, b], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
@@ -287,7 +287,7 @@ Sink(fields=[a1, b, c2], updateAsRetraction=[false], accMode=[Acc])
Sink(fields=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
+- Calc(select=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a3]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a3, c AS c1], where=[<(b, 5)], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[2])
@@ -743,13 +743,13 @@ LogicalSink(fields=[a1, b, c1])
<![CDATA[
Sink(fields=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
+- Calc(select=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a3]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a3, c AS c1], where=[AND(>=(a, 0), <(b, 5))], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc], reuse_id=[1])
+- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
+- Calc(select=[a1, b, c AS c2], updateAsRetraction=[true], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], updateAsRetraction=[true], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a1, b], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
@@ -777,7 +777,7 @@ Sink(fields=[a1, b1], updateAsRetraction=[false], accMode=[Acc])
:- Calc(select=[a AS a1, b AS b1], where=[<=(a, 10)], updateAsRetraction=[false], accMode=[Acc], reuse_id=[1])
: +- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc])
+- Calc(select=[a, b1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a, a1)], select=[a1, b1, a, b, c, d, e], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a, a1)], select=[a1, b1, a, b, c, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
+- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc])
@@ -800,19 +800,19 @@ LogicalSink(fields=[a, b, c])
<![CDATA[
Sink(fields=[a, b, c], updateAsRetraction=[false], accMode=[Acc])
+- Calc(select=[a1, b1, c1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a1, a3, b1, c1], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a1, a3, b1, c1], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a1], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc], reuse_id=[1])
+- Exchange(distribution=[hash[a3]], updateAsRetraction=[true], accMode=[Acc])
+- Calc(select=[a3, b AS b1, c1], updateAsRetraction=[true], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], updateAsRetraction=[true], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
:- Exchange(distribution=[hash[a3]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a3, c AS c1], where=[AND(>=(a, 0), <(b, 5))], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
+- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
+- Calc(select=[a1, b, c AS c2], updateAsRetraction=[true], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], updateAsRetraction=[true], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a1, b], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
@@ -842,9 +842,9 @@ LogicalSink(fields=[a, b, c, d, e, f, i, j, k, l, m, s])
<![CDATA[
Sink(fields=[a, b, c, d, e, f, i, j, k, l, m, s], updateAsRetraction=[false], accMode=[Acc])
+- Correlate(invocation=[split($cor0.c)], correlate=[table(split($cor0.c))], select=[a,b,c,d,e,f,i,j,k,l,m,f0], rowType=[RecordType(INTEGER a, BIGINT b, VARCHAR(2147483647) c, INTEGER d, BIGINT e, VARCHAR(2147483647) f, INTEGER i, BIGINT j, INTEGER k, VARCHAR(2147483647) l, BIGINT m, VARCHAR(2147483647) f0)], joinType=[INNER], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a, i)], select=[a, b, c, d, e, f, i, j, k, l, m], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a, i)], select=[a, b, c, d, e, f, i, j, k, l, m], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a]], updateAsRetraction=[true], accMode=[Acc])
- : +- Join(joinType=[InnerJoin], where=[=(b, e)], select=[a, b, c, d, e, f], updateAsRetraction=[true], accMode=[Acc])
+ : +- Join(joinType=[InnerJoin], where=[=(b, e)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
: :- Exchange(distribution=[hash[b]], updateAsRetraction=[true], accMode=[Acc])
: : +- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc])
: +- Exchange(distribution=[hash[e]], updateAsRetraction=[true], accMode=[Acc])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SetOperatorsTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SetOperatorsTest.xml
index 18300e3..08ac417 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SetOperatorsTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SetOperatorsTest.xml
@@ -33,7 +33,7 @@ LogicalIntersect(all=[false])
<![CDATA[
GroupAggregate(groupBy=[c], select=[c])
+- Exchange(distribution=[hash[c]])
- +- Join(joinType=[LeftSemiJoin], where=[OR(=(c, f), AND(IS NULL(c), IS NULL(f)))], select=[c])
+ +- Join(joinType=[LeftSemiJoin], where=[OR(=(c, f), AND(IS NULL(c), IS NULL(f)))], select=[c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- Calc(select=[c])
: +- TableSourceScan(table=[[T1, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -100,7 +100,7 @@ LogicalMinus(all=[false])
<![CDATA[
GroupAggregate(groupBy=[c], select=[c])
+- Exchange(distribution=[hash[c]])
- +- Join(joinType=[LeftAntiJoin], where=[OR(=(c, f), AND(IS NULL(c), IS NULL(f)))], select=[c])
+ +- Join(joinType=[LeftAntiJoin], where=[OR(=(c, f), AND(IS NULL(c), IS NULL(f)))], select=[c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- Calc(select=[c])
: +- TableSourceScan(table=[[T1, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -170,7 +170,7 @@ LogicalMinus(all=[false])
<![CDATA[
GroupAggregate(groupBy=[a, b, c], select=[a, b, c])
+- Exchange(distribution=[hash[a, b, c]])
- +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, a0), AND(IS NULL(a), IS NULL(a0))), OR(=(b, b0), AND(IS NULL(b), IS NULL(b0))), OR(=(c, c0), AND(IS NULL(c), IS NULL(c0))))], select=[a, b, c])
+ +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, a0), AND(IS NULL(a), IS NULL(a0))), OR(=(b, b0), AND(IS NULL(b), IS NULL(b0))), OR(=(c, c0), AND(IS NULL(c), IS NULL(c0))))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b, c]], reuse_id=[1])
: +- TableSourceScan(table=[[MyTable, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Reused(reference_id=[1])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SinkTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SinkTest.xml
index 22e014d..fd7b949 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SinkTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SinkTest.xml
@@ -265,13 +265,13 @@ LogicalSink(fields=[a1, b, c1])
<![CDATA[
Sink(fields=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
+- Calc(select=[a1, b, c1], updateAsRetraction=[false], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], updateAsRetraction=[false], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a3)], select=[a3, c1, a1, b, c2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a3]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a3, c AS c1], where=[AND(>=(a, 0), <(b, 5))], updateAsRetraction=[true], accMode=[Acc])
: +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c], updateAsRetraction=[true], accMode=[Acc], reuse_id=[1])
+- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
+- Calc(select=[a1, b, c AS c2], updateAsRetraction=[true], accMode=[Acc])
- +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], updateAsRetraction=[true], accMode=[Acc])
+ +- Join(joinType=[InnerJoin], where=[=(a1, a2)], select=[a1, b, a2, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[true], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a AS a1, b], where=[<=(a, 10)], updateAsRetraction=[true], accMode=[Acc])
: +- Reused(reference_id=[1])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SubplanReuseTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SubplanReuseTest.xml
index a00b988..168292c 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SubplanReuseTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/SubplanReuseTest.xml
@@ -70,16 +70,16 @@ LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3], e=[$4], f=[$5], a0=[$6], b0=[$7],
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(b, e0)], select=[a, b, c, d, e, f, a0, b0, c0, d0, e0, f0])
+Join(joinType=[InnerJoin], where=[=(b, e0)], select=[a, b, c, d, e, f, a0, b0, c0, d0, e0, f0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
-: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- Calc(select=[a, b, c], where=[<(a, 10)])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
: +- TableSourceScan(table=[[y, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
+- Exchange(distribution=[hash[e]])
- +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+ +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, c], where=[>(a, 5)])
: +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -114,9 +114,9 @@ LogicalProject(a=[$0], b=[$1], d=[$2], e=[$3], a0=[$4], b0=[$5], d0=[$6], e0=[$7
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(b, e0)], select=[a, b, d, e, a0, b0, d0, e0])
+Join(joinType=[InnerJoin], where=[=(b, e0)], select=[a, b, d, e, a0, b0, d0, e0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
-: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, d, e])
+: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- Calc(select=[a, b], where=[<(a, 10)])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c], reuse_id=[1])
@@ -124,7 +124,7 @@ Join(joinType=[InnerJoin], where=[=(b, e0)], select=[a, b, d, e, a0, b0, d0, e0]
: +- Calc(select=[d, e])
: +- TableSourceScan(table=[[y, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
+- Exchange(distribution=[hash[e]])
- +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, d, e])
+ +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b], where=[>(a, 5)])
: +- Reused(reference_id=[1])
@@ -155,7 +155,7 @@ LogicalProject(c=[$0], a=[$1], b=[$2], c0=[$3], a0=[$4], b0=[$5])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c, a, b, c0, a1, b0])
-+- Join(joinType=[InnerJoin], where=[=(a0, b0)], select=[c, a, b, a0, c0, a1, b0])
++- Join(joinType=[InnerJoin], where=[=(a0, b0)], select=[c, a, b, a0, c0, a1, b0], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey])
:- Exchange(distribution=[hash[a0]])
: +- Calc(select=[c, a, b, CAST(a) AS a0])
: +- GroupAggregate(groupBy=[c], select=[c, MyFirst(a) AS a, MyLast(b) AS b], reuse_id=[1])
@@ -199,7 +199,7 @@ LogicalUnion(all=[true])
<![CDATA[
Union(all=[true], union=[a, c, e])
:- Calc(select=[a, LOWER(c) AS c, e], reuse_id=[1])
-: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, c, d, e])
+: +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, c, d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- Calc(select=[a, c], where=[LIKE(c, _UTF-16LE'test%')])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -262,7 +262,7 @@ LogicalProject(a=[$0], b=[$1], c=[$2], v=[$3], a0=[$4], b0=[$5], c0=[$6], v0=[$7
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(f0, f00)], select=[a, b, c, f0, a0, b0, c0, f00])
+Join(joinType=[InnerJoin], where=[=(f0, f00)], select=[a, b, c, f0, a0, b0, c0, f00], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[f0]])
: +- Correlate(invocation=[str_split($cor0.c, _UTF-16LE'-')], correlate=[table(str_split($cor0.c,_UTF-16LE'-'))], select=[a,b,c,f0], rowType=[RecordType(INTEGER a, BIGINT b, VARCHAR(2147483647) c, VARCHAR(2147483647) f0)], joinType=[INNER])
: +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -296,7 +296,7 @@ LogicalProject(a=[$0], b=[$1], c=[$2], s=[$3], a0=[$4], b0=[$5], c0=[$6], s0=[$7
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(c, f00)], select=[a, b, c, f0, a0, b0, c0, f00])
+Join(joinType=[InnerJoin], where=[=(c, f00)], select=[a, b, c, f0, a0, b0, c0, f00], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- Correlate(invocation=[TableFun($cor0.c)], correlate=[table(TableFun($cor0.c))], select=[a,b,c,f0], rowType=[RecordType(INTEGER a, BIGINT b, VARCHAR(2147483647) c, VARCHAR(2147483647) f0)], joinType=[INNER])
: +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -337,14 +337,14 @@ LogicalUnion(all=[true])
<Resource name="planAfter">
<![CDATA[
Union(all=[true], union=[a, b, c, d, e, f])
-:- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+:- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]], reuse_id=[1])
: : +- Calc(select=[a, b, c], where=[LIKE(c, _UTF-16LE'test%')])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
: +- Calc(select=[d, e, f], where=[>(e, 10)])
: +- TableSourceScan(table=[[y, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
-+- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
++- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Reused(reference_id=[1])
+- Exchange(distribution=[hash[d]])
+- Calc(select=[d, e, f], where=[<>(f, _UTF-16LE'':VARCHAR(2147483647) CHARACTER SET "UTF-16LE")])
@@ -375,7 +375,7 @@ LogicalProject(c=[$0], a=[$1], b=[$2], c0=[$3], a0=[$4], b0=[$5])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c, a, b, c0, a1, b0])
-+- Join(joinType=[InnerJoin], where=[=(a0, b0)], select=[c, a, b, a0, c0, a1, b0])
++- Join(joinType=[InnerJoin], where=[=(a0, b0)], select=[c, a, b, a0, c0, a1, b0], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey])
:- Exchange(distribution=[hash[a0]])
: +- Calc(select=[c, a, b, CAST(a) AS a0])
: +- GroupAggregate(groupBy=[c], select=[c, SUM(a) AS a, SUM(b) AS b], reuse_id=[1])
@@ -417,7 +417,7 @@ LogicalUnion(all=[true])
<![CDATA[
Union(all=[true], union=[a, b])
:- Calc(select=[a, b])
-: +- Join(joinType=[InnerJoin], where=[OR(=(ABS(a), ABS(d)), =(c, f))], select=[a, b, c, d, e, f], reuse_id=[1])
+: +- Join(joinType=[InnerJoin], where=[OR(=(ABS(a), ABS(d)), =(c, f))], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], reuse_id=[1])
: :- Exchange(distribution=[single])
: : +- Calc(select=[a, b, c], where=[>(b, 1)])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -459,7 +459,7 @@ LogicalUnion(all=[true])
<![CDATA[
Union(all=[true], union=[a, b])
:- Calc(select=[a, b])
-: +- Join(joinType=[InnerJoin], where=[OR(=(random_udf(a), random_udf(d)), =(c, f))], select=[a, b, c, d, e, f], reuse_id=[1])
+: +- Join(joinType=[InnerJoin], where=[OR(=(random_udf(a), random_udf(d)), =(c, f))], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], reuse_id=[1])
: :- Exchange(distribution=[single])
: : +- Calc(select=[a, b, c], where=[>(b, 1)])
: : +- TableSourceScan(table=[[x, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -491,7 +491,7 @@ LogicalProject(a=[$0], b=[$1], EXPR$2=[$2], a0=[$3], b0=[$4], EXPR$20=[$5])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a, a0)], select=[a, b, $2, a0, b0, w0$o0])
+Join(joinType=[InnerJoin], where=[=(a, a0)], select=[a, b, $2, a0, b0, w0$o0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, w0$o0 AS $2], where=[<(b, 100)])
: +- OverAggregate(orderBy=[c DESC], window=[ RANG BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], select=[a, b, c, RANK(*) AS w0$o0], reuse_id=[1])
@@ -560,7 +560,7 @@ LogicalProject(a=[$0], b=[$1], EXPR$2=[$2], a0=[$3], b0=[$4], EXPR$20=[$5])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a, a0)], select=[a, b, $2, a0, b0, w0$o0])
+Join(joinType=[InnerJoin], where=[=(a, a0)], select=[a, b, $2, a0, b0, w0$o0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, w0$o0 AS $2], where=[<(b, 100)])
: +- OverAggregate(partitionBy=[c], orderBy=[c DESC], window=[ RANG BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], select=[a, b, c, MyFirst(c) AS w0$o0], reuse_id=[1])
@@ -594,7 +594,7 @@ LogicalProject(c=[$0], a=[$1], b=[$2], c0=[$3], a0=[$4], b0=[$5])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a, a0)], select=[c, a, b, c0, a0, b0])
+Join(joinType=[InnerJoin], where=[=(a, a0)], select=[c, a, b, c0, a0, b0], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[c, a, b], where=[>(a, 1)])
: +- GroupAggregate(groupBy=[c], select=[c, SUM(a) AS a, SUM(b) AS b], reuse_id=[1])
@@ -668,11 +668,11 @@ LogicalIntersect(all=[false])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[OR(=(random, random0), AND(IS NULL(random), IS NULL(random0)))], select=[random])
+Join(joinType=[LeftSemiJoin], where=[OR(=(random, random0), AND(IS NULL(random), IS NULL(random0)))], select=[random], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[random]])
: +- GroupAggregate(groupBy=[random], select=[random])
: +- Exchange(distribution=[hash[random]])
-: +- Join(joinType=[LeftSemiJoin], where=[OR(=(random, random0), AND(IS NULL(random), IS NULL(random0)))], select=[random])
+: +- Join(joinType=[LeftSemiJoin], where=[OR(=(random, random0), AND(IS NULL(random), IS NULL(random0)))], select=[random], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[random]], reuse_id=[1])
: : +- Calc(select=[random])
: : +- SortLimit(orderBy=[EXPR$1 ASC], offset=[0], fetch=[1])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/GroupingSetsTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/GroupingSetsTest.xml
index a3d715f..ecc9b28 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/GroupingSetsTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/GroupingSetsTest.xml
@@ -273,7 +273,7 @@ Calc(select=[deptno, gender, min_name], where=[OR(>($f5, 2), AND(=(gender, _UTF-
+- Exchange(distribution=[hash[deptno, deptno0, gender, $e]])
+- Expand(projects=[{deptno=[$0], deptno0=[$1], gender=[$2], ename=[$3], $e=[0]}, {deptno=[$0], deptno0=[$1], gender=[null], ename=[$3], $e=[1]}, {deptno=[$0], deptno0=[null], gender=[$2], ename=[$3], $e=[2]}, {deptno=[$0], deptno0=[null], gender=[null], ename=[$3], $e=[3]}, {deptno=[null], deptno0=[$1], gender=[$2], ename=[$3], $e=[4]}, {deptno=[null], deptno0=[$1], gender=[null], ename=[$3], $e=[5]}, {deptno=[null], deptno0=[null], gender=[$2], ename=[$3], $e=[6]}, {deptno=[null] [...]
+- Calc(select=[deptno, deptno0, gender, ename])
- +- Join(joinType=[InnerJoin], where=[=(deptno, deptno0)], select=[ename, deptno, gender, deptno0, dname])
+ +- Join(joinType=[InnerJoin], where=[=(deptno, deptno0)], select=[ename, deptno, gender, deptno0, dname], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[deptno]])
: +- TableSourceScan(table=[[emp, source: [TestTableSource(ename, deptno, gender)]]], fields=[ename, deptno, gender])
+- Exchange(distribution=[hash[deptno]])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/WindowAggregateTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/WindowAggregateTest.xml
index 59a46f3..190929a 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/WindowAggregateTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/agg/WindowAggregateTest.xml
@@ -253,7 +253,7 @@ LogicalProject(hs1=[$0], he1=[$1], c1=[$2], s1=[$3], hs2=[$4], he2=[$5], c2=[$6]
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(he1, he2)], select=[hs1, he1, c1, s1, hs2, he2, c2, s2])
+Join(joinType=[InnerJoin], where=[=(he1, he2)], select=[hs1, he1, c1, s1, hs2, he2, c2, s2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[he1]])
: +- Calc(select=[CAST(w$start) AS hs1, CAST(w$end) AS he1, c1, s1], where=[IS NOT NULL(s1)])
: +- GroupWindowAggregate(window=[SlidingGroupWindow('w$, rowtime, 3600000, 60000)], properties=[w$start, w$end, w$rowtime, w$proctime], select=[COUNT(*) AS c1, SUM(c) AS s1, start('w$) AS w$start, end('w$) AS w$end, rowtime('w$) AS w$rowtime, proctime('w$) AS w$proctime])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/JoinTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/JoinTest.xml
index 9c41ba5..3706dae 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/JoinTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/JoinTest.xml
@@ -30,7 +30,7 @@ LogicalProject(a1=[$0], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -55,7 +55,7 @@ LogicalProject(a1=[$0], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1, a2], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -85,7 +85,7 @@ LogicalProject(a1=[$1], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -120,7 +120,7 @@ LogicalProject(a1=[$1], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -153,7 +153,7 @@ LogicalProject(a1=[$1], b1=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[FullOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -183,7 +183,7 @@ LogicalProject(a1=[$1], b1=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[FullOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -216,7 +216,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[FullOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[FullOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -253,7 +253,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[FullOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[FullOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -283,7 +283,7 @@ LogicalProject(a1=[$0], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1])
+Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a1]])
: +- Calc(select=[a1])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3])
@@ -313,7 +313,7 @@ LogicalProject(a1=[$1], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[Acc])
+Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[Acc])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -327,30 +327,6 @@ Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetractio
]]>
</Resource>
</TestCase>
- <TestCase name="testInnerJoinWithMiniBatch">
- <Resource name="sql">
- <![CDATA[SELECT a1, b1 FROM A JOIN B ON a1 = b1]]>
- </Resource>
- <Resource name="planBefore">
- <![CDATA[
-LogicalProject(a1=[$0], b1=[$3])
-+- LogicalJoin(condition=[=($0, $3)], joinType=[inner])
- :- LogicalTableScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]])
- +- LogicalTableScan(table=[[B, source: [TestTableSource(b1, b2, b3)]]])
-]]>
- </Resource>
- <Resource name="planAfter">
- <![CDATA[
-Join(joinType=[InnerJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[Acc])
-:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
-: +- Calc(select=[a1], updateAsRetraction=[true], accMode=[Acc])
-: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
-+- Exchange(distribution=[hash[b1]], updateAsRetraction=[true], accMode=[Acc])
- +- Calc(select=[b1], updateAsRetraction=[true], accMode=[Acc])
- +- TableSourceScan(table=[[B, source: [TestTableSource(b1, b2, b3)]]], fields=[b1, b2, b3], updateAsRetraction=[true], accMode=[Acc])
-]]>
- </Resource>
- </TestCase>
<TestCase name="testLeftJoinWithEqualPk">
<Resource name="sql">
<![CDATA[SELECT a1, b1 FROM (SELECT SUM(a2) AS a2, a1 FROM A GROUP BY a1) LEFT JOIN (SELECT SUM(b2) AS b2, b1 FROM B GROUP BY b1) ON a1 = b1]]>
@@ -371,7 +347,7 @@ LogicalProject(a1=[$1], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -406,7 +382,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[InnerJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[InnerJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -442,7 +418,7 @@ LogicalProject(i=[$0], j=[$1], t=[$2], i0=[$3], k=[$4])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[FullOuterJoin], where=[AND(=(i, i0), =(i, k))], select=[i, j, t, i0, k])
+Join(joinType=[FullOuterJoin], where=[AND(=(i, i0), =(i, k))], select=[i, j, t, i0, k], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[i, i]])
: +- TableSourceScan(table=[[MyTable3, source: [TestTableSource(i, j, t)]]], fields=[i, j, t])
+- Exchange(distribution=[hash[i, k]])
@@ -464,7 +440,7 @@ LogicalProject(a1=[$0], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -489,7 +465,7 @@ LogicalProject(a1=[$0], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1, a2], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -520,7 +496,7 @@ LogicalProject(a1=[$1], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -557,7 +533,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[LeftOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[LeftOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -594,7 +570,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -627,7 +603,7 @@ LogicalProject(a1=[$1], b1=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[LeftOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -657,7 +633,7 @@ LogicalProject(a1=[$1], b1=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -685,7 +661,7 @@ LogicalProject(b=[$1], y=[$5])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, y])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a, z), $f3)], select=[a, b, $f3, y, z])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a, z), $f3)], select=[a, b, $f3, y, z], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, <(b, 2) AS $f3])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -710,7 +686,7 @@ LogicalProject(b=[$1], y=[$4])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, y])
-+- Join(joinType=[LeftOuterJoin], where=[AND(=(a, z), <(b, x))], select=[a, b, x, y, z])
++- Join(joinType=[LeftOuterJoin], where=[AND(=(a, z), <(b, x))], select=[a, b, x, y, z], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -734,7 +710,7 @@ LogicalProject(a1=[$0], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a1, a2, b1, b2], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1, a2], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -759,7 +735,7 @@ LogicalProject(b=[$1], y=[$4])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, y])
-+- Join(joinType=[LeftOuterJoin], where=[=(a, z)], select=[a, b, y, z])
++- Join(joinType=[LeftOuterJoin], where=[=(a, z)], select=[a, b, y, z], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -784,7 +760,7 @@ LogicalProject(b=[$1], y=[$4])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, y])
-+- Join(joinType=[RightOuterJoin], where=[=(a, z)], select=[a, b, y, z])
++- Join(joinType=[RightOuterJoin], where=[=(a, z)], select=[a, b, y, z], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -808,7 +784,7 @@ LogicalProject(a1=[$0], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[a1], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[A, source: [TestTableSource(a1, a2, a3)]]], fields=[a1, a2, a3], updateAsRetraction=[true], accMode=[Acc])
@@ -838,7 +814,7 @@ LogicalProject(a1=[$1], b1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -873,7 +849,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[RightOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[RightOuterJoin], where=[=(a2, b2)], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -910,7 +886,7 @@ LogicalProject(a1=[$1], a2=[$0], b1=[$3], b2=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, a2, b1, b2], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a2, b2), >(a1, b1))], select=[a2, a1, b2, b1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a2]], updateAsRetraction=[true], accMode=[AccRetract])
: +- Calc(select=[a2, a1], updateAsRetraction=[true], accMode=[AccRetract])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[true], accMode=[AccRetract])
@@ -943,7 +919,7 @@ LogicalProject(a1=[$1], b1=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[RightOuterJoin], where=[=(a1, b1)], select=[a1, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1], updateAsRetraction=[false], accMode=[Acc])
: +- Exchange(distribution=[hash[a1]], updateAsRetraction=[true], accMode=[Acc])
@@ -973,7 +949,7 @@ LogicalProject(a1=[$1], b1=[$2])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b1, b2, b3], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -1006,7 +982,7 @@ LogicalProject(a1=[$1], b1=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a1, b1], updateAsRetraction=[false], accMode=[AccRetract])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], updateAsRetraction=[false], accMode=[AccRetract])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a1, b1), >(a2, b2))], select=[a2, a1, b2, b1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[a1]], updateAsRetraction=[false], accMode=[Acc])
: +- Calc(select=[a2, a1], updateAsRetraction=[false], accMode=[Acc])
: +- GroupAggregate(groupBy=[a1], select=[a1, SUM(a2) AS a2], updateAsRetraction=[false], accMode=[Acc])
@@ -1038,7 +1014,7 @@ LogicalProject(b=[$1], x=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, x])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a, z), $f3)], select=[a, b, x, z, $f3])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a, z), $f3)], select=[a, b, x, z, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1063,7 +1039,7 @@ LogicalProject(b=[$1], y=[$4])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b, y])
-+- Join(joinType=[RightOuterJoin], where=[AND(=(a, z), <(b, x))], select=[a, b, x, y, z])
++- Join(joinType=[RightOuterJoin], where=[AND(=(a, z), <(b, x))], select=[a, b, x, y, z], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[t, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1096,7 +1072,7 @@ LogicalProject(key=[$0], v=[$1], key0=[$2], v0=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftOuterJoin], where=[=(key, key0)], select=[key, v, key0, v0], updateAsRetraction=[false], accMode=[AccRetract])
+Join(joinType=[LeftOuterJoin], where=[=(key, key0)], select=[key, v, key0, v0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey], updateAsRetraction=[false], accMode=[AccRetract])
:- Exchange(distribution=[hash[key]], updateAsRetraction=[true], accMode=[Acc])
: +- Calc(select=[CAST(0:BIGINT) AS key, v], where=[=(key, 0:BIGINT)], updateAsRetraction=[true], accMode=[Acc])
: +- TableSourceScan(table=[[src, source: [TestTableSource(key, v)]]], fields=[key, v], updateAsRetraction=[true], accMode=[Acc])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/SemiAntiJoinTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/SemiAntiJoinTest.xml
index f415be3..cdae069 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/SemiAntiJoinTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/SemiAntiJoinTest.xml
@@ -34,9 +34,9 @@ LogicalFilter(condition=[AND(=($cor0.a, $0), <($1, 100))])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[=(a, i)], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[=(a, i)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
-: +- Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c])
+: +- Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[single])
@@ -69,7 +69,7 @@ LogicalAggregate(group=[{0, 1, 2, 3}], EXPR$0=[MAX($4)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, e), =(c, f))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, e), =(c, f))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[e, f]])
@@ -99,7 +99,7 @@ LogicalFilter(condition=[=($cor1.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -125,7 +125,7 @@ LogicalFilter(condition=[<($cor0.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[<(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[<(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -150,7 +150,7 @@ LogicalFilter(condition=[<($cor0.a, 10)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[true], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[true], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c], where=[<(a, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -178,7 +178,7 @@ LogicalAggregate(group=[{0}])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(c, f)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(c, f)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[f]])
@@ -206,7 +206,7 @@ LogicalFilter(condition=[=($cor0.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -231,7 +231,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
<Resource name="planAfter">
<![CDATA[
Calc(select=[+(a, 10) AS EXPR$0, c])
-+- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, c])
++- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, c], where=[AND(>(b, 10), NOT(LIKE(c, _UTF-16LE'abc')))])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -263,7 +263,7 @@ LogicalJoin(condition=[=($1, $3)], joinType=[full])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[c])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[c])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -272,7 +272,7 @@ Join(joinType=[LeftSemiJoin], where=[$f0], select=[c])
+- GroupAggregate(select=[MIN(i) AS m])
+- Exchange(distribution=[single])
+- Calc(select=[true AS i])
- +- Join(joinType=[FullOuterJoin], where=[=(e, j)], select=[e, j])
+ +- Join(joinType=[FullOuterJoin], where=[=(e, j)], select=[e, j], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[e]])
: +- Calc(select=[e])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -302,7 +302,7 @@ LogicalTableScan(table=[[t, source: [TestTableSource(i, j, k)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -310,7 +310,7 @@ Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+- GroupAggregate(select=[MIN(i) AS m])
+- Exchange(distribution=[single])
+- Calc(select=[true AS i])
- +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[d])
+ +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[d], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[d])
: +- Correlate(invocation=[table_func($cor0.f)], correlate=[table(table_func($cor0.f))], select=[d,e,f,f0], rowType=[RecordType(INTEGER d, BIGINT e, VARCHAR(2147483647) f, VARCHAR(2147483647) f0)], joinType=[INNER])
@@ -339,7 +339,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -366,7 +366,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c], where=[>(b, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -400,7 +400,7 @@ LogicalUnion(all=[false])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -439,9 +439,9 @@ LogicalProject(i=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, i), =(b, j))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, i), =(b, j))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
-: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
@@ -472,9 +472,9 @@ LogicalFilter(condition=[=($cor0.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
-: +- Join(joinType=[LeftSemiJoin], where=[=(b, j)], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[=(b, j)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[b]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[j]])
@@ -514,13 +514,13 @@ LogicalFilter(condition=[<>($cor0.b, $1)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[<>(b, e)], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[<>(b, e)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
-: +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(b, i), IS NULL(b), IS NULL(i)), =(c, k))], select=[a, b, c])
+: +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(b, i), IS NULL(b), IS NULL(i)), =(c, k))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[c]])
-: : +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+: : +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: : :- Exchange(distribution=[single])
-: : : +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+: : : +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: : : :- Exchange(distribution=[hash[a]])
: : : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: : : +- Exchange(distribution=[hash[d]])
@@ -563,7 +563,7 @@ LogicalProject(EXPR$0=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, EXPR$0), =(c, f))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, EXPR$0), =(c, f))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
:- Exchange(distribution=[hash[b, c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[EXPR$0, f]])
@@ -594,7 +594,7 @@ LogicalProject(EXPR$0=[$4], d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, EXPR$0), =(a, d), =(c, f))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, EXPR$0), =(a, d), =(c, f))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, a, c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[EXPR$0, d, f]])
@@ -623,7 +623,7 @@ LogicalProject(EXPR$0=[SUBSTRING($2, 1, 5)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[+(a, 10) AS EXPR$0, c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, EXPR$0), =($f4, e))], select=[a, c, $f3, $f4])
++- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, EXPR$0), =($f4, e))], select=[a, c, $f3, $f4], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3, $f4]])
: +- Calc(select=[a, c, SUBSTRING(c, 1, 5) AS $f3, +(b, 1) AS $f4])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -650,7 +650,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- Calc(select=[a, b, c], where=[AND(>(b, 10), NOT(LIKE(c, _UTF-16LE'abc')))])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -681,12 +681,12 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, d), =(c, f))], select=[b, c, $f3])
++- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, d), =(c, f))], select=[b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3, c]])
: +- Calc(select=[b, c, CASE(AND(<>(c0, 0), IS NOT NULL(i), IS NOT NULL(a)), 1, 2) AS $f3])
- : +- Join(joinType=[LeftOuterJoin], where=[=(a, 1)], select=[a, b, c, c0, i])
+ : +- Join(joinType=[LeftOuterJoin], where=[=(a, 1)], select=[a, b, c, c0, i], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
- : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0])
+ : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : :- Exchange(distribution=[single])
: : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: : +- Exchange(distribution=[single])
@@ -729,12 +729,12 @@ LogicalProject(e=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(b, e), =(a, d), =(c, k))], select=[a, b, c])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(b, e), =(a, d), =(c, k))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, a, c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[e, d, k]])
+- Calc(select=[e, d, k])
- +- Join(joinType=[InnerJoin], where=[=(e, j)], select=[e, d, j, k])
+ +- Join(joinType=[InnerJoin], where=[=(e, j)], select=[e, d, j, k], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[e]])
: +- Calc(select=[e, d], where=[<(e, 50)])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -765,12 +765,12 @@ LogicalProject(j=[$3])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(a, d))], select=[a, b, c])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(a, d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[j, d]])
+- Calc(select=[j, d])
- +- Join(joinType=[LeftOuterJoin], where=[=(f, k)], select=[f, d, j, k])
+ +- Join(joinType=[LeftOuterJoin], where=[=(f, k)], select=[f, d, j, k], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[f]])
: +- Calc(select=[f, d], where=[<(e, 50)])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -801,13 +801,13 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(c, k))], select=[a, c])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(c, k))], select=[a, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, c]])
: +- Calc(select=[a, c])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d, k]])
+- Calc(select=[d, k])
- +- Join(joinType=[RightOuterJoin], where=[=(d, i)], select=[d, i, k])
+ +- Join(joinType=[RightOuterJoin], where=[=(d, i)], select=[d, i, k], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[d]])
: +- Calc(select=[d])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -836,7 +836,7 @@ LogicalProject(f1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(c, f1), =(a, d))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(c, f1), =(a, d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c, a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[f1, d]])
@@ -864,7 +864,7 @@ LogicalProject(d=[$0], EXPR$1=[SUBSTRING($2, 1, 5)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =($f3, EXPR$1), =(b, e))], select=[a, b, c, $f3])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =($f3, EXPR$1), =(b, e))], select=[a, b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, $f3, b]])
: +- Calc(select=[a, b, c, SUBSTRING(c, 1, 5) AS $f3])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -891,7 +891,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), >(b, e))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), >(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -917,7 +917,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, c], where=[>(b, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -945,7 +945,7 @@ LogicalProject(rk=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, rk), <>(a, d))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, rk), <>(a, d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[rk]])
@@ -982,9 +982,9 @@ LogicalProject(i=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(EXPR$0, i), =(k, c))], select=[a, c, EXPR$0])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(EXPR$0, i), =(k, c))], select=[a, c, EXPR$0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[EXPR$0, c]])
- : +- Join(joinType=[LeftOuterJoin], where=[true], select=[a, c, EXPR$0])
+ : +- Join(joinType=[LeftOuterJoin], where=[true], select=[a, c, EXPR$0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: :- Exchange(distribution=[single])
: : +- Calc(select=[a, c])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -992,7 +992,7 @@ Calc(select=[a])
: +- GroupAggregate(select=[MAX(d) AS EXPR$0])
: +- Exchange(distribution=[single])
: +- Calc(select=[d])
- : +- Join(joinType=[InnerJoin], where=[=(e, j)], select=[d, e, j])
+ : +- Join(joinType=[InnerJoin], where=[=(e, j)], select=[d, e, j], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: :- Exchange(distribution=[hash[e]])
: : +- Calc(select=[d, e])
: : +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -1024,7 +1024,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d, e]])
@@ -1050,7 +1050,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- Calc(select=[a, b, c], where=[>(b, 1)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1078,7 +1078,7 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b0, d))], select=[a, b, c, b0])
++- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b0, d))], select=[a, b, c, b0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b0]])
: +- Calc(select=[a, b, c, CAST(b) AS b0])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1108,7 +1108,7 @@ LogicalProject(EXPR$0=[$1])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a])
-+- Join(joinType=[LeftSemiJoin], where=[=(b, EXPR$0)], select=[a, b])
++- Join(joinType=[LeftSemiJoin], where=[=(b, EXPR$0)], select=[a, b], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1138,7 +1138,7 @@ LogicalAggregate(group=[{0}], EXPR$1=[COUNT()])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, EXPR$1))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, EXPR$1))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d, EXPR$1]])
@@ -1165,7 +1165,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, c], where=[AND(>(b, 10), NOT(LIKE(c, _UTF-16LE'abc')))])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1191,7 +1191,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -1223,12 +1223,12 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b])
-+- Join(joinType=[LeftSemiJoin], where=[=($f3, d)], select=[b, $f3])
++- Join(joinType=[LeftSemiJoin], where=[=($f3, d)], select=[b, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3]])
: +- Calc(select=[b, CASE(AND(<>(c0, 0), IS NOT NULL(i), IS NOT NULL(a)), 1, 2) AS $f3])
- : +- Join(joinType=[LeftOuterJoin], where=[=(a, 1)], select=[a, b, c, i])
+ : +- Join(joinType=[LeftOuterJoin], where=[=(a, 1)], select=[a, b, c, i], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
- : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c])
+ : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : :- Exchange(distribution=[single])
: : : +- Calc(select=[a, b])
: : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1271,9 +1271,9 @@ LogicalProject(j=[$1])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a])
-+- Join(joinType=[LeftSemiJoin], where=[=(EXPR$0, j)], select=[a, EXPR$0])
++- Join(joinType=[LeftSemiJoin], where=[=(EXPR$0, j)], select=[a, EXPR$0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[EXPR$0]])
- : +- Join(joinType=[LeftOuterJoin], where=[true], select=[a, EXPR$0])
+ : +- Join(joinType=[LeftOuterJoin], where=[true], select=[a, EXPR$0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: :- Exchange(distribution=[single])
: : +- Calc(select=[a])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1312,10 +1312,10 @@ LogicalProject(EXPR$0=[*(0.5:DECIMAL(2, 1), $0)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b])
-+- Join(joinType=[InnerJoin], where=[>(b, $f0)], select=[b, $f0])
++- Join(joinType=[InnerJoin], where=[>(b, $f0)], select=[b, $f0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[b])
- : +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b])
+ : +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- Calc(select=[a, b])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1352,7 +1352,7 @@ LogicalProject(e=[$1])
<Resource name="planAfter">
<![CDATA[
Calc(select=[s])
-+- Join(joinType=[LeftSemiJoin], where=[=($f3, e)], select=[s, $f3])
++- Join(joinType=[LeftSemiJoin], where=[=($f3, e)], select=[s, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3]])
: +- Calc(select=[s, $f3], where=[>($f2, 2)])
: +- GroupAggregate(groupBy=[b], select=[b, SUM(a) AS s, COUNT(*) AS $f2, MAX(b) AS $f3])
@@ -1389,13 +1389,13 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[c])
-+- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, c])
++- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, c])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
+- Calc(select=[d])
- +- Join(joinType=[FullOuterJoin], where=[=(e, i0)], select=[d, e, i0])
+ +- Join(joinType=[FullOuterJoin], where=[=(e, i0)], select=[d, e, i0], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[e]])
: +- Calc(select=[d, e])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -1423,7 +1423,7 @@ LogicalProject(f1=[$3])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(c, f1)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(c, f1)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[f1]])
@@ -1453,7 +1453,7 @@ LogicalProject(EXPR$0=[+($0, 100)], EXPR$1=[SUBSTRING($2, 1, 5)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, EXPR$0), =($f4, EXPR$1))], select=[a, b, c, $f3, $f4])
++- Join(joinType=[LeftSemiJoin], where=[AND(=($f3, EXPR$0), =($f4, EXPR$1))], select=[a, b, c, $f3, $f4], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3, $f4]])
: +- Calc(select=[a, b, c, +(a, 10) AS $f3, SUBSTRING(c, 1, 5) AS $f4])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1483,7 +1483,7 @@ LogicalProject(EXPR$0=[MAX($0) OVER (PARTITION BY $2 ORDER BY $0 NULLS FIRST RAN
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, $0), =(b, $1))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, $0), =(b, $1))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[$0, $1]])
@@ -1510,7 +1510,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -1536,7 +1536,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- Calc(select=[a, b, c], where=[>(b, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1563,7 +1563,7 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftSemiJoin], where=[=($f3, d)], select=[a, b, c, $f3])
++- Join(joinType=[LeftSemiJoin], where=[=($f3, d)], select=[a, b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f3]])
: +- Calc(select=[a, b, c, +(a, 1) AS $f3])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1598,7 +1598,7 @@ LogicalUnion(all=[false])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a])
-+- Join(joinType=[LeftSemiJoin], where=[=(b, e)], select=[a, b])
++- Join(joinType=[LeftSemiJoin], where=[=(b, e)], select=[a, b], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- Calc(select=[a, b])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1632,9 +1632,9 @@ LogicalFilter(condition=[<($1, 100)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
-: +- Join(joinType=[LeftSemiJoin], where=[<>(a, d)], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[<>(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[single])
@@ -1667,11 +1667,11 @@ LogicalTableScan(table=[[t, source: [TestTableSource(i, j, k)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
- +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[d])
+ +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[d], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[d])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -1705,11 +1705,11 @@ LogicalFilter(condition=[<($1, 100)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c, d, e, f])
+Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
-: +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c, d, e, f])
+: +- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
-: : +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+: : +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: : :- Exchange(distribution=[hash[a]])
: : : +- Calc(select=[a, b, c], where=[>=(b, 1)])
: : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1751,9 +1751,9 @@ LogicalProject(j=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(a, i))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(a, i))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, a]])
-: +- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(c, f))], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(c, f))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a, c]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d, f]])
@@ -1786,12 +1786,12 @@ LogicalProject(k=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(a, d), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d, e]])
+- Calc(select=[d, e])
- +- Join(joinType=[LeftSemiJoin], where=[AND(=(f, k), =(e, j))], select=[d, e, f])
+ +- Join(joinType=[LeftSemiJoin], where=[AND(=(f, k), =(e, j))], select=[d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[f, e]])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
+- Exchange(distribution=[hash[k, j]])
@@ -1820,9 +1820,9 @@ LogicalProject(j=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(k, c))], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[AND(=(b, j), =(k, c))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b, c]])
-: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
@@ -1853,9 +1853,9 @@ LogicalProject(j=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(b, j)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(b, j)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
-: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+: +- Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
@@ -1887,12 +1887,12 @@ LogicalProject(j=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftSemiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
+- Calc(select=[d])
- +- Join(joinType=[LeftSemiJoin], where=[=(e, j)], select=[d, e])
+ +- Join(joinType=[LeftSemiJoin], where=[=(e, j)], select=[d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[e]])
: +- Calc(select=[d, e])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -1923,11 +1923,11 @@ LogicalFilter(condition=[AND(=($cor0.a, $0), <($1, 100))])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
-: +- Join(joinType=[LeftAntiJoin], where=[=(a, i)], select=[a, b, c])
+: +- Join(joinType=[LeftAntiJoin], where=[=(a, i)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
-: : +- Join(joinType=[LeftAntiJoin], where=[=(b, j)], select=[a, b, c])
+: : +- Join(joinType=[LeftAntiJoin], where=[=(b, j)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: : :- Exchange(distribution=[hash[b]])
: : : +- Calc(select=[a, b, c], where=[>=(CAST(c), 1:BIGINT)])
: : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -1963,11 +1963,11 @@ LogicalFilter(condition=[<($1, 100)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c, d, e, f])
+Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
-: +- Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c, d, e, f])
+: +- Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[single])
-: : +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f])
+: : +- Join(joinType=[InnerJoin], where=[=(a, d)], select=[a, b, c, d, e, f], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: : :- Exchange(distribution=[hash[a]])
: : : +- Calc(select=[a, b, c], where=[>=(b, 1)])
: : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2009,12 +2009,12 @@ LogicalProject(j=[$1])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
+- Calc(select=[d])
- +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(e, j), IS NULL(e), IS NULL(j)), =(i, d))], select=[d, e])
+ +- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(e, j), IS NULL(e), IS NULL(j)), =(i, d))], select=[d, e], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[d]])
: +- Calc(select=[d, e])
: +- TableSourceScan(table=[[r, source: [TestTableSource(d, e, f)]]], fields=[d, e, f])
@@ -2040,7 +2040,7 @@ LogicalFilter(condition=[<($cor0.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[<(a, d)], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[<(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2066,7 +2066,7 @@ LogicalFilter(condition=[<($cor0.a, 10)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftAntiJoin], where=[$f3], select=[a, b, c, $f3])
++- Join(joinType=[LeftAntiJoin], where=[$f3], select=[a, b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c, <(a, 10) AS $f3])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2092,7 +2092,7 @@ LogicalFilter(condition=[=($cor0.a, $0)])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[=(a, d)], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[d]])
@@ -2117,7 +2117,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
<Resource name="planAfter">
<![CDATA[
Calc(select=[+(a, 10) AS EXPR$0, c])
-+- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, c])
++- Join(joinType=[LeftSemiJoin], where=[$f0], select=[a, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, c], where=[AND(<=(b, 10), NOT(LIKE(c, _UTF-16LE'abc')))])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2145,7 +2145,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2172,7 +2172,7 @@ LogicalTableScan(table=[[r, source: [TestTableSource(d, e, f)]]])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[$f0], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c], where=[>(b, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2205,9 +2205,9 @@ LogicalProject(i=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, i), IS NULL(a), IS NULL(i)), =(b, j))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, i), IS NULL(a), IS NULL(i)), =(b, j))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
-: +- Join(joinType=[LeftAntiJoin], where=[=(a, d)], select=[a, b, c])
+: +- Join(joinType=[LeftAntiJoin], where=[=(a, d)], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
: :- Exchange(distribution=[hash[a]])
: : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: +- Exchange(distribution=[hash[d]])
@@ -2237,7 +2237,7 @@ LogicalProject(EXPR$0=[SUBSTRING($2, 1, 5)])
<Resource name="planAfter">
<![CDATA[
Calc(select=[+(a, 10) AS EXPR$0, c])
-+- Join(joinType=[LeftAntiJoin], where=[AND(OR(=($f3, EXPR$0), IS NULL($f3), IS NULL(EXPR$0)), =($f4, e))], select=[a, c, $f3, $f4])
++- Join(joinType=[LeftAntiJoin], where=[AND(OR(=($f3, EXPR$0), IS NULL($f3), IS NULL(EXPR$0)), =($f4, e))], select=[a, c, $f3, $f4], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f4]])
: +- Calc(select=[a, c, SUBSTRING(c, 1, 5) AS $f3, +(b, 1) AS $f4])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2271,17 +2271,17 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b])
-+- Join(joinType=[LeftAntiJoin], where=[AND(OR(=($f3, d), IS NULL(d)), =(c, f))], select=[b, c, $f3])
++- Join(joinType=[LeftAntiJoin], where=[AND(OR(=($f3, d), IS NULL(d)), =(c, f))], select=[b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[c]])
: +- Calc(select=[b, c, CASE(OR(=(c0, 0), AND(<>(c0, 0), IS NULL(i0), >=(ck, c0), IS NOT NULL(a))), 1, OR(=(c1, 0), AND(<>(c1, 0), IS NULL(i), >=(ck0, c1), IS NOT NULL(a))), 2, 3) AS $f3])
- : +- Join(joinType=[LeftOuterJoin], where=[=(a, EXPR$0)], select=[a, b, c, c0, ck, i0, c1, ck0, EXPR$0, i])
+ : +- Join(joinType=[LeftOuterJoin], where=[=(a, EXPR$0)], select=[a, b, c, c0, ck, i0, c1, ck0, EXPR$0, i], leftInputSpec=[NoUniqueKey], rightInputSpec=[HasUniqueKey])
: :- Exchange(distribution=[hash[a]])
- : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0, ck, i0, c1, ck0])
+ : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0, ck, i0, c1, ck0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : :- Exchange(distribution=[single])
: : : +- Calc(select=[a, b, c, c0, ck, i0])
- : : : +- Join(joinType=[LeftOuterJoin], where=[=(a, i)], select=[a, b, c, c0, ck, i, i0])
+ : : : +- Join(joinType=[LeftOuterJoin], where=[=(a, i)], select=[a, b, c, c0, ck, i, i0], leftInputSpec=[NoUniqueKey], rightInputSpec=[HasUniqueKey])
: : : :- Exchange(distribution=[hash[a]])
- : : : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0, ck])
+ : : : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, c0, ck], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : : : :- Exchange(distribution=[single])
: : : : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
: : : : +- Exchange(distribution=[single])
@@ -2327,7 +2327,7 @@ LogicalProject(d=[$0], f=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), OR(=(c, f), IS NULL(c), IS NULL(f)), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), OR(=(c, f), IS NULL(c), IS NULL(f)), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[e]])
@@ -2353,7 +2353,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), >(b, e))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), >(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2380,7 +2380,7 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), $f3)], select=[a, b, c, $f3])
++- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), $f3)], select=[a, b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c, >(b, 10) AS $f3])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2407,7 +2407,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[hash[e]])
@@ -2433,7 +2433,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), =(b, e))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), =(b, e))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[b]])
: +- Calc(select=[a, b, c], where=[>(b, 1)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2459,7 +2459,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2484,7 +2484,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c], where=[AND(>(b, 10), LIKE(c, _UTF-16LE'abc'))])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2517,17 +2517,17 @@ LogicalProject(e=[$1], d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[b])
-+- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(b, e), IS NULL(b), IS NULL(e)), OR(=($f3, d), IS NULL(d)))], select=[b, $f3])
++- Join(joinType=[LeftAntiJoin], where=[AND(OR(=(b, e), IS NULL(b), IS NULL(e)), OR(=($f3, d), IS NULL(d)))], select=[b, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[b, CASE(OR(=(c0, 0), AND(<>(c0, 0), IS NULL(i0), >=(ck, c0), IS NOT NULL(a))), 1, OR(=(c1, 0), AND(<>(c1, 0), IS NULL(i), >=(ck0, c1), IS NOT NULL(a))), 2, 3) AS $f3])
- : +- Join(joinType=[LeftOuterJoin], where=[=(a, j)], select=[a, b, c0, ck, i0, c, ck0, j, i])
+ : +- Join(joinType=[LeftOuterJoin], where=[=(a, j)], select=[a, b, c0, ck, i0, c, ck0, j, i], leftInputSpec=[NoUniqueKey], rightInputSpec=[HasUniqueKey])
: :- Exchange(distribution=[hash[a]])
- : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c0, ck, i0, c, ck0])
+ : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c0, ck, i0, c, ck0], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : :- Exchange(distribution=[single])
: : : +- Calc(select=[a, b, c0, ck, i0])
- : : : +- Join(joinType=[LeftOuterJoin], where=[=(a, i)], select=[a, b, c, ck, i, i0])
+ : : : +- Join(joinType=[LeftOuterJoin], where=[=(a, i)], select=[a, b, c, ck, i, i0], leftInputSpec=[NoUniqueKey], rightInputSpec=[HasUniqueKey])
: : : :- Exchange(distribution=[hash[a]])
- : : : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, ck])
+ : : : : +- Join(joinType=[InnerJoin], where=[true], select=[a, b, c, ck], leftInputSpec=[NoUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey])
: : : : :- Exchange(distribution=[single])
: : : : : +- Calc(select=[a, b])
: : : : : +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2571,7 +2571,7 @@ LogicalProject(d=[$0], f=[$2])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), OR(=(c, f), IS NULL(c), IS NULL(f)))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[AND(OR(=(a, d), IS NULL(a), IS NULL(d)), OR(=(c, f), IS NULL(c), IS NULL(f)))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2596,7 +2596,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
+- Exchange(distribution=[single])
@@ -2622,7 +2622,7 @@ LogicalProject(d=[$0])
</Resource>
<Resource name="planAfter">
<![CDATA[
-Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c])
+Join(joinType=[LeftAntiJoin], where=[OR(=(a, d), IS NULL(a), IS NULL(d))], select=[a, b, c], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c], where=[>(b, 10)])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
@@ -2649,7 +2649,7 @@ LogicalProject(d=[$0])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b, c])
-+- Join(joinType=[LeftAntiJoin], where=[OR(=($f3, d), IS NULL($f3), IS NULL(d))], select=[a, b, c, $f3])
++- Join(joinType=[LeftAntiJoin], where=[OR(=($f3, d), IS NULL($f3), IS NULL(d))], select=[a, b, c, $f3], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[single])
: +- Calc(select=[a, b, c, *(a, b) AS $f3])
: +- TableSourceScan(table=[[l, source: [TestTableSource(a, b, c)]]], fields=[a, b, c])
diff --git a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.xml b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.xml
index 6cc4d22..de3380f 100644
--- a/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.xml
+++ b/flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.xml
@@ -35,7 +35,7 @@ LogicalProject(a=[$0], b=[$6])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b])
-+- Join(joinType=[InnerJoin], where=[AND(=(a, a0), =($f5, $f50))], select=[a, $f5, a0, b, $f50])
++- Join(joinType=[InnerJoin], where=[AND(=(a, a0), =($f5, $f50))], select=[a, $f5, a0, b, $f50], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, $f5]])
: +- Calc(select=[a, PROCTIME_MATERIALIZE(proctime) AS $f5])
: +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c, proctime, rowtime])
@@ -64,7 +64,7 @@ LogicalProject(a=[$0], b=[$6])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b])
-+- Join(joinType=[InnerJoin], where=[AND(=(a, a0), =(rowtime0, rowtime00))], select=[a, rowtime0, a0, b, rowtime00])
++- Join(joinType=[InnerJoin], where=[AND(=(a, a0), =(rowtime0, rowtime00))], select=[a, rowtime0, a0, b, rowtime00], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[a, rowtime0]])
: +- Calc(select=[a, CAST(rowtime) AS rowtime0])
: +- DataStreamScan(table=[[_DataStreamTable_0]], fields=[a, b, c, proctime, rowtime])
diff --git a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/api/stream/ExplainTest.scala b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/api/stream/ExplainTest.scala
index e745d59..d0f6460 100644
--- a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/api/stream/ExplainTest.scala
+++ b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/api/stream/ExplainTest.scala
@@ -59,9 +59,7 @@ class ExplainTest(extended: Boolean) extends TableTestBase {
util.verifyExplain("SELECT COUNT(*) FROM MyTable1 GROUP BY a", extended)
}
- @Test(expected = classOf[TableException])
- // TODO remove expected TableException after translateToPlanInternal method is implemented
- // in StreamExecJoin
+ @Test
def testExplainWithJoin(): Unit = {
util.verifyExplain("SELECT a, b, c, e, f FROM MyTable1, MyTable2 WHERE a = d", extended)
}
diff --git a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/JoinTest.scala b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/JoinTest.scala
index 4fbe7dc..ace8aa9 100644
--- a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/JoinTest.scala
+++ b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/JoinTest.scala
@@ -38,13 +38,6 @@ class JoinTest extends TableTestBase {
}
@Test
- def testInnerJoinWithMiniBatch(): Unit = {
- util.tableEnv.getConfig.getConf
- .setLong(TableConfigOptions.SQL_EXEC_MINIBATCH_ALLOW_LATENCY, 1000L)
- util.verifyPlanWithTrait( "SELECT a1, b1 FROM A JOIN B ON a1 = b1")
- }
-
- @Test
def testInnerJoinWithEqualPk(): Unit = {
val query1 = "SELECT SUM(a2) AS a2, a1 FROM A GROUP BY a1"
val query2 = "SELECT SUM(b2) AS b2, b1 FROM B GROUP BY b1"
diff --git a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.scala b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.scala
index e3b3b00..bcc540f 100644
--- a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.scala
+++ b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/plan/stream/sql/join/WindowJoinTest.scala
@@ -133,6 +133,7 @@ class WindowJoinTest extends TableTestBase {
@Test
def testJoinWithEquiProcTime(): Unit = {
+ // TODO: this should be translated into window join
val sqlQuery =
"""
|SELECT t1.a, t2.b FROM MyTable t1, MyTable2 t2 WHERE
@@ -144,6 +145,7 @@ class WindowJoinTest extends TableTestBase {
@Test
def testJoinWithEquiRowTime(): Unit = {
+ // TODO: this should be translated into window join
val sqlQuery =
"""
|SELECT t1.a, t2.b FROM MyTable t1, MyTable2 t2 WHERE
diff --git a/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/runtime/stream/sql/JoinITCase.scala b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/runtime/stream/sql/JoinITCase.scala
new file mode 100644
index 0000000..c9fcfcb
--- /dev/null
+++ b/flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/runtime/stream/sql/JoinITCase.scala
@@ -0,0 +1,1109 @@
+/*
+ * 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.runtime.stream.sql
+
+import org.apache.flink.api.scala._
+import org.apache.flink.streaming.api.TimeCharacteristic
+import org.apache.flink.table.api.scala._
+import org.apache.flink.table.runtime.utils.StreamingWithStateTestBase.StateBackendMode
+import org.apache.flink.table.runtime.utils._
+import org.apache.flink.types.Row
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
+
+import scala.collection.{Seq, mutable}
+
+@RunWith(classOf[Parameterized])
+class JoinITCase(state: StateBackendMode) extends StreamingWithStateTestBase(state) {
+
+ val smallTuple5Data = List(
+ (1, 1L, 0, "Hallo", 1L),
+ (2, 2L, 1, "Hallo Welt", 2L),
+ (2, 3L, 2, "Hallo Welt wie", 1L),
+ (3, 4L, 3, "Hallo Welt wie gehts?", 2L),
+ (3, 5L, 4, "ABC", 2L),
+ (3, 6L, 5, "BCD", 3L)
+ )
+
+ val tuple3Data = List(
+ (1, 1L, "Hi"),
+ (2, 2L, "Hello"),
+ (3, 2L, "Hello world")
+ )
+
+ val dataCannotBeJoin = List(
+ (2, 3L, 2, "Hallo Welt wie", 1L),
+ (3, 4L, 3, "Hallo Welt wie gehts?", 2L),
+ (3, 5L, 4, "ABC", 2L),
+ (3, 6L, 5, "BCD", 3L)
+ )
+
+ override def before(): Unit = {
+ super.before()
+ val tableA = failingDataSource(TestData.smallTupleData3)
+ .toTable(tEnv, 'a1, 'a2, 'a3)
+ val tableB = failingDataSource(TestData.tupleData5)
+ .toTable(tEnv, 'b1, 'b2, 'b3, 'b4, 'b5)
+ tEnv.registerTable("A", tableA)
+ tEnv.registerTable("B", tableB)
+ }
+
+
+
+ // Tests for inner join.
+ override def after(): Unit = {}
+
+
+ /** test non-window inner join **/
+ @Test
+ def testNonWindowInnerJoin(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long, String)]
+ data1.+=((1, 1L, "Hi1"))
+ data1.+=((1, 2L, "Hi2"))
+ data1.+=((1, 2L, "Hi2"))
+ data1.+=((1, 5L, "Hi3"))
+ data1.+=((2, 7L, "Hi5"))
+ data1.+=((1, 9L, "Hi6"))
+ data1.+=((1, 8L, "Hi8"))
+ data1.+=((3, 8L, "Hi9"))
+
+ val data2 = new mutable.MutableList[(Int, Long, String)]
+ data2.+=((1, 1L, "HiHi"))
+ data2.+=((2, 2L, "HeHe"))
+ data2.+=((3, 2L, "HeHe"))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b, 'c)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b, 'c)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t2.a, t2.c, t1.c
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b, c FROM T1
+ |) as t1
+ |JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b, c FROM T2
+ |) as t2
+ |ON t1.a = t2.a AND t1.b > t2.b
+ |""".stripMargin
+
+ val sink = new TestingAppendSink
+ tEnv.sqlQuery(sqlQuery).toAppendStream[Row].addSink(sink)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,HiHi,Hi2",
+ "1,HiHi,Hi2",
+ "1,HiHi,Hi3",
+ "1,HiHi,Hi6",
+ "1,HiHi,Hi8",
+ "2,HeHe,Hi5")
+
+ assertEquals(expected.sorted, sink.getAppendResults.sorted)
+ }
+
+ @Test
+ def testIsNullInnerJoinWithNullCond(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long, String)]
+ data1.+=((1, 1L, "Hi1"))
+ data1.+=((1, 2L, "Hi2"))
+ data1.+=((1, 2L, "Hi2"))
+ data1.+=((1, 5L, "Hi3"))
+ data1.+=((2, 7L, "Hi5"))
+ data1.+=((1, 9L, "Hi6"))
+ data1.+=((1, 8L, "Hi8"))
+ data1.+=((3, 8L, "Hi9"))
+
+ val data2 = new mutable.MutableList[(Int, Long, String)]
+ data2.+=((1, 1L, "HiHi"))
+ data2.+=((2, 2L, "HeHe"))
+ data2.+=((3, 2L, "HeHe"))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b, 'c)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b, 'c)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t2.a, t2.c, t1.c
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b, c FROM T1
+ |) as t1
+ |JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b, c FROM T2
+ |) as t2
+ |ON
+ | ((t1.a is null AND t2.a is null) OR
+ | (t1.a = t2.a))
+ | AND t1.b > t2.b
+ |""".stripMargin
+
+ val sink = new TestingAppendSink
+ tEnv.sqlQuery(sqlQuery).toAppendStream[Row].addSink(sink)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,HiHi,Hi2",
+ "1,HiHi,Hi2",
+ "1,HiHi,Hi3",
+ "1,HiHi,Hi6",
+ "1,HiHi,Hi8",
+ "2,HeHe,Hi5",
+ "null,HeHe,Hi9")
+ assertEquals(expected.sorted, sink.getAppendResults.sorted)
+ }
+
+ @Test
+ def testJoin(): Unit = {
+
+ val sqlQuery = "SELECT a3, b4 FROM A, B WHERE a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testInnerJoin(): Unit = {
+ val ds1 = failingDataSource(tuple3Data).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(smallTuple5Data).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("ds1", ds1)
+ tEnv.registerTable("ds2", ds2)
+ val query = "SELECT b, c, e, g FROM ds1 JOIN ds2 ON b = e"
+
+ val sink = new TestingAppendSink
+ tEnv.sqlQuery(query).toAppendStream[Row].addSink(sink)
+ env.execute()
+
+ val expected = Seq("1,Hi,1,Hallo", "2,Hello world,2,Hallo Welt", "2,Hello,2,Hallo Welt")
+ assertEquals(expected.sorted, sink.getAppendResults.sorted)
+ }
+
+ @Test
+ def testInnerJoin2(): Unit = {
+ val query = "SELECT a1, b1 FROM A JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("3,3", "1,1", "3,3", "2,2", "3,3", "2,2")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testJoinWithFilter(): Unit = {
+ val sqlQuery = "SELECT a3, b4 FROM A, B WHERE a2 = b2 AND a2 < 2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hi,Hallo")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testInnerJoinWithNonEquiJoinPredicate(): Unit = {
+ val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE b = e AND a < 6 AND h < b"
+
+ val ds1 = failingDataSource(TestData.tupleData3).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(TestData.tupleData5).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("Table3", ds1)
+ tEnv.registerTable("Table5", ds2)
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hello world, how are you?,Hallo Welt wie", "I am fine.,Hallo Welt wie")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testJoinWithMultipleKeys(): Unit = {
+ val sqlQuery = "SELECT c, g FROM Table3, Table5 WHERE a = d AND b = h"
+
+ val ds1 = failingDataSource(TestData.tupleData3).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(TestData.tupleData5).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("Table3", ds1)
+ tEnv.registerTable("Table5", ds2)
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq(
+ "Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt wie gehts?", "Hello world,ABC",
+ "I am fine.,HIJ", "I am fine.,IJK")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testJoinWithAlias(): Unit = {
+ val sqlQuery =
+ "SELECT B.b5, T.`1-_./Ü` FROM (SELECT a1, a2, a3 AS `1-_./Ü` FROM A) AS T, B " +
+ "WHERE a1 = b1 AND a1 < 4"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,Hi", "2,Hello", "1,Hello",
+ "2,Hello world", "2,Hello world", "3,Hello world")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testDataStreamJoinWithAggregation(): Unit = {
+ val sqlQuery = "SELECT COUNT(b4), COUNT(a2) FROM A, B WHERE a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("6,6")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftOuterJoin(): Unit = {
+ val ds1 = failingDataSource(tuple3Data).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(dataCannotBeJoin).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("ds1", ds1)
+ tEnv.registerTable("ds2", ds2)
+ val query = "SELECT b, c, e, g FROM ds1 LEFT OUTER JOIN ds2 ON b = e"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,Hi,null,null", "2,Hello world,null,null", "2,Hello,null,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftOuterJoinWithRetraction(): Unit = {
+ val ds1 = failingDataSource(tuple3Data).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(smallTuple5Data).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("ds1", ds1)
+ tEnv.registerTable("ds2", ds2)
+ val query = "SELECT b, c, e, g FROM ds1 LEFT OUTER JOIN ds2 ON b = e"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,Hi,1,Hallo", "2,Hello world,2,Hallo Welt", "2,Hello,2,Hallo Welt")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testStreamJoinWithSameRecord(): Unit = {
+ val data1 = List(
+ (1, 1),
+ (1, 1),
+ (2, 2),
+ (2, 2),
+ (3, 3),
+ (3, 3),
+ (4, 4),
+ (4, 4),
+ (5, 5),
+ (5, 5))
+
+ val data2 = List(
+ (1, 1),
+ (2, 2),
+ (3, 3),
+ (4, 4),
+ (5, 5),
+ (6, 6),
+ (7, 7),
+ (8, 8),
+ (9, 9),
+ (10, 10))
+
+ val table1 = failingDataSource(data1).toTable(tEnv, 'pk, 'a)
+ val table2 = failingDataSource(data2).toTable(tEnv, 'pk, 'a)
+ tEnv.registerTable("ds1", table1)
+ tEnv.registerTable("ds2", table2)
+
+ val sql =
+ """
+ |SELECT
+ | ds1.pk as leftPk,
+ | ds1.a as leftA,
+ | ds2.pk as rightPk,
+ | ds2.a as rightA
+ |FROM ds1 JOIN ds2 ON ds1.pk = ds2.pk
+ """.stripMargin
+
+ val sink = new TestingAppendSink
+ tEnv.sqlQuery(sql).toAppendStream[Row].addSink(sink)
+ env.execute()
+
+ val expected = Seq("1,1,1,1", "1,1,1,1",
+ "2,2,2,2", "2,2,2,2",
+ "3,3,3,3", "3,3,3,3",
+ "4,4,4,4", "4,4,4,4",
+ "5,5,5,5", "5,5,5,5")
+ assertEquals(expected.sorted, sink.getAppendResults.sorted)
+ }
+
+ @Test
+ def testFullOuterJoin(): Unit = {
+ val sqlQuery = "SELECT a3, b4 FROM A FULL OUTER JOIN B ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt",
+ "null,Hallo Welt wie", "null,Hallo Welt wie gehts?", "null,ABC", "null,BCD",
+ "null,CDE", "null,DEF", "null,EFG", "null,FGH", "null,GHI", "null,HIJ",
+ "null,IJK", "null,JKL", "null,KLM")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftOuterJoin2(): Unit = {
+ val sqlQuery = "SELECT c, g FROM Table5 LEFT OUTER JOIN Table3 ON b = e"
+
+ val ds1 = failingDataSource(TestData.smallTupleData3).toTable(tEnv, 'a, 'b, 'c)
+ val ds2 = failingDataSource(TestData.tupleData5).toTable(tEnv, 'd, 'e, 'f, 'g, 'h)
+ tEnv.registerTable("Table3", ds1)
+ tEnv.registerTable("Table5", ds2)
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt",
+ "null,Hallo Welt wie", "null,Hallo Welt wie gehts?", "null,ABC", "null,BCD",
+ "null,CDE", "null,DEF", "null,EFG", "null,FGH", "null,GHI", "null,HIJ",
+ "null,IJK", "null,JKL", "null,KLM")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightOuterJoin(): Unit = {
+ val sqlQuery = "SELECT a3, b4 FROM A RIGHT OUTER JOIN B ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("Hi,Hallo", "Hello,Hallo Welt", "Hello world,Hallo Welt",
+ "null,Hallo Welt wie", "null,Hallo Welt wie gehts?", "null,ABC", "null,BCD",
+ "null,CDE", "null,DEF", "null,EFG", "null,FGH", "null,GHI", "null,HIJ",
+ "null,IJK", "null,JKL", "null,KLM")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testInnerJoinWithEqualPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) JOIN ($query2) ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1", "2,2", "3,3")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testInnerJoinWithPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) JOIN ($query2) ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1,1,1")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinNonEqui(): Unit = {
+ val query = "SELECT a1, b1 FROM A LEFT JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("3,null", "1,null", "2,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithEqualPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) LEFT JOIN ($query2) ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,null", "3,null", "2,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithRightNotPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) LEFT JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,null", "3,null", "2,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) LEFT JOIN ($query2) ON a2 = b2 AND a1 > b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1,null,null", "3,2,null,null", "2,2,null,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoin(): Unit = {
+ val query = "SELECT a1, b1 FROM A LEFT JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1", "2,2", "3,3", "2,2", "3,3", "3,3")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithEqualPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) LEFT JOIN ($query2) ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("2,2", "1,1", "3,3")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithRightNotPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) LEFT JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("3,3", "3,3", "3,3", "2,2", "2,2", "1,1")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testLeftJoinWithPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) LEFT JOIN ($query2) ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1,1,1", "3,2,null,null", "2,2,null,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinNonEqui(): Unit = {
+ val query = "SELECT a1, b1 FROM A RIGHT JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,2", "null,1", "null,3", "null,3", "null,2", "null,5", "null,3",
+ "null,5", "null,4", "null,5", "null,4", "null,5", "null,4", "null,5", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithEqualPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) RIGHT JOIN ($query2) ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,1", "null,3", "null,2", "null,5", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithRightNotPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) RIGHT JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,2", "null,1", "null,3", "null,2", "null,3", "null,5", "null,5",
+ "null,3", "null,5", "null,5", "null,4", "null,5", "null,4", "null,4", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) RIGHT JOIN ($query2) ON a2 = b2 AND a1 > b1"
+
+ env.setParallelism(1)
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,null,3,15", "null,null,4,34", "null,null,2,5", "null,null,5,65",
+ "null,null,1,1")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoin(): Unit = {
+ val query = "SELECT a1, b1 FROM A RIGHT JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("2,2", "3,3", "3,3", "2,2", "3,3", "null,5", "null,4", "1,1", "null,5",
+ "null,4", "null,5", "null,5", "null,5", "null,4", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithEqualPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) RIGHT JOIN ($query2) ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1", "2,2", "null,5", "3,3", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithRightNotPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) RIGHT JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,4", "null,4", "null,4", "null,4", "null,5", "null,5", "null,5",
+ "null,5", "null,5", "1,1", "2,2", "3,3", "3,3", "3,3", "2,2")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testRightJoinWithPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) RIGHT JOIN ($query2) ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,null,3,15", "null,null,4,34", "null,null,5,65",
+ "1,1,1,1", "null,null,2,5")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinNonEqui(): Unit = {
+ val query = "SELECT a1, b1 FROM A FULL JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,null", "3,null", "2,null", "null,3", "null,2", "null,2", "null,3",
+ "null,5", "null,3", "null,5", "null,4", "null,5", "null,4", "null,1", "null,5", "null,4",
+ "null,5", "null,4")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinWithEqualPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) FULL JOIN ($query2) ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,2", "null,5", "null,3", "null,4", "3,null", "1,null", "null,1", "2," +
+ "null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinWithFullNotPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) FULL JOIN B ON a1 = b1 AND a2 > b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,2", "null,1", "null,2", "null,5", "null,5", "null,5", "null,5",
+ "null,5", "null,3", "null,3", "null,3", "null,4", "null,4", "null,4", "null,4", "3,null",
+ "1,null", "2,null")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinWithPkNonEqui(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) FULL JOIN ($query2) ON a2 = b2 AND a1 > b1"
+
+ env.setParallelism(1)
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1,null,null", "null,null,5,65", "null,null,2,5", "2,2,null,null", "3,2," +
+ "null,null", "null,null,3,15", "null,null,4,34", "null,null,1,1")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoin(): Unit = {
+ val query = "SELECT a1, b1 FROM A FULL JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("1,1", "null,5", "null,5", "null,5", "null,4", "null,5", "null,4", "null," +
+ "5", "null,4", "null,4", "2,2", "2,2", "3,3", "3,3", "3,3")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinWithEqualPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, b1 FROM ($query1) FULL JOIN ($query2) ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,4", "1,1", "3,3", "2,2", "null,5")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testFullJoinWithFullNotPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query = s"SELECT a1, b1 FROM ($query1) FULL JOIN B ON a1 = b1"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,4", "null,4", "null,4", "null,4", "null,5", "null,5", "null,5",
+ "null,5", "null,5", "3,3", "3,3", "3,3", "1,1", "2,2", "2,2")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def FullJoinWithPk(): Unit = {
+ val query1 = "SELECT SUM(a2) AS a2, a1 FROM A group by a1"
+ val query2 = "SELECT SUM(b2) AS b2, b1 FROM B group by b1"
+ val query = s"SELECT a1, a2, b1, b2 FROM ($query1) FULL JOIN ($query2) ON a2 = b2"
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(query).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = Seq("null,null,3,15", "null,null,4,34", "null,null,5,65", "3,2,null,null", "2," +
+ "2,null,null", "null,null,2,5", "1,1,1,1")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullLeftOuterJoin(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |LEFT OUTER JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2
+ |ON t1.a = t2.a
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "4,2,null,null",
+ "null,8,null,null"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullLeftOuterJoinWithNullCond(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |LEFT OUTER JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2
+ |ON t1.a = t2.a OR (t1.a is null AND t2.a is null)
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "4,2,null,null",
+ "null,8,null,2"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullRightOuterJoin(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |RIGHT OUTER JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2 ON t1.a = t2.a
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "null,null,2,2",
+ "null,null,null,2"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullRightOuterJoinWithNullCond(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |RIGHT OUTER JOIN (
+ | SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2
+ |ON t1.a = t2.a OR (t1.a is null AND t2.a is null)
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "null,null,2,2",
+ "null,8,null,2"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullFullOuterJoin(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |FULL OUTER JOIN (
+ SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2
+ |ON t1.a = t2.a
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "null,null,2,2",
+ "4,2,null,null",
+ "null,8,null,null",
+ "null,null,null,2"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testNullFullOuterJoinWithNullCond(): Unit = {
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1.+=((1, 1L))
+ data1.+=((3, 8L))
+ data1.+=((4, 2L))
+
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2.+=((1, 1L))
+ data2.+=((2, 2L))
+ data2.+=((3, 2L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'b)
+
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sqlQuery =
+ """
+ |SELECT t1.a, t1.b, t2.a, t2.b
+ |FROM (
+ SELECT if(a = 3, cast(null as int), a) as a, b FROM T1
+ |) as t1
+ |FULL OUTER JOIN (
+ SELECT if(a = 3, cast(null as int), a) as a, b FROM T2
+ |) as t2
+ |ON t1.a = t2.a
+ |OR (t1.a is null AND t2.a is null)
+ |""".stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sqlQuery).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = mutable.MutableList(
+ "1,1,1,1",
+ "null,null,2,2",
+ "4,2,null,null",
+ "null,8,null,2"
+ )
+
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testJoinWithoutWatermark(): Unit = {
+ // NOTE: Different from AggregateITCase, we do not set stream time characteristic
+ // of environment to event time, so that emitWatermark() actually does nothing.
+ env.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime)
+
+ val data1 = new mutable.MutableList[(Int, Long)]
+ data1 .+= ((1, 1L))
+ data1 .+= ((2, 2L))
+ data1 .+= ((3, 3L))
+ val data2 = new mutable.MutableList[(Int, Long)]
+ data2 .+= ((1, -1L))
+ data2 .+= ((2, -2L))
+ data2 .+= ((3, -3L))
+
+ val t1 = failingDataSource(data1).toTable(tEnv, 'a, 'b)
+ tEnv.registerTable("T1", t1)
+ val t2 = failingDataSource(data2).toTable(tEnv, 'a, 'c)
+ tEnv.registerTable("T2", t2)
+
+ val t3 = tEnv.sqlQuery(
+ "select T1.a, b, c from T1, T2 WHERE T1.a = T2.a")
+ val sink = new TestingRetractSink
+ t3.toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+ val expected = List("1,1,-1", "2,2,-2", "3,3,-3")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+
+ @Test
+ def testBigDataOfJoin(): Unit = {
+ env.setParallelism(1)
+
+ val data = new mutable.MutableList[(Int, Long, String)]
+ for (i <- 0 until 500) {
+ data.+=((i % 10, i, i.toString))
+ }
+
+ val t1 = failingDataSource(data).toTable(tEnv, 'a, 'b, 'c)
+ val t2 = failingDataSource(data).toTable(tEnv, 'd, 'e, 'f)
+ tEnv.registerTable("T1", t1)
+ tEnv.registerTable("T2", t2)
+
+ val sql =
+ """
+ |SELECT COUNT(DISTINCT b) FROM (SELECT b FROM T1, T2 WHERE b = e)
+ """.stripMargin
+
+ val sink = new TestingRetractSink
+ tEnv.sqlQuery(sql).toRetractStream[Row].addSink(sink).setParallelism(1)
+ env.execute()
+
+ val expected = List("500")
+ assertEquals(expected.sorted, sink.getRetractResults.sorted)
+ }
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/StreamingJoinOperator.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/StreamingJoinOperator.java
new file mode 100644
index 0000000..849eeec
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/StreamingJoinOperator.java
@@ -0,0 +1,504 @@
+/*
+ * 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.runtime.join.stream;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.TimestampedCollector;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.dataformat.BaseRow;
+import org.apache.flink.table.dataformat.BinaryRow;
+import org.apache.flink.table.dataformat.GenericRow;
+import org.apache.flink.table.dataformat.JoinedRow;
+import org.apache.flink.table.dataformat.util.BaseRowUtil;
+import org.apache.flink.table.generated.GeneratedJoinCondition;
+import org.apache.flink.table.generated.JoinCondition;
+import org.apache.flink.table.runtime.join.NullAwareJoinHelper;
+import org.apache.flink.table.runtime.join.stream.state.JoinInputSideSpec;
+import org.apache.flink.table.runtime.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.join.stream.state.JoinRecordStateViews;
+import org.apache.flink.table.runtime.join.stream.state.OuterJoinRecordStateView;
+import org.apache.flink.table.runtime.join.stream.state.OuterJoinRecordStateViews;
+import org.apache.flink.table.typeutils.BaseRowTypeInfo;
+import org.apache.flink.util.IterableIterator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Streaming unbounded Join operator which supports INNER/LEFT/RIGHT/FULL JOIN.
+ */
+public class StreamingJoinOperator extends AbstractStreamOperator<BaseRow>
+ implements TwoInputStreamOperator<BaseRow, BaseRow, BaseRow> {
+
+ private static final long serialVersionUID = -376944622236540545L;
+
+ private final BaseRowTypeInfo leftType;
+ private final BaseRowTypeInfo rightType;
+ private final GeneratedJoinCondition generatedJoinCondition;
+
+ private final JoinInputSideSpec leftInputSideSpec;
+ private final JoinInputSideSpec rightInputSideSpec;
+
+ // whether left side is outer side, e.g. left is outer but right is not when LEFT OUTER JOIN
+ private final boolean leftIsOuter;
+ // whether right side is outer side, e.g. right is outer but left is not when RIGHT OUTER JOIN
+ private final boolean rightIsOuter;
+
+ /**
+ * Should filter null keys.
+ */
+ private final int[] nullFilterKeys;
+
+ /**
+ * No keys need to filter null.
+ */
+ private final boolean nullSafe;
+
+ /**
+ * Filter null to all keys.
+ */
+ private final boolean filterAllNulls;
+
+ private final long minRetentionTime;
+ private final boolean stateCleaningEnabled;
+
+ private transient JoinCondition joinCondition;
+ private transient TimestampedCollector<BaseRow> collector;
+
+ private transient JoinedRow outRow;
+ private transient BaseRow leftNullRow;
+ private transient BaseRow rightNullRow;
+
+ // left join state
+ private transient JoinRecordStateView leftRecordStateView;
+ // right join state
+ private transient JoinRecordStateView rightRecordStateView;
+
+ public StreamingJoinOperator(
+ BaseRowTypeInfo leftType,
+ BaseRowTypeInfo rightType,
+ GeneratedJoinCondition generatedJoinCondition,
+ JoinInputSideSpec leftInputSideSpec,
+ JoinInputSideSpec rightInputSideSpec,
+ boolean leftIsOuter,
+ boolean rightIsOuter,
+ boolean[] filterNullKeys,
+ long minRetentionTime) {
+ this.leftType = leftType;
+ this.rightType = rightType;
+ this.generatedJoinCondition = generatedJoinCondition;
+ this.leftInputSideSpec = leftInputSideSpec;
+ this.rightInputSideSpec = rightInputSideSpec;
+ this.minRetentionTime = minRetentionTime;
+ this.stateCleaningEnabled = minRetentionTime > 1;
+ this.leftIsOuter = leftIsOuter;
+ this.rightIsOuter = rightIsOuter;
+ this.nullFilterKeys = NullAwareJoinHelper.getNullFilterKeys(filterNullKeys);
+ this.nullSafe = nullFilterKeys.length == 0;
+ this.filterAllNulls = nullFilterKeys.length == filterNullKeys.length;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ this.joinCondition = new JoinConditionWithNullFilters(
+ generatedJoinCondition.newInstance(getRuntimeContext().getUserCodeClassLoader()));
+
+ this.collector = new TimestampedCollector<>(output);
+ this.outRow = new JoinedRow();
+ this.leftNullRow = new GenericRow(leftType.getArity());
+ this.rightNullRow = new GenericRow(rightType.getArity());
+
+ // initialize states
+ if (leftIsOuter) {
+ this.leftRecordStateView = OuterJoinRecordStateViews.create(
+ getRuntimeContext(),
+ "left-records",
+ leftInputSideSpec,
+ leftType,
+ minRetentionTime,
+ stateCleaningEnabled);
+ } else {
+ this.leftRecordStateView = JoinRecordStateViews.create(
+ getRuntimeContext(),
+ "left-records",
+ leftInputSideSpec,
+ leftType,
+ minRetentionTime,
+ stateCleaningEnabled);
+ }
+
+ if (rightIsOuter) {
+ this.rightRecordStateView = OuterJoinRecordStateViews.create(
+ getRuntimeContext(),
+ "right-records",
+ rightInputSideSpec,
+ rightType,
+ minRetentionTime,
+ stateCleaningEnabled);
+ } else {
+ this.rightRecordStateView = JoinRecordStateViews.create(
+ getRuntimeContext(),
+ "right-records",
+ rightInputSideSpec,
+ rightType,
+ minRetentionTime,
+ stateCleaningEnabled);
+ }
+ }
+
+ @Override
+ public void processElement1(StreamRecord<BaseRow> element) throws Exception {
+ processElement(element.getValue(), leftRecordStateView, rightRecordStateView, true);
+ }
+
+ @Override
+ public void processElement2(StreamRecord<BaseRow> element) throws Exception {
+ processElement(element.getValue(), rightRecordStateView, leftRecordStateView, false);
+ }
+
+ /**
+ * Process an input element and output incremental joined records, retraction messages will
+ * be sent in some scenarios.
+ *
+ * <p>Following is the pseudocode to describe the core logic of this method. The logic of this
+ * method is too complex, so we provide the pseudocode to help understand the logic. We should
+ * keep sync the following pseudocode with the real logic of the method.
+ *
+ * <pre>
+ * if input record is accumulate
+ * | if input side is outer
+ * | | if there is no matched rows on the other side, send +[record+null], state.add(record, 0)
+ * | | if there are matched rows on the other side
+ * | | | if other side is outer
+ * | | | | if the matched num in the matched rows == 0, send -[null+other]
+ * | | | | if the matched num in the matched rows > 0, skip
+ * | | | | otherState.update(other, old + 1)
+ * | | | endif
+ * | | | send +[record+other]s, state.add(record, other.size)
+ * | | endif
+ * | endif
+ * | if input side not outer
+ * | | state.add(record)
+ * | | if there is no matched rows on the other side, skip
+ * | | if there are matched rows on the other side
+ * | | | if other side is outer
+ * | | | | if the matched num in the matched rows == 0, send -[null+other]
+ * | | | | if the matched num in the matched rows > 0, skip
+ * | | | | otherState.update(other, old + 1)
+ * | | | endif
+ * | | | send +[record+other]s
+ * | | endif
+ * | endif
+ * endif
+ *
+ * if input record is retract
+ * | state.retract(record)
+ * | if there is no matched rows on the other side
+ * | | if input side is outer, send -[record+null]
+ * | endif
+ * | if there are matched rows on the other side, send -[record+other]s
+ * | | if other side is outer
+ * | | | if the matched num in the matched rows == 0, this should never happen!
+ * | | | if the matched num in the matched rows == 1, send +[null+other]
+ * | | | if the matched num in the matched rows > 1, skip
+ * | | | otherState.update(other, old - 1)
+ * | | endif
+ * | endif
+ * endif
+ * </pre>
+ *
+ * @param input the input element
+ * @param inputSideStateView state of input side
+ * @param otherSideStateView state of other side
+ * @param inputIsLeft whether input side is left side
+ */
+ private void processElement(
+ BaseRow input,
+ JoinRecordStateView inputSideStateView,
+ JoinRecordStateView otherSideStateView,
+ boolean inputIsLeft) throws Exception {
+ boolean inputIsOuter = inputIsLeft ? leftIsOuter : rightIsOuter;
+ boolean otherIsOuter = inputIsLeft ? rightIsOuter : leftIsOuter;
+
+ AssociatedRecords associatedRecords = AssociatedRecords.of(input, inputIsLeft, otherSideStateView, joinCondition);
+ if (BaseRowUtil.isAccumulateMsg(input)) { // record is accumulate
+ if (inputIsOuter) { // input side is outer
+ OuterJoinRecordStateView inputSideOuterStateView = (OuterJoinRecordStateView) inputSideStateView;
+ if (associatedRecords.isEmpty()) { // there is no matched rows on the other side
+ // send +[record+null]
+ outRow.setHeader(BaseRowUtil.ACCUMULATE_MSG);
+ outputNullPadding(input, inputIsLeft);
+ // state.add(record, 0)
+ inputSideOuterStateView.addRecord(input, 0);
+ } else { // there are matched rows on the other side
+ if (otherIsOuter) { // other side is outer
+ OuterJoinRecordStateView otherSideOuterStateView = (OuterJoinRecordStateView) otherSideStateView;
+ for (OuterRecord outerRecord : associatedRecords.getOuterRecords()) {
+ BaseRow other = outerRecord.record;
+ // if the matched num in the matched rows == 0
+ if (outerRecord.numOfAssociations == 0) {
+ // send -[null+other]
+ outRow.setHeader(BaseRowUtil.RETRACT_MSG);
+ outputNullPadding(other, !inputIsLeft);
+ } // ignore matched number > 0
+ // otherState.update(other, old + 1)
+ otherSideOuterStateView.updateNumOfAssociations(other, outerRecord.numOfAssociations + 1);
+ }
+ }
+ // send +[record+other]s
+ outRow.setHeader(BaseRowUtil.ACCUMULATE_MSG);
+ for (BaseRow other : associatedRecords.getRecords()) {
+ output(input, other, inputIsLeft);
+ }
+ // state.add(record, other.size)
+ inputSideOuterStateView.addRecord(input, associatedRecords.size());
+ }
+ } else { // input side not outer
+ // state.add(record)
+ inputSideStateView.addRecord(input);
+ if (!associatedRecords.isEmpty()) { // if there are matched rows on the other side
+ if (otherIsOuter) { // if other side is outer
+ OuterJoinRecordStateView otherSideOuterStateView = (OuterJoinRecordStateView) otherSideStateView;
+ for (OuterRecord outerRecord : associatedRecords.getOuterRecords()) {
+ if (outerRecord.numOfAssociations == 0) { // if the matched num in the matched rows == 0
+ // send -[null+other]
+ outRow.setHeader(BaseRowUtil.RETRACT_MSG);
+ outputNullPadding(outerRecord.record, !inputIsLeft);
+ }
+ // otherState.update(other, old + 1)
+ otherSideOuterStateView.updateNumOfAssociations(outerRecord.record, outerRecord.numOfAssociations + 1);
+ }
+ }
+ // send +[record+other]s
+ outRow.setHeader(BaseRowUtil.ACCUMULATE_MSG);
+ for (BaseRow other : associatedRecords.getRecords()) {
+ output(input, other, inputIsLeft);
+ }
+ }
+ // skip when there is no matched rows on the other side
+ }
+ } else { // input record is retract
+ // state.retract(record)
+ inputSideStateView.retractRecord(input);
+ if (associatedRecords.isEmpty()) { // there is no matched rows on the other side
+ if (inputIsOuter) { // input side is outer
+ // send -[record+null]
+ outRow.setHeader(BaseRowUtil.RETRACT_MSG);
+ outputNullPadding(input, inputIsLeft);
+ }
+ // nothing to do when input side is not outer
+ } else { // there are matched rows on the other side
+ // send -[record+other]s
+ outRow.setHeader(BaseRowUtil.RETRACT_MSG);
+ for (BaseRow other : associatedRecords.getRecords()) {
+ output(input, other, inputIsLeft);
+ }
+ // if other side is outer
+ if (otherIsOuter) {
+ OuterJoinRecordStateView otherSideOuterStateView = (OuterJoinRecordStateView) otherSideStateView;
+ for (OuterRecord outerRecord : associatedRecords.getOuterRecords()) {
+ if (outerRecord.numOfAssociations == 1) {
+ // send +[null+other]
+ outRow.setHeader(BaseRowUtil.ACCUMULATE_MSG);
+ outputNullPadding(outerRecord.record, !inputIsLeft);
+ } // nothing else to do when number of associations > 1
+ // otherState.update(other, old - 1)
+ otherSideOuterStateView.updateNumOfAssociations(outerRecord.record, outerRecord.numOfAssociations - 1);
+ }
+ }
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------------------------
+
+ private void output(BaseRow inputRow, BaseRow otherRow, boolean inputIsLeft) {
+ if (inputIsLeft) {
+ outRow.replace(inputRow, otherRow);
+ } else {
+ outRow.replace(otherRow, inputRow);
+ }
+ collector.collect(outRow);
+ }
+
+ private void outputNullPadding(BaseRow row, boolean isLeft) {
+ if (isLeft) {
+ outRow.replace(row, rightNullRow);
+ } else {
+ outRow.replace(leftNullRow, row);
+ }
+ collector.collect(outRow);
+ }
+
+ // ----------------------------------------------------------------------------------------
+ // Utility Classes
+ // ----------------------------------------------------------------------------------------
+
+ private class JoinConditionWithNullFilters implements JoinCondition {
+
+ final JoinCondition backingJoinCondition;
+
+ private JoinConditionWithNullFilters(JoinCondition backingJoinCondition) {
+ this.backingJoinCondition = backingJoinCondition;
+ }
+
+ @Override
+ public boolean apply(BaseRow left, BaseRow right) {
+ if (!nullSafe) { // is not null safe, return false if any null exists
+ // key is always BinaryRow
+ BinaryRow joinKey = (BinaryRow) getCurrentKey();
+ if (filterAllNulls ? joinKey.anyNull() : joinKey.anyNull(nullFilterKeys)) {
+ // find null present, return false directly
+ return false;
+ }
+ }
+ // test condition
+ return backingJoinCondition.apply(left, right);
+ }
+ }
+
+ /**
+ * The {@link AssociatedRecords} is the records associated to the input row. It is a wrapper
+ * of {@code List<OuterRecord>} which provides two helpful methods {@link #getRecords()} and
+ * {@link #getOuterRecords()}. See the method Javadoc for more details.
+ */
+ private static final class AssociatedRecords {
+ private final List<OuterRecord> records;
+
+ private AssociatedRecords(List<OuterRecord> records) {
+ checkNotNull(records);
+ this.records = records;
+ }
+
+ public boolean isEmpty() {
+ return records.isEmpty();
+ }
+
+ public int size() {
+ return records.size();
+ }
+
+ /**
+ * Gets the iterable of records. This is usually be called when the
+ * {@link AssociatedRecords} is from inner side.
+ */
+ public Iterable<BaseRow> getRecords() {
+ return new RecordsIterable(records);
+ }
+
+ /**
+ * Gets the iterable of {@link OuterRecord} which composites record and numOfAssociations.
+ * This is usually be called when the {@link AssociatedRecords} is from outer side.
+ */
+ public Iterable<OuterRecord> getOuterRecords() {
+ return records;
+ }
+
+ /**
+ * Creates an {@link AssociatedRecords} which represents the records associated to the
+ * input row.
+ */
+ public static AssociatedRecords of(
+ BaseRow input,
+ boolean inputIsLeft,
+ JoinRecordStateView otherSideStateView,
+ JoinCondition condition) throws Exception {
+ List<OuterRecord> associations = new ArrayList<>();
+ if (otherSideStateView instanceof OuterJoinRecordStateView) {
+ OuterJoinRecordStateView outerStateView = (OuterJoinRecordStateView) otherSideStateView;
+ Iterable<Tuple2<BaseRow, Integer>> records = outerStateView.getRecordsAndNumOfAssociations();
+ for (Tuple2<BaseRow, Integer> record : records) {
+ boolean matched = inputIsLeft ? condition.apply(input, record.f0) : condition.apply(record.f0, input);
+ if (matched) {
+ associations.add(new OuterRecord(record.f0, record.f1));
+ }
+ }
+ } else {
+ Iterable<BaseRow> records = otherSideStateView.getRecords();
+ for (BaseRow record : records) {
+ boolean matched = inputIsLeft ? condition.apply(input, record) : condition.apply(record, input);
+ if (matched) {
+ // use -1 as the default number of associations
+ associations.add(new OuterRecord(record, -1));
+ }
+ }
+ }
+ return new AssociatedRecords(associations);
+ }
+
+ }
+
+ /**
+ * A lazy Iterable which transform {@code List<OuterReocord>} to {@code Iterable<BaseRow>}.
+ */
+ private static final class RecordsIterable implements IterableIterator<BaseRow> {
+ private final List<OuterRecord> records;
+ private int index = 0;
+
+ private RecordsIterable(List<OuterRecord> records) {
+ this.records = records;
+ }
+
+ @Override
+ public Iterator<BaseRow> iterator() {
+ index = 0;
+ return this;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return index < records.size();
+ }
+
+ @Override
+ public BaseRow next() {
+ BaseRow row = records.get(index).record;
+ index++;
+ return row;
+ }
+ }
+
+ /**
+ * An {@link OuterRecord} is a composite of record and {@code numOfAssociations}. The
+ * {@code numOfAssociations} represents the number of associated records in the other side.
+ * It is used when the record is from outer side (e.g. left side in LEFT OUTER JOIN).
+ * When the {@code numOfAssociations} is ZERO, we need to send a null padding row.
+ * This is useful to avoid recompute the associated numbers every time.
+ *
+ * <p>When the record is from inner side (e.g. right side in LEFT OUTER JOIN), the
+ * {@code numOfAssociations} will always be {@code -1}.
+ */
+ private static final class OuterRecord {
+ private final BaseRow record;
+ private final int numOfAssociations;
+
+ private OuterRecord(BaseRow record, int numOfAssociations) {
+ this.record = record;
+ this.numOfAssociations = numOfAssociations;
+ }
+ }
+
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinInputSideSpec.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinInputSideSpec.java
new file mode 100644
index 0000000..dc35538
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinInputSideSpec.java
@@ -0,0 +1,128 @@
+/*
+ * 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.runtime.join.stream.state;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.table.dataformat.BaseRow;
+import org.apache.flink.table.typeutils.BaseRowTypeInfo;
+
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * The {@link JoinInputSideSpec} is ap specification which describes input side information of
+ * a Join.
+ */
+public class JoinInputSideSpec implements Serializable {
+ private static final long serialVersionUID = 3178408082297179959L;
+
+ private final boolean inputSideHasUniqueKey;
+ private final boolean joinKeyContainsUniqueKey;
+ @Nullable private final BaseRowTypeInfo uniqueKeyType;
+ @Nullable private final KeySelector<BaseRow, BaseRow> uniqueKeySelector;
+
+ private JoinInputSideSpec(
+ boolean joinKeyContainsUniqueKey,
+ @Nullable BaseRowTypeInfo uniqueKeyType,
+ @Nullable KeySelector<BaseRow, BaseRow> uniqueKeySelector) {
+ this.inputSideHasUniqueKey = uniqueKeyType != null && uniqueKeySelector != null;
+ this.joinKeyContainsUniqueKey = joinKeyContainsUniqueKey;
+ this.uniqueKeyType = uniqueKeyType;
+ this.uniqueKeySelector = uniqueKeySelector;
+ }
+
+ /**
+ * Returns true if the input has unique key, otherwise false.
+ */
+ public boolean hasUniqueKey() {
+ return inputSideHasUniqueKey;
+ }
+
+ /**
+ * Returns true if the join key contains the unique key of the input.
+ */
+ public boolean joinKeyContainsUniqueKey() {
+ return joinKeyContainsUniqueKey;
+ }
+
+ /**
+ * Returns the {@link TypeInformation} of the unique key.
+ * Returns null if the input hasn't unique key.
+ */
+ @Nullable
+ public BaseRowTypeInfo getUniqueKeyType() {
+ return uniqueKeyType;
+ }
+
+ /**
+ * Returns the {@link KeySelector} to extract unique key from the input row.
+ * Returns null if the input hasn't unique key.
+ */
+ @Nullable
+ public KeySelector<BaseRow, BaseRow> getUniqueKeySelector() {
+ return uniqueKeySelector;
+ }
+
+ /**
+ * Creates a {@link JoinInputSideSpec} that the input has an unique key.
+ * @param uniqueKeyType type information of the unique key
+ * @param uniqueKeySelector key selector to extract unique key from the input row
+ */
+ public static JoinInputSideSpec withUniqueKey(BaseRowTypeInfo uniqueKeyType, KeySelector<BaseRow, BaseRow> uniqueKeySelector) {
+ checkNotNull(uniqueKeyType);
+ checkNotNull(uniqueKeySelector);
+ return new JoinInputSideSpec(false, uniqueKeyType, uniqueKeySelector);
+ }
+
+ /**
+ * Creates a {@link JoinInputSideSpec} that input has an unique key and the unique key is
+ * contained by the join key.
+ * @param uniqueKeyType type information of the unique key
+ * @param uniqueKeySelector key selector to extract unique key from the input row
+ */
+ public static JoinInputSideSpec withUniqueKeyContainedByJoinKey(BaseRowTypeInfo uniqueKeyType, KeySelector<BaseRow, BaseRow> uniqueKeySelector) {
+ checkNotNull(uniqueKeyType);
+ checkNotNull(uniqueKeySelector);
+ return new JoinInputSideSpec(true, uniqueKeyType, uniqueKeySelector);
+ }
+
+ /**
+ * Creates a {@link JoinInputSideSpec} that input hasn't any unique keys.
+ */
+ public static JoinInputSideSpec withoutUniqueKey() {
+ return new JoinInputSideSpec(false, null, null);
+ }
+
+ @Override
+ public String toString() {
+ if (inputSideHasUniqueKey) {
+ if (joinKeyContainsUniqueKey) {
+ return "JoinKeyContainsUniqueKey";
+ } else {
+ return "HasUniqueKey";
+ }
+ } else {
+ return "NoUniqueKey";
+ }
+ }
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateView.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateView.java
new file mode 100644
index 0000000..58c4d84
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateView.java
@@ -0,0 +1,47 @@
+/*
+ * 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.runtime.join.stream.state;
+
+import org.apache.flink.table.dataformat.BaseRow;
+
+/**
+ * A {@link JoinRecordStateView} is a view to the join state. It encapsulates the join state and
+ * provides some APIs facing the input records. The join state is used to store
+ * input records. The structure of the join state is vary depending on the {@link JoinInputSideSpec}.
+ *
+ * <p>For example: when the {@link JoinInputSideSpec} is JoinKeyContainsUniqueKey, we will use
+ * {@link org.apache.flink.api.common.state.ValueState} to store records which has better performance.
+ */
+public interface JoinRecordStateView {
+
+ /**
+ * Add a new record to the state view.
+ */
+ void addRecord(BaseRow record) throws Exception;
+
+ /**
+ * Retract the record from the state view.
+ */
+ void retractRecord(BaseRow record) throws Exception;
+
+ /**
+ * Gets all the records under the current context (i.e. join key).
+ */
+ Iterable<BaseRow> getRecords() throws Exception;
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateViews.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateViews.java
new file mode 100644
index 0000000..e3908fc
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/JoinRecordStateViews.java
@@ -0,0 +1,253 @@
+/*
+ * 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.runtime.join.stream.state;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.state.MapState;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.api.common.state.StateTtlConfig;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.table.dataformat.BaseRow;
+import org.apache.flink.table.typeutils.BaseRowTypeInfo;
+import org.apache.flink.util.IterableIterator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Utility to create a {@link JoinRecordStateView} depends on {@link JoinInputSideSpec}.
+ */
+public final class JoinRecordStateViews {
+
+ /**
+ * Creates a {@link JoinRecordStateView} depends on {@link JoinInputSideSpec}.
+ */
+ public static JoinRecordStateView create(
+ RuntimeContext ctx,
+ String stateName,
+ JoinInputSideSpec inputSideSpec,
+ BaseRowTypeInfo recordType,
+ long retentionTime,
+ boolean stateCleaningEnabled) {
+ StateTtlConfig ttlConfig = createTtlConfig(retentionTime, stateCleaningEnabled);
+ if (inputSideSpec.hasUniqueKey()) {
+ if (inputSideSpec.joinKeyContainsUniqueKey()) {
+ return new JoinKeyContainsUniqueKey(ctx, stateName, recordType, ttlConfig);
+ } else {
+ return new InputSideHasUniqueKey(
+ ctx,
+ stateName,
+ recordType,
+ inputSideSpec.getUniqueKeyType(),
+ inputSideSpec.getUniqueKeySelector(),
+ ttlConfig);
+ }
+ } else {
+ return new InputSideHasNoUniqueKey(ctx, stateName, recordType, ttlConfig);
+ }
+ }
+
+ static StateTtlConfig createTtlConfig(long retentionTime, boolean stateCleaningEnabled) {
+ if (stateCleaningEnabled) {
+ checkArgument(retentionTime > 0);
+ return StateTtlConfig
+ .newBuilder(Time.milliseconds(retentionTime))
+ .setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
+ .setStateVisibility(StateTtlConfig.StateVisibility.ReturnExpiredIfNotCleanedUp)
+ .build();
+ } else {
+ return StateTtlConfig.DISABLED;
+ }
+ }
+
+ // ------------------------------------------------------------------------------------
+
+ private static final class JoinKeyContainsUniqueKey implements JoinRecordStateView {
+
+ private final ValueState<BaseRow> recordState;
+ private final List<BaseRow> reusedList;
+
+ private JoinKeyContainsUniqueKey(
+ RuntimeContext ctx,
+ String stateName,
+ BaseRowTypeInfo recordType,
+ StateTtlConfig ttlConfig) {
+ ValueStateDescriptor<BaseRow> recordStateDesc = new ValueStateDescriptor<>(
+ stateName,
+ recordType);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getState(recordStateDesc);
+ // the result records always not more than 1
+ this.reusedList = new ArrayList<>(1);
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ recordState.update(record);
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ recordState.clear();
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ reusedList.clear();
+ BaseRow record = recordState.value();
+ if (record != null) {
+ reusedList.add(record);
+ }
+ return reusedList;
+ }
+ }
+
+ private static final class InputSideHasUniqueKey implements JoinRecordStateView {
+
+ // stores record in the mapping <UK, Record>
+ private final MapState<BaseRow, BaseRow> recordState;
+ private final KeySelector<BaseRow, BaseRow> uniqueKeySelector;
+
+ private InputSideHasUniqueKey(
+ RuntimeContext ctx,
+ String stateName,
+ BaseRowTypeInfo recordType,
+ BaseRowTypeInfo uniqueKeyType,
+ KeySelector<BaseRow, BaseRow> uniqueKeySelector,
+ StateTtlConfig ttlConfig) {
+ checkNotNull(uniqueKeyType);
+ checkNotNull(uniqueKeySelector);
+ MapStateDescriptor<BaseRow, BaseRow> recordStateDesc = new MapStateDescriptor<>(
+ stateName,
+ uniqueKeyType,
+ recordType);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getMapState(recordStateDesc);
+ this.uniqueKeySelector = uniqueKeySelector;
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ BaseRow uniqueKey = uniqueKeySelector.getKey(record);
+ recordState.put(uniqueKey, record);
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ BaseRow uniqueKey = uniqueKeySelector.getKey(record);
+ recordState.remove(uniqueKey);
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ return recordState.values();
+ }
+ }
+
+ private static final class InputSideHasNoUniqueKey implements JoinRecordStateView {
+
+ private final MapState<BaseRow, Integer> recordState;
+
+ private InputSideHasNoUniqueKey(
+ RuntimeContext ctx,
+ String stateName,
+ BaseRowTypeInfo recordType,
+ StateTtlConfig ttlConfig) {
+ MapStateDescriptor<BaseRow, Integer> recordStateDesc = new MapStateDescriptor<>(
+ stateName,
+ recordType,
+ Types.INT);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getMapState(recordStateDesc);
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ Integer cnt = recordState.get(record);
+ if (cnt != null) {
+ cnt += 1;
+ } else {
+ cnt = 1;
+ }
+ recordState.put(record, cnt);
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ Integer cnt = recordState.get(record);
+ if (cnt != null) {
+ if (cnt > 1) {
+ recordState.put(record, cnt - 1);
+ } else {
+ recordState.remove(record);
+ }
+ }
+ // ignore cnt == null, which means state may be expired
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ return new IterableIterator<BaseRow>() {
+
+ private final Iterator<Map.Entry<BaseRow, Integer>> backingIterable = recordState.entries().iterator();
+ private BaseRow record;
+ private int remainingTimes = 0;
+
+ @Override
+ public boolean hasNext() {
+ return backingIterable.hasNext() || remainingTimes > 0;
+ }
+
+ @Override
+ public BaseRow next() {
+ if (remainingTimes > 0) {
+ checkNotNull(record);
+ remainingTimes--;
+ return record;
+ } else {
+ Map.Entry<BaseRow, Integer> entry = backingIterable.next();
+ record = entry.getKey();
+ remainingTimes = entry.getValue() - 1;
+ return record;
+ }
+ }
+
+ @Override
+ public Iterator<BaseRow> iterator() {
+ return this;
+ }
+ };
+ }
+ }
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateView.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateView.java
new file mode 100644
index 0000000..32942a6
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateView.java
@@ -0,0 +1,56 @@
+/*
+ * 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.runtime.join.stream.state;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.table.dataformat.BaseRow;
+
+/**
+ * A {@link OuterJoinRecordStateView} is an extension to {@link JoinRecordStateView}.
+ * The {@link OuterJoinRecordStateView} is used to store records for the outer input
+ * side of the Join, e.g. the left side of left join, the both side of full join.
+ *
+ * <p>The additional information we should store with the record is the number of associations
+ * which is the number of records associated this record with other side. This is an
+ * important information when to send/retract a null padding row, to avoid recompute the
+ * associated numbers every time.
+ *
+ * @see JoinRecordStateView
+ */
+public interface OuterJoinRecordStateView extends JoinRecordStateView {
+
+ /**
+ * Adds a new record with the number of associations to the state view.
+ * @param record the added record
+ * @param numOfAssociations the number of records associated with other side
+ */
+ void addRecord(BaseRow record, int numOfAssociations) throws Exception;
+
+ /**
+ * Updates the number of associations belongs to the record.
+ * @param record the record to update
+ * @param numOfAssociations the new number of records associated with other side
+ */
+ void updateNumOfAssociations(BaseRow record, int numOfAssociations) throws Exception;
+
+ /**
+ * Gets all the records and number of associations under the current context (i.e. join key).
+ */
+ Iterable<Tuple2<BaseRow, Integer>> getRecordsAndNumOfAssociations() throws Exception;
+}
diff --git a/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateViews.java b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateViews.java
new file mode 100644
index 0000000..c463992
--- /dev/null
+++ b/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/join/stream/state/OuterJoinRecordStateViews.java
@@ -0,0 +1,329 @@
+/*
+ * 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.runtime.join.stream.state;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.state.MapState;
+import org.apache.flink.api.common.state.MapStateDescriptor;
+import org.apache.flink.api.common.state.StateTtlConfig;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TupleTypeInfo;
+import org.apache.flink.table.dataformat.BaseRow;
+import org.apache.flink.table.typeutils.BaseRowTypeInfo;
+import org.apache.flink.util.IterableIterator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.runtime.join.stream.state.JoinRecordStateViews.createTtlConfig;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Utility to create a {@link OuterJoinRecordStateViews} depends on {@link JoinInputSideSpec}.
+ */
+public final class OuterJoinRecordStateViews {
+
+ /**
+ * Creates a {@link OuterJoinRecordStateView} depends on {@link JoinInputSideSpec}.
+ */
+ public static OuterJoinRecordStateView create(
+ RuntimeContext ctx,
+ String stateName,
+ JoinInputSideSpec inputSideSpec,
+ BaseRowTypeInfo recordType,
+ long retentionTime,
+ boolean stateCleaningEnabled) {
+ StateTtlConfig ttlConfig = createTtlConfig(retentionTime, stateCleaningEnabled);
+ if (inputSideSpec.hasUniqueKey()) {
+ if (inputSideSpec.joinKeyContainsUniqueKey()) {
+ return new OuterJoinRecordStateViews.JoinKeyContainsUniqueKey(ctx, stateName, recordType, ttlConfig);
+ } else {
+ return new OuterJoinRecordStateViews.InputSideHasUniqueKey(
+ ctx,
+ stateName,
+ recordType,
+ inputSideSpec.getUniqueKeyType(),
+ inputSideSpec.getUniqueKeySelector(),
+ ttlConfig);
+ }
+ } else {
+ return new OuterJoinRecordStateViews.InputSideHasNoUniqueKey(ctx, stateName, recordType, ttlConfig);
+ }
+ }
+
+ // ------------------------------------------------------------------------------------------
+
+ private static final class JoinKeyContainsUniqueKey implements OuterJoinRecordStateView {
+
+ private final ValueState<Tuple2<BaseRow, Integer>> recordState;
+ private final List<BaseRow> reusedRecordList;
+ private final List<Tuple2<BaseRow, Integer>> reusedTupleList;
+
+ private JoinKeyContainsUniqueKey(RuntimeContext ctx, String stateName, BaseRowTypeInfo recordType, StateTtlConfig ttlConfig) {
+ TupleTypeInfo<Tuple2<BaseRow, Integer>> valueTypeInfo = new TupleTypeInfo<>(recordType, Types.INT);
+ ValueStateDescriptor<Tuple2<BaseRow, Integer>> recordStateDesc = new ValueStateDescriptor<>(
+ stateName,
+ valueTypeInfo);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getState(recordStateDesc);
+ // the result records always not more than 1
+ this.reusedRecordList = new ArrayList<>(1);
+ this.reusedTupleList = new ArrayList<>(1);
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ addRecord(record, -1);
+ }
+
+ @Override
+ public void addRecord(BaseRow record, int numOfAssociations) throws Exception {
+ recordState.update(Tuple2.of(record, numOfAssociations));
+ }
+
+ @Override
+ public void updateNumOfAssociations(BaseRow record, int numOfAssociations) throws Exception {
+ recordState.update(Tuple2.of(record, numOfAssociations));
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ recordState.clear();
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ Tuple2<BaseRow, Integer> tuple = recordState.value();
+ if (tuple == null) {
+ reusedRecordList.clear();
+ } else {
+ reusedRecordList.add(tuple.f0);
+ }
+ return reusedRecordList;
+ }
+
+ @Override
+ public Iterable<Tuple2<BaseRow, Integer>> getRecordsAndNumOfAssociations() throws Exception {
+ reusedTupleList.clear();
+ Tuple2<BaseRow, Integer> tuple = recordState.value();
+ if (tuple != null) {
+ reusedTupleList.add(tuple);
+ }
+ return reusedTupleList;
+ }
+ }
+
+ private static final class InputSideHasUniqueKey implements OuterJoinRecordStateView {
+
+ // stores record in the mapping <UK, <Record, associated-num>>
+ private final MapState<BaseRow, Tuple2<BaseRow, Integer>> recordState;
+ private final KeySelector<BaseRow, BaseRow> uniqueKeySelector;
+
+ private InputSideHasUniqueKey(
+ RuntimeContext ctx,
+ String stateName,
+ BaseRowTypeInfo recordType,
+ BaseRowTypeInfo uniqueKeyType,
+ KeySelector<BaseRow, BaseRow> uniqueKeySelector,
+ StateTtlConfig ttlConfig) {
+ checkNotNull(uniqueKeyType);
+ checkNotNull(uniqueKeySelector);
+ TupleTypeInfo<Tuple2<BaseRow, Integer>> valueTypeInfo = new TupleTypeInfo<>(recordType, Types.INT);
+ MapStateDescriptor<BaseRow, Tuple2<BaseRow, Integer>> recordStateDesc = new MapStateDescriptor<>(
+ stateName,
+ uniqueKeyType,
+ valueTypeInfo);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getMapState(recordStateDesc);
+ this.uniqueKeySelector = uniqueKeySelector;
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ addRecord(record, -1);
+ }
+
+ @Override
+ public void addRecord(BaseRow record, int numOfAssociations) throws Exception {
+ BaseRow uniqueKey = uniqueKeySelector.getKey(record);
+ recordState.put(uniqueKey, Tuple2.of(record, numOfAssociations));
+ }
+
+ @Override
+ public void updateNumOfAssociations(BaseRow record, int numOfAssociations) throws Exception {
+ BaseRow uniqueKey = uniqueKeySelector.getKey(record);
+ recordState.put(uniqueKey, Tuple2.of(record, numOfAssociations));
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ BaseRow uniqueKey = uniqueKeySelector.getKey(record);
+ recordState.remove(uniqueKey);
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ return new RecordsIterable(getRecordsAndNumOfAssociations());
+ }
+
+ @Override
+ public Iterable<Tuple2<BaseRow, Integer>> getRecordsAndNumOfAssociations() throws Exception {
+ return recordState.values();
+ }
+ }
+
+ private static final class InputSideHasNoUniqueKey implements OuterJoinRecordStateView {
+
+ // stores record in the mapping <Record, <appear-times, associated-num>>
+ private final MapState<BaseRow, Tuple2<Integer, Integer>> recordState;
+
+ private InputSideHasNoUniqueKey(
+ RuntimeContext ctx,
+ String stateName,
+ BaseRowTypeInfo recordType,
+ StateTtlConfig ttlConfig) {
+ TupleTypeInfo<Tuple2<Integer, Integer>> tupleTypeInfo = new TupleTypeInfo<>(Types.INT, Types.INT);
+ MapStateDescriptor<BaseRow, Tuple2<Integer, Integer>> recordStateDesc = new MapStateDescriptor<>(
+ stateName,
+ recordType,
+ tupleTypeInfo);
+ if (!ttlConfig.equals(StateTtlConfig.DISABLED)) {
+ recordStateDesc.enableTimeToLive(ttlConfig);
+ }
+ this.recordState = ctx.getMapState(recordStateDesc);
+ }
+
+ @Override
+ public void addRecord(BaseRow record) throws Exception {
+ addRecord(record, -1);
+ }
+
+ @Override
+ public void addRecord(BaseRow record, int numOfAssociations) throws Exception {
+ Tuple2<Integer, Integer> tuple = recordState.get(record);
+ if (tuple != null) {
+ tuple.f0 = tuple.f0 + 1;
+ tuple.f1 = numOfAssociations;
+ } else {
+ tuple = Tuple2.of(1, numOfAssociations);
+ }
+ recordState.put(record, tuple);
+ }
+
+ @Override
+ public void updateNumOfAssociations(BaseRow record, int numOfAssociations) throws Exception {
+ Tuple2<Integer, Integer> tuple = recordState.get(record);
+ if (tuple != null) {
+ tuple.f1 = numOfAssociations;
+ } else {
+ // compatible for state ttl
+ tuple = Tuple2.of(1, numOfAssociations);
+ }
+ recordState.put(record, tuple);
+ }
+
+ @Override
+ public void retractRecord(BaseRow record) throws Exception {
+ Tuple2<Integer, Integer> tuple = recordState.get(record);
+ if (tuple != null) {
+ if (tuple.f0 > 1) {
+ tuple.f0 = tuple.f0 - 1;
+ recordState.put(record, tuple);
+ } else {
+ recordState.remove(record);
+ }
+ }
+ }
+
+ @Override
+ public Iterable<BaseRow> getRecords() throws Exception {
+ return new RecordsIterable(getRecordsAndNumOfAssociations());
+ }
+
+ @Override
+ public Iterable<Tuple2<BaseRow, Integer>> getRecordsAndNumOfAssociations() throws Exception {
+ return new IterableIterator<Tuple2<BaseRow, Integer>>() {
+
+ private final Iterator<Map.Entry<BaseRow, Tuple2<Integer, Integer>>> backingIterable = recordState.entries().iterator();
+ private Tuple2<BaseRow, Integer> tuple;
+ private int remainingTimes = 0;
+
+ @Override
+ public boolean hasNext() {
+ return backingIterable.hasNext() || remainingTimes > 0;
+ }
+
+ @Override
+ public Tuple2<BaseRow, Integer> next() {
+ if (remainingTimes > 0) {
+ checkNotNull(tuple);
+ remainingTimes--;
+ return tuple;
+ } else {
+ Map.Entry<BaseRow, Tuple2<Integer, Integer>> entry = backingIterable.next();
+ tuple = Tuple2.of(entry.getKey(), entry.getValue().f1);
+ remainingTimes = entry.getValue().f0 - 1;
+ return tuple;
+ }
+ }
+
+ @Override
+ public Iterator<Tuple2<BaseRow, Integer>> iterator() {
+ return this;
+ }
+ };
+ }
+ }
+
+ // ----------------------------------------------------------------------------------------
+
+ private static final class RecordsIterable implements IterableIterator<BaseRow> {
+ private final Iterator<Tuple2<BaseRow, Integer>> tupleIterator;
+
+ private RecordsIterable(Iterable<Tuple2<BaseRow, Integer>> tuples) {
+ checkNotNull(tuples);
+ this.tupleIterator = tuples.iterator();
+ }
+
+ @Override
+ public Iterator<BaseRow> iterator() {
+ return this;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return tupleIterator.hasNext();
+ }
+
+ @Override
+ public BaseRow next() {
+ return tupleIterator.next().f0;
+ }
+ }
+}