yuzelin commented on code in PR #21187:
URL: https://github.com/apache/flink/pull/21187#discussion_r1046601074
##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/context/SessionContextTest.java:
##########
@@ -133,6 +139,70 @@ public void testSetAndResetArbitraryKey() {
assertThat(sessionContext.getConfigMap().get("bb")).isNull();
}
+ @Test
+ public void testStatementSetStateTransition() {
+ assertThat(sessionContext.isStatementSetState()).isFalse();
+
+ OperationExecutor executor =
sessionContext.createOperationExecutor(new Configuration());
+ TableEnvironmentInternal tableEnv = executor.getTableEnvironment();
+ tableEnv.executeSql("CREATE TABLE whatever (f STRING) WITH
('connector' = 'values')");
+
+ executor.executeStatement(OperationHandle.create(), "BEGIN STATEMENT
SET;");
+
+ assertThat(sessionContext.isStatementSetState()).isTrue();
+
+ // invalid statement in Statement Set
+ assertThatThrownBy(() ->
executor.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
+ String insert = "INSERT INTO whatever VALUES('test%s');";
+ int repeat = 3;
+ for (int i = 0; i < repeat; i++) {
+ executor.executeStatement(OperationHandle.create(),
String.format(insert, i));
+ }
+
+
assertThat(sessionContext.getStatementSetOperations().size()).isEqualTo(repeat);
+ for (int i = 0; i < repeat; i++) {
+
assertThat(sessionContext.getStatementSetOperations().get(i).asSummaryString())
+ .isEqualTo(
+ tableEnv.getParser()
+ .parse(String.format(insert, i))
+ .get(0)
+ .asSummaryString());
+ }
+
+ // end Statement Set
+ try {
+ executor.executeStatement(OperationHandle.create(), "END;");
+ } catch (Throwable t) {
+ // just test the Statement Set state transition, so ignore the
error that cluster
+ // doesn't exist
+ }
Review Comment:
Now I think the SqlGatewayServiceStatementITCase is enough, so I remove the
test.
--
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]