Skip to content

Commit ad47717

Browse files
authored
[FLINK-38750][table] Validation of queries with functions erroneously invoked under SELECT fails with StackOverflow
1 parent e4c197d commit ad47717

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/inference/TypeInferenceOperandInference.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ public void inferOperandTypes(
8181
false)) {
8282
inferOperandTypesOrError(unwrapTypeFactory(callBinding), callContext, operandTypes);
8383
}
84-
} catch (ValidationException | CalciteContextException e) {
84+
} catch (ValidationException e) {
8585
// let operand checker fail
86+
} catch (CalciteContextException e) {
87+
throw e;
8688
} catch (Throwable t) {
8789
throw createUnexpectedException(callContext, t);
8890
}

flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/CalcTest.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ class CalcTest extends TableTestBase {
108108
.isThrownBy(() => util.tableEnv.sqlQuery("SELECT a, foo FROM MyTable"))
109109
}
110110

111+
@Test
112+
def testCoalesceOnInvalidField(): Unit = {
113+
assertThatExceptionOfType(classOf[ValidationException])
114+
.isThrownBy(() => util.verifyExecPlan("SELECT coalesce(SELECT invalid)"))
115+
.withMessageContaining("Column 'invalid' not found in any table")
116+
}
117+
118+
@Test
119+
def testNestedCoalesceOnInvalidField(): Unit = {
120+
assertThatExceptionOfType(classOf[ValidationException])
121+
.isThrownBy(
122+
() => util.verifyExecPlan("SELECT coalesce(SELECT coalesce(SELECT coalesce(invalid)))"))
123+
.withMessageContaining("Column 'invalid' not found in any table")
124+
}
125+
111126
@Test
112127
def testPrimitiveMapType(): Unit = {
113128
util.verifyExecPlan("SELECT MAP[b, 30, 10, a] FROM MyTable")

0 commit comments

Comments
 (0)