godfreyhe commented on a change in pull request #15089:
URL: https://github.com/apache/flink/pull/15089#discussion_r589216628



##########
File path: 
flink-table/flink-sql-client/src/test/resources/sql/catalog_database.q
##########
@@ -0,0 +1,323 @@
+# catalog_database.q - CREATE/DROP/SHOW/USE CATALOG/DATABASE
+# you can run CliClientITCase to test this sql script
+# ==========================================================================
+#
+# 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.
+
+# ==========================================================================
+# validation test
+# ==========================================================================
+
+use non_existing_db;
+[ERROR] Could not execute SQL statement. Reason:
+org.apache.flink.table.catalog.exceptions.CatalogException: A database with 
name [non_existing_db] does not exist in the catalog: [default_catalog].
+!error
+
+use catalog non_existing_catalog;
+[ERROR] Could not execute SQL statement. Reason:
+org.apache.flink.table.catalog.exceptions.CatalogException: A catalog with 
name [non_existing_catalog] does not exist.
+!error
+
+# ==========================================================================
+# test catalog
+# ==========================================================================
+
+create catalog c1 with ('type'='generic_in_memory');

Review comment:
       add an invalid test case for `create catalog`

##########
File path: 
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlScriptReader.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.client.cli.utils;
+
+import javax.annotation.Nullable;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A utility to read and parse content of a SQL script. The SQL script is 
located in "resources/sql"
+ * path and in the "xx.q" file name pattern. The SQL script is executed and 
tested by {@link

Review comment:
       add some pattern example for xx.q file in this doc, and list the 
constraint of the supported pattern.

##########
File path: flink-table/flink-sql-client/src/test/resources/sql/set.q
##########
@@ -0,0 +1,80 @@
+# set.q - SET/RESET configuration
+# you can run CliClientITCase to test this sql script
+# ==========================================================================
+#
+# 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.
+
+# validation test
+set execution.parallelism = 10a;

Review comment:
       add some cases to override the default properties and then call `set` or 
`reset`

##########
File path: 
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlScriptReader.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.client.cli.utils;
+
+import javax.annotation.Nullable;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A utility to read and parse content of a SQL script. The SQL script is 
located in "resources/sql"
+ * path and in the "xx.q" file name pattern. The SQL script is executed and 
tested by {@link
+ * org.apache.flink.table.client.cli.CliClientITCase}.
+ */
+public final class SqlScriptReader implements AutoCloseable {
+
+    private final BufferedReader reader;
+    private String currentLine;
+
+    public static List<TestSqlStatement> parseSqlScript(String in) {
+        try (SqlScriptReader sqlReader = new SqlScriptReader(in)) {
+            return sqlReader.parseSqlScript();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private SqlScriptReader(String input) {
+        this.reader = new BufferedReader(new StringReader(input));
+    }
+
+    private List<TestSqlStatement> parseSqlScript() throws IOException {
+        List<TestSqlStatement> specs = new ArrayList<>();
+        TestSqlStatement spec;
+        while ((spec = readNext()) != null) {
+            specs.add(spec);
+        }
+        return specs;
+    }
+
+    private void readLine() throws IOException {
+        this.currentLine = reader.readLine();
+    }
+
+    private @Nullable TestSqlStatement readNext() throws IOException {
+        StringBuilder commentLines = new StringBuilder();
+        StringBuilder sqlLines = new StringBuilder();
+        ReadingStatus status = ReadingStatus.BEGINNING;
+        readLine();
+        while (currentLine != null) {
+            switch (status) {

Review comment:
       what if there is an invalid sql file, what's the behavior of this method

##########
File path: 
flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlScriptReader.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.client.cli.utils;
+
+import javax.annotation.Nullable;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A utility to read and parse content of a SQL script. The SQL script is 
located in "resources/sql"
+ * path and in the "xx.q" file name pattern. The SQL script is executed and 
tested by {@link
+ * org.apache.flink.table.client.cli.CliClientITCase}.
+ */
+public final class SqlScriptReader implements AutoCloseable {
+
+    private final BufferedReader reader;
+    private String currentLine;
+
+    public static List<TestSqlStatement> parseSqlScript(String in) {
+        try (SqlScriptReader sqlReader = new SqlScriptReader(in)) {
+            return sqlReader.parseSqlScript();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private SqlScriptReader(String input) {
+        this.reader = new BufferedReader(new StringReader(input));
+    }
+
+    private List<TestSqlStatement> parseSqlScript() throws IOException {
+        List<TestSqlStatement> specs = new ArrayList<>();
+        TestSqlStatement spec;
+        while ((spec = readNext()) != null) {
+            specs.add(spec);
+        }
+        return specs;
+    }
+
+    private void readLine() throws IOException {
+        this.currentLine = reader.readLine();
+    }
+
+    private @Nullable TestSqlStatement readNext() throws IOException {
+        StringBuilder commentLines = new StringBuilder();
+        StringBuilder sqlLines = new StringBuilder();
+        ReadingStatus status = ReadingStatus.BEGINNING;
+        readLine();
+        while (currentLine != null) {
+            switch (status) {
+                case BEGINNING:
+                    if (currentLine.startsWith("#") || 
currentLine.trim().length() == 0) {
+                        commentLines.append(currentLine).append("\n");
+                        // continue reading if not reach SQL statement
+                        readLine();
+                    } else {
+                        // if current currentLine is not comment and empty 
currentLine, begin to
+                        // read SQL
+                        status = ReadingStatus.SQL_STATEMENT;
+                    }
+                    break;
+
+                case SQL_STATEMENT:
+                    sqlLines.append(currentLine).append("\n");
+                    if (currentLine.trim().endsWith(";")) {

Review comment:
       how about multiple sql statements (e.g. insert statement)

##########
File path: 
flink-table/flink-sql-client/src/test/resources/sql/catalog_database.q
##########
@@ -0,0 +1,323 @@
+# catalog_database.q - CREATE/DROP/SHOW/USE CATALOG/DATABASE
+# you can run CliClientITCase to test this sql script
+# ==========================================================================
+#
+# 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.
+
+# ==========================================================================
+# validation test
+# ==========================================================================
+
+use non_existing_db;
+[ERROR] Could not execute SQL statement. Reason:
+org.apache.flink.table.catalog.exceptions.CatalogException: A database with 
name [non_existing_db] does not exist in the catalog: [default_catalog].
+!error
+
+use catalog non_existing_catalog;
+[ERROR] Could not execute SQL statement. Reason:
+org.apache.flink.table.catalog.exceptions.CatalogException: A catalog with 
name [non_existing_catalog] does not exist.
+!error
+
+# ==========================================================================
+# test catalog
+# ==========================================================================
+
+create catalog c1 with ('type'='generic_in_memory');
+[INFO] Catalog has been created.
+!info
+
+show catalogs;
+c1
+default_catalog
+!ok
+
+show current catalog;
+default_catalog
+!ok
+
+use catalog c1;
+[INFO] Catalog changed.
+!info
+
+show current catalog;
+c1
+!ok
+
+drop catalog default_catalog;
+[INFO] Catalog has been removed.
+!info
+
+# ==========================================================================
+# test database
+# ==========================================================================
+
+create database db1;
+[INFO] Database has been created.
+!info
+
+show databases;
+default
+db1
+!ok
+
+show current database;
+default
+!ok
+
+use db1;
+[INFO] Database changed.
+!info
+
+show current database;
+db1
+!ok
+
+create database db2 comment 'db2_comment' with ('k1' = 'v1');

Review comment:
       ditto

##########
File path: flink-table/flink-sql-client/src/test/resources/sql/select.q
##########
@@ -0,0 +1,65 @@
+# select.q - SELECT query
+# you can run CliClientITCase to test this sql script
+# ==========================================================================
+#
+# 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.
+
+# ==========================================================================
+# test stream query with tableau result mode
+# (we can't test changelog mode and table mode in IT case)
+# ==========================================================================
+
+SET execution.type = streaming;
+[INFO] Session property has been set.
+!info
+
+SET execution.result-mode = tableau;
+[INFO] Session property has been set.
+!info
+
+SELECT id, COUNT(*) as cnt, COUNT(DISTINCT str) as uv

Review comment:
       add some invalid case




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to