Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.apache.flink.table.planner.plan.utils.LookupJoinUtil._
import org.apache.flink.table.planner.plan.utils.PythonUtil.containsPythonCall
import org.apache.flink.table.planner.plan.utils.RelExplainUtil.preferExpressionFormat
import org.apache.flink.table.planner.plan.utils.{JoinTypeUtil, LookupJoinUtil, RelExplainUtil}
import org.apache.flink.table.runtime.types.PlannerTypeUtils

import org.apache.calcite.plan.{RelOptCluster, RelOptTable, RelTraitSet}
import org.apache.calcite.rel.`type`.{RelDataType, RelDataTypeField}
Expand Down Expand Up @@ -295,7 +296,11 @@ abstract class CommonPhysicalLookupJoin(
expr = call.getOperands.get(0)
case call: RexCall if call.getOperator == SqlStdOperatorTable.CAST =>
// drill through identity function
expr = call.getOperands.get(0)
val outputType = call.getType
val inputType = call.getOperands.get(0).getType
val isCompatible = PlannerTypeUtils.isInteroperable(
FlinkTypeFactory.toLogicalType(outputType), FlinkTypeFactory.toLogicalType(inputType))
expr = if (isCompatible) call.getOperands.get(0) else expr
case _ =>
}
expr match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,54 @@ class LookupJoinTest(legacyTableSource: Boolean) extends TableTestBase with Seri
util.verifyExecPlan(sql)
}

@Test
def testJoinTemporalTableWithCastOnLookupTable(): Unit = {
util.addTable(
"""
|CREATE TABLE LookupTable2 (
| `id` decimal(38, 18),
| `name` STRING,
| `age` INT
|) WITH (
| 'connector' = 'values'
|)
|""".stripMargin)
val sql =
"""
|SELECT MyTable.b, LookupTable2.id
|FROM MyTable
|LEFT JOIN LookupTable2 FOR SYSTEM_TIME AS OF MyTable.`proctime`
|ON MyTable.a = CAST(LookupTable2.`id` as INT)
|""".stripMargin
thrown.expect(classOf[TableException])
thrown.expectMessage("Temporal table join requires an equality condition on fields of " +
"table [default_catalog.default_database.LookupTable2]")
verifyTranslationSuccess(sql)
}

@Test
def testJoinTemporalTableWithInteroperableCastOnLookupTable(): Unit = {
util.addTable(
"""
|CREATE TABLE LookupTable2 (
| `id` INT,
| `name` char(10),
| `age` INT
|) WITH (
| 'connector' = 'values'
|)
|""".stripMargin)

val sql =
"""
|SELECT MyTable.b, LookupTable2.id
|FROM MyTable
|LEFT JOIN LookupTable2 FOR SYSTEM_TIME AS OF MyTable.`proctime`
|ON MyTable.b = CAST(LookupTable2.`name` as String)
|""".stripMargin
verifyTranslationSuccess(sql)
}

// ==========================================================================================

private def createLookupTable(tableName: String, lookupFunction: UserDefinedFunction): Unit = {
Expand Down