jnh5y commented on code in PR #25316:
URL: https://github.com/apache/flink/pull/25316#discussion_r1829716133
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/calcite/FlinkCalciteSqlValidatorTest.java:
##########
@@ -50,74 +67,43 @@ void testUpsertInto() {
"UPSERT INTO statement is not supported. Please use
INSERT INTO instead.");
}
- @Test
- void testInsertIntoShouldColumnMismatchWithValues() {
- assertThatThrownBy(() -> plannerMocks.getParser().parse("INSERT INTO
t2 (a,b) VALUES(1)"))
- .isInstanceOf(ValidationException.class)
- .hasMessageContaining(" Number of columns must match number of
query columns");
- }
-
- @Test
- void testInsertIntoShouldColumnMismatchWithSelect() {
- assertThatThrownBy(() -> plannerMocks.getParser().parse("INSERT INTO
t2 (a,b) SELECT 1"))
- .isInstanceOf(ValidationException.class)
- .hasMessageContaining(" Number of columns must match number of
query columns");
- }
-
- @Test
- void testInsertIntoShouldColumnMismatchWithLastValue() {
- assertThatThrownBy(
- () ->
- plannerMocks
- .getParser()
- .parse("INSERT INTO t2 (a,b) VALUES
(1,2), (3)"))
- .isInstanceOf(ValidationException.class)
- .hasMessageContaining(" Number of columns must match number of
query columns");
- }
-
- @Test
- void testInsertIntoShouldColumnMismatchWithFirstValue() {
- assertThatThrownBy(
- () ->
- plannerMocks
- .getParser()
- .parse("INSERT INTO t2 (a,b) VALUES
(1), (2,3)"))
- .isInstanceOf(ValidationException.class)
- .hasMessageContaining(" Number of columns must match number of
query columns");
- }
-
- @Test
- void testInsertIntoShouldColumnMismatchWithMultiFieldValues() {
- assertThatThrownBy(
- () ->
- plannerMocks
- .getParser()
- .parse("INSERT INTO t2 (a,b) VALUES
(1,2), (3,4,5)"))
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "INSERT INTO t2 (a, b) VALUES(1)",
+ "INSERT INTO t2 (a, b) VALUES (1, 2), (3)",
+ "INSERT INTO t2 (a, b) VALUES (1), (2, 3)",
+ "INSERT INTO t2 (a, b) VALUES (1, 2), (3, 4, 5)",
+ "INSERT INTO t2 (a, b) SELECT 1",
+ "INSERT INTO t2 (a, b) SELECT * FROM t1",
+ "INSERT INTO t2 (a, b) SELECT *, 42 FROM t2_copy",
+ "INSERT INTO t2 (a, b) SELECT 42, * FROM t2_copy",
+ "INSERT INTO t2 (a, b) SELECT * FROM t_nested",
+ "INSERT INTO t2 (a, b) TABLE t_nested",
+ "INSERT INTO t2 (a, b) SELECT * FROM (TABLE t_nested)"
+ })
+ void testInvalidNumberOfColumnsWhileInsertInto(String sql) {
+ assertThatThrownBy(() -> plannerMocks.getParser().parse(sql))
.isInstanceOf(ValidationException.class)
.hasMessageContaining(" Number of columns must match number of
query columns");
}
- @Test
- void testInsertIntoShouldNotColumnMismatchWithValues() {
- assertDoesNotThrow(
- () -> {
- plannerMocks.getParser().parse("INSERT INTO t2 (a,b)
VALUES (1,2), (3,4)");
- });
- }
-
- @Test
- void testInsertIntoShouldNotColumnMismatchWithSelect() {
- assertDoesNotThrow(
- () -> {
- plannerMocks.getParser().parse("INSERT INTO t2 (a,b)
Select 1, 2");
- });
- }
-
- @Test
- void testInsertIntoShouldNotColumnMismatchWithSingleColValues() {
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "INSERT INTO t2 (a, b) VALUES (1, 2), (3, 4)",
+ "INSERT INTO t2 (a) VALUES (1), (3)",
+ "INSERT INTO t2 (a, b) SELECT 1, 2",
+ "INSERT INTO t2 (a, b) SELECT * FROM t2_copy",
+ "INSERT INTO t2 (a, b) SELECT *, 42 FROM t1",
+ "INSERT INTO t2 (a, b) SELECT 42, * FROM t1",
+ "INSERT INTO t2 (a, b) SELECT f.* FROM t_nested",
+ "INSERT INTO t2 (a, b) TABLE t2_copy"
Review Comment:
Interesting. In that case, how did you figure out that you needed to add
that condition? (I'm mainly just curious.)
If it cannot be hit from SQL, it may be nice to see a unit test which
exercises the new condition. Not sure how hard that'd be.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]