wuchong commented on a change in pull request #16723:
URL: https://github.com/apache/flink/pull/16723#discussion_r698484240



##########
File path: 
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentITCase.scala
##########
@@ -808,6 +808,162 @@ class TableEnvironmentITCase(tableEnvName: String, 
isStreaming: Boolean) extends
     listener.close()
   }
 
+  // `SHOW COLUMNS ......` syntax of flink SQL test cases.
+  @Test
+  def testShowColumnsSyntaxOfSQL(): Unit = {

Review comment:
       This test is a little verbose and we have many more similar statements 
to test, actually, they dont' have much thing to do with `TableEnvironment`. 
Could you extract the test into a separate test class, e.g. `ExecuteSqlTest`. 
   

##########
File path: 
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentITCase.scala
##########
@@ -808,6 +808,162 @@ class TableEnvironmentITCase(tableEnvName: String, 
isStreaming: Boolean) extends
     listener.close()
   }
 
+  // `SHOW COLUMNS ......` syntax of flink SQL test cases.
+  @Test
+  def testShowColumnsSyntaxOfSQL(): Unit = {
+
+    initTableAndView()
+    // Tests `SHOW COLUMNS FROM TABLE`.
+    showAllColumnsFromTable()
+    showColumnsWithLikeClauseFromTable()
+    showColumnsWithNotLikeClauseFromTable()
+
+    // Tests `SHOW COLUMNS FROM VIEW`.
+    showAllColumnsFromView()
+    showColumnsWithLikeClauseFromView()
+    showColumnsWithNotLikeClauseFromView()
+
+  }
+
+  private def initTableAndView(): Unit = {
+    val createClause: String =
+      s"""
+         |CREATE TABLE IF NOT EXISTS orders (
+         | `user` BIGINT NOT NULl,
+         | `product` VARCHAR(32),
+         | `amount` INT,
+         | PRIMARY KEY(`user`) NOT ENFORCED
+         |) """.stripMargin
+    var createWithClause: String =
+      s"""
+         |with (
+         | 'connector' = 'datagen'
+         |)""".stripMargin
+    if (!isStreaming) {
+      val sinkPath = _tempFolder.newFolder().toString
+      createWithClause =
+        s"""
+           |with (
+           |  'connector' = 'filesystem',
+           |  'path' = '$sinkPath',
+           |  'format' = 'testcsv'
+           |)""".stripMargin
+    }
+    tEnv.executeSql(createClause + createWithClause)
+    tEnv.executeSql("create view orders_view as select * from orders")
+  }
+
+  private def showAllColumnsFromTable(): Unit = {
+    val expectedResultStr: String = "[" +
+      "+I[user, BIGINT, false, PRI(user), null, null], " +
+      "+I[product, VARCHAR(32), true, null, null, null], " +
+      "+I[amount, INT, true, null, null, null]" +
+      "]"

Review comment:
       The expected result would be better to be Row list, we avoid to compare 
Rows by string. 

##########
File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/ShowColumnsOperation.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.operations;
+
+import org.apache.flink.table.catalog.ObjectIdentifier;
+
+/** Show columns from [[catalog.]database.]table. */
+public class ShowColumnsOperation implements ShowOperation {
+
+    private ObjectIdentifier tableIdentifier;
+    private boolean useLike;
+    private boolean notLike;
+    private String likePattern;

Review comment:
       Could you make all the member fields to be `final`? It would be safer to 
make the structure immutable. 




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


Reply via email to