raminqaf commented on code in PR #28277:
URL: https://github.com/apache/flink/pull/28277#discussion_r3356636007
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlDdlToOperationConverterTest.java:
##########
@@ -2591,6 +2591,127 @@ void testCreateViewWithDynamicTableOptions() {
assertThat(operation).isInstanceOf(CreateViewOperation.class);
}
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("viewOriginalQueryCases")
+ void testCreateViewOriginalQuery(String name, String sql, String
expectedOriginalQuery) {
+ final Operation operation = parse(sql);
+ assertThat(operation).isInstanceOf(CreateViewOperation.class);
+ assertThat(((CreateViewOperation)
operation).getCatalogView().getOriginalQuery())
+ .isEqualTo(expectedOriginalQuery);
+ }
+
+ private static Stream<Arguments> viewOriginalQueryCases() {
+ return Stream.of(
+ viewCommentHandlingCases(),
+ viewLineBreakCases(),
+ viewComplexQueryShapeCases(),
+ viewAdversarialTextCases())
+ .flatMap(s -> s);
+ }
+
+ private static Stream<Arguments> viewCommentHandlingCases() {
+ return Stream.of(
+ viewAsQueryCase(
+ "comments around the AS query are kept",
+ "/* leading comment */\nSELECT 1\n/* trailing comment
*/"),
+ viewAsQueryCase(
+ "block comment inside the AS query is kept",
+ "SELECT /* inline comment */ 1"),
+ viewAsQueryCase(
+ "trailing comment after the AS query is kept",
+ "SELECT 1 -- trailing comment"));
+ }
+
+ private static Stream<Arguments> viewLineBreakCases() {
+ return Stream.of(
+ Arguments.of(
+ "line comment mentioning AS before the AS keyword is
dropped",
+ "CREATE VIEW v1 --AS\nAS SELECT 1",
+ "SELECT 1"),
+ viewAsQueryCase(
+ "line comment mentioning AS between AS and the query
is kept",
+ "--AS\nSELECT 1"),
+ viewAsQueryCase(
+ "line comments mentioning AS in mixed case between AS
and the query are kept",
+ "--line AS\n--comment as\n--break As\nSELECT 1"),
+ Arguments.of(
+ "blank lines and line comments between AS and the
query are kept",
+ "CREATE VIEW v1 AS \n\n\n--AS\n
--line\n--comment\n--break\nSELECT 1",
+ "--AS\n --line\n--comment\n--break\nSELECT 1"),
+ viewAsQueryCase(
+ "multi-line block comment between AS and the query is
kept",
+ "/* multi\n line */\nSELECT 1"),
+ Arguments.of(
+ "multi-line block comment before AS is dropped",
+ "CREATE VIEW v1\n/* note\n before AS */\nAS SELECT 1",
+ "SELECT 1"),
+ Arguments.of(
+ "column list and comment before AS are dropped",
+ "CREATE VIEW v1 (w, x, y, z)\nCOMMENT 'a view'\nAS
SELECT a, b, c, d FROM t1",
+ "SELECT a, b, c, d FROM t1"));
+ }
+
+ private static Stream<Arguments> viewComplexQueryShapeCases() {
Review Comment:
Fair enough. I just added these to make sure the approach is sound and there
is no doubt in the logic.
--
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]