forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-29219][table] Fix CREATE TABLE AS statement blocks SQL client'…
…s execution This closes apache#20869
- Loading branch information
Showing
16 changed files
with
316 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...o-end-tests-sql/src/test/java/org/apache/flink/table/sql/codegen/CreateTableAsITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.table.sql.codegen; | ||
|
||
import org.apache.flink.test.util.SQLJobSubmission; | ||
import org.apache.flink.tests.util.flink.ClusterController; | ||
|
||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** End to End tests for create table as select syntax. */ | ||
public class CreateTableAsITCase extends SqlITCaseBase { | ||
|
||
public CreateTableAsITCase(String executionMode) { | ||
super(executionMode); | ||
} | ||
|
||
@Test | ||
public void testCreateTableAs() throws Exception { | ||
runAndCheckSQL( | ||
"create_table_as_e2e.sql", | ||
generateReplaceVars(), | ||
2, | ||
Arrays.asList( | ||
"{\"before\":null,\"after\":{\"user_name\":\"Alice\",\"order_cnt\":1},\"op\":\"c\"}", | ||
"{\"before\":null,\"after\":{\"user_name\":\"Bob\",\"order_cnt\":2},\"op\":\"c\"}")); | ||
} | ||
|
||
@Test | ||
public void testCreateTableAsInStatementSet() throws Exception { | ||
runAndCheckSQL( | ||
"create_table_as_statementset_e2e.sql", | ||
generateReplaceVars(), | ||
2, | ||
Arrays.asList( | ||
"{\"before\":null,\"after\":{\"user_name\":\"Alice\",\"order_cnt\":1},\"op\":\"c\"}", | ||
"{\"before\":null,\"after\":{\"user_name\":\"Bob\",\"order_cnt\":2},\"op\":\"c\"}")); | ||
} | ||
|
||
@Override | ||
protected void executeSqlStatements(ClusterController clusterController, List<String> sqlLines) | ||
throws Exception { | ||
clusterController.submitSQLJob( | ||
new SQLJobSubmission.SQLJobSubmissionBuilder(sqlLines) | ||
.addJar(SQL_TOOL_BOX_JAR) | ||
.build(), | ||
Duration.ofMinutes(2L)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
flink-end-to-end-tests/flink-end-to-end-tests-sql/src/test/resources/create_table_as_e2e.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE TEMPORARY FUNCTION count_agg AS 'org.apache.flink.table.toolbox.CountAggFunction'; | ||
|
||
SET execution.runtime-mode = $MODE; | ||
SET table.exec.mini-batch.enabled = true; | ||
SET table.exec.mini-batch.size = 5; | ||
SET table.exec.mini-batch.allow-latency = 2s; | ||
|
||
CREATE TABLE JsonTable | ||
WITH ( | ||
'connector' = 'filesystem', | ||
'path' = '$RESULT', | ||
'sink.rolling-policy.rollover-interval' = '2s', | ||
'sink.rolling-policy.check-interval' = '2s', | ||
'format' = 'debezium-json' | ||
) | ||
AS SELECT user_name, count_agg(order_id) AS order_cnt | ||
FROM (VALUES (1, 'Bob'), (2, 'Bob'), (1, 'Alice')) T(order_id, user_name) | ||
GROUP BY user_name; |
40 changes: 40 additions & 0 deletions
40
...-tests/flink-end-to-end-tests-sql/src/test/resources/create_table_as_statementset_e2e.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
CREATE TEMPORARY FUNCTION count_agg AS 'org.apache.flink.table.toolbox.CountAggFunction'; | ||
|
||
SET execution.runtime-mode = $MODE; | ||
SET table.exec.mini-batch.enabled = true; | ||
SET table.exec.mini-batch.size = 5; | ||
SET table.exec.mini-batch.allow-latency = 2s; | ||
|
||
BEGIN STATEMENT SET; | ||
|
||
CREATE TABLE JsonTable | ||
WITH ( | ||
'connector' = 'filesystem', | ||
'path' = '$RESULT', | ||
'sink.rolling-policy.rollover-interval' = '2s', | ||
'sink.rolling-policy.check-interval' = '2s', | ||
'format' = 'debezium-json' | ||
) | ||
AS SELECT user_name, count_agg(order_id) AS order_cnt | ||
FROM (VALUES (1, 'Bob'), (2, 'Bob'), (1, 'Alice')) T(order_id, user_name) | ||
GROUP BY user_name; | ||
|
||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.