yuzelin commented on code in PR #21187:
URL: https://github.com/apache/flink/pull/21187#discussion_r1022505487
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/context/SessionContextTest.java:
##########
@@ -133,6 +138,79 @@ public void testSetAndResetArbitraryKey() {
assertThat(sessionContext.getConfigMap().get("bb")).isNull();
}
+ @Test
+ public void testStatementSetStateTransition() {
+ assertThat(sessionContext.isStatementSetState()).isFalse();
+
+ Configuration emptyConfiguration = new Configuration();
+ TableEnvironmentInternal tableEnv =
+
sessionContext.createOperationExecutor(emptyConfiguration).getTableEnvironment();
+ tableEnv.executeSql("CREATE TABLE whatever (f STRING) WITH
('connector' = 'values')");
+
+ sessionContext
+ .createOperationExecutor(emptyConfiguration)
+ .executeStatement(OperationHandle.create(), "BEGIN STATEMENT
SET;");
+
+ assertThat(sessionContext.isStatementSetState()).isTrue();
+
+ // invalid statement in Statement Set
+ assertThatThrownBy(
+ () ->
+ sessionContext
+
.createOperationExecutor(emptyConfiguration)
+
.executeStatement(OperationHandle.create(), "SELECT 1;"))
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ SqlExecutionException.class,
+ "Wrong statement after 'BEGIN STATEMENT
SET'.\n"
+ + "Only 'INSERT/CREATE TABLE AS'
statement is allowed in Statement Set or use 'END' statement to terminate
Statement Set."));
+
+ // 'isStatementSetState' is still true, and nothing in
'statementSetOperations'
+ assertThat(sessionContext.isStatementSetState()).isTrue();
+
assertThat(sessionContext.getStatementSetOperations().size()).isEqualTo(0);
+
+ // valid statement in Statement Set
+ sessionContext
+ .createOperationExecutor(emptyConfiguration)
+ .executeStatement(
+ OperationHandle.create(), "INSERT INTO whatever
VALUES('Hello World');");
Review Comment:
Sure it is worth. I forgot to test this case. The test is improved now.
--
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]