twalthr commented on code in PR #25195:
URL: https://github.com/apache/flink/pull/25195#discussion_r1714729815


##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/internal/ShowCreateUtilTest.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.api.internal;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogView;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedCatalogView;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.TableDistribution;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test {@link ShowCreateUtil}. */
+public class ShowCreateUtilTest {
+    private static final ObjectIdentifier TABLE_IDENTIFIER =
+            ObjectIdentifier.of("catalogName", "dbName", "tableName");
+    private static final ObjectIdentifier VIEW_IDENTIFIER =
+            ObjectIdentifier.of("catalogName", "dbName", "viewName");
+
+    private static final ResolvedSchema ONE_COLUMN_SCHEMA =
+            ResolvedSchema.of(Column.physical("id", DataTypes.INT()));
+
+    private static final ResolvedSchema TWO_COLUMNS_SCHEMA =
+            ResolvedSchema.of(
+                    Column.physical("id", DataTypes.INT()),
+                    Column.physical("name", DataTypes.STRING()));
+
+    @ParameterizedTest(name = "{index}: {1}")
+    @MethodSource("argsForShowCreateTable")
+    void showCreateTable(ResolvedCatalogTable resolvedCatalogTable, String 
expected) {
+        final String createViewString =

Review Comment:
   ```suggestion
           final String createTableString =
   ```



##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/internal/ShowCreateUtilTest.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * 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.api.internal;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogView;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedCatalogView;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.TableDistribution;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test {@link ShowCreateUtil}. */
+public class ShowCreateUtilTest {
+    private static final ObjectIdentifier TABLE_IDENTIFIER =
+            ObjectIdentifier.of("catalogName", "dbName", "tableName");
+    private static final ObjectIdentifier VIEW_IDENTIFIER =
+            ObjectIdentifier.of("catalogName", "dbName", "viewName");
+
+    private static final ResolvedSchema ONE_COLUMN_SCHEMA =
+            ResolvedSchema.of(Column.physical("id", DataTypes.INT()));
+
+    private static final ResolvedSchema TWO_COLUMNS_SCHEMA =
+            ResolvedSchema.of(
+                    Column.physical("id", DataTypes.INT()),
+                    Column.physical("name", DataTypes.STRING()));
+
+    @ParameterizedTest(name = "{index}: {1}")
+    @MethodSource("argsForShowCreateTable")
+    void showCreateTable(ResolvedCatalogTable resolvedCatalogTable, String 
expected) {
+        final String createViewString =
+                ShowCreateUtil.buildShowCreateTableRow(
+                        resolvedCatalogTable, TABLE_IDENTIFIER, false);
+        assertThat(createViewString).isEqualTo(expected);
+    }
+
+    @ParameterizedTest(name = "{index}: {1}")
+    @MethodSource("argsForShowCreateView")
+    void showCreateView(ResolvedCatalogView resolvedCatalogView, String 
expected) {
+        final String createViewString =
+                ShowCreateUtil.buildShowCreateViewRow(resolvedCatalogView, 
VIEW_IDENTIFIER, false);
+        assertThat(createViewString).isEqualTo(expected);
+    }
+
+    private static Collection<Arguments> argsForShowCreateView() {
+        Collection<Arguments> argList = new ArrayList<>();
+        argList.add(
+                Arguments.of(
+                        createResolvedView(ONE_COLUMN_SCHEMA, "SELECT 1", 
"SELECT 1", null),
+                        "CREATE VIEW `catalogName`.`dbName`.`viewName` (\n"
+                                + "  `id`\n"
+                                + ") AS SELECT 1\n"));
+
+        argList.add(
+                Arguments.of(
+                        createResolvedView(
+                                TWO_COLUMNS_SCHEMA,
+                                "SELECT id, name FROM tbl_a",
+                                "SELECT id, name FROM 
`catalogName`.`dbName`.`tbl_a`",
+                                "View comment"),
+                        "CREATE VIEW `catalogName`.`dbName`.`viewName` (\n"
+                                + "  `id`,\n"
+                                + "  `name`\n"
+                                + ") COMMENT 'View comment'\n"
+                                + "AS SELECT id, name FROM 
`catalogName`.`dbName`.`tbl_a`\n"));
+        return argList;
+    }
+
+    private static Collection<Arguments> argsForShowCreateTable() {
+        Collection<Arguments> argList = new ArrayList<>();
+        argList.add(
+                Arguments.of(
+                        createResolvedTable(
+                                ONE_COLUMN_SCHEMA,
+                                Collections.emptyMap(),
+                                Collections.emptyList(),
+                                TableDistribution.of(
+                                        TableDistribution.Kind.HASH,
+                                        2,
+                                        Arrays.asList("key1", "key2")),
+                                null),
+                        "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n"
+                                + "  `id` INT\n"
+                                + ") DISTRIBUTED BY HASH(`key1`, `key2`) INTO 
2 BUCKETS\n"));
+
+        argList.add(
+                Arguments.of(
+                        createResolvedTable(
+                                ONE_COLUMN_SCHEMA,
+                                Collections.emptyMap(),
+                                Collections.emptyList(),
+                                TableDistribution.of(
+                                        TableDistribution.Kind.RANGE, 2, 
Arrays.asList("1", "10")),
+                                "Table comment"),
+                        "CREATE TABLE `catalogName`.`dbName`.`tableName` (\n"
+                                + "  `id` INT\n"
+                                + ") COMMENT 'Table comment'\n"

Review Comment:
   It's weird that COMMENT causes a newline at the end whereas other subclauses 
don't. We should fix this or we will never fix it. Can we add a `\n` after `)`:
   
   ```
   CREATE TABLE `catalog`.`database`.`t` (
     `s` VARCHAR(2147483647)
   )
   DISTRIBUTED INTO 6 BUCKETS
   WITH (
     'k' = 'v'
   )
   ```
   
   ```
   CREATE TABLE `catalog`.`database`.`t` (
     `s` VARCHAR(2147483647)
   )
   COMMENT 'comment'
   DISTRIBUTED INTO 6 BUCKETS
   WITH (
     'k' = 'v'
   )
   ```
   
   ```
   CREATE TABLE `catalog`.`database`.`t` (
     `s` VARCHAR(2147483647)
   )
   COMMENT 'comment'
   DISTRIBUTED INTO 6 BUCKETS
   PARTITIONED BY (`key1`, `key2`)
   WITH (
     'k' = 'v'
   )
   ```
   
   ```
   CREATE VIEW `catalogName`.`dbName`.`viewName` (
     `id`
     `name`
   )
   COMMENT 'View comment'
   AS SELECT ...
   ```



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to