LadyForest commented on code in PR #24932: URL: https://github.com/apache/flink/pull/24932#discussion_r1638176317
########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogComment.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.sql.parser.ddl; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** ALTER CATALOG catalog_name COMMENT 'comment'. */ +public class SqlAlterCatalogComment extends SqlAlterCatalog { + + private final SqlCharStringLiteral comment; + + public SqlAlterCatalogComment( + SqlParserPos position, SqlIdentifier catalogName, SqlCharStringLiteral comment) { + super(position, catalogName); + this.comment = requireNonNull(comment, "comment cannot be null"); + } + + @Override + public List<SqlNode> getOperandList() { + return ImmutableNullableList.of(catalogName, comment); + } + + public SqlCharStringLiteral getComment() { Review Comment: I didn't see any reference to this method; remove it? ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -176,6 +176,15 @@ SqlAlterCatalog SqlAlterCatalog() : catalogName, propertyList); } + | + <COMMENT> <QUOTED_STRING> + { + String p = SqlParserUtil.parseString(token.image); + comment = SqlLiteral.createCharString(p, getPos()); Review Comment: Use `StringLiteral()` instead ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogComment.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.sql.parser.ddl; + +import org.apache.calcite.sql.SqlCharStringLiteral; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +/** ALTER CATALOG catalog_name COMMENT 'comment'. */ +public class SqlAlterCatalogComment extends SqlAlterCatalog { + + private final SqlCharStringLiteral comment; + + public SqlAlterCatalogComment( + SqlParserPos position, SqlIdentifier catalogName, SqlCharStringLiteral comment) { + super(position, catalogName); + this.comment = requireNonNull(comment, "comment cannot be null"); + } + + @Override + public List<SqlNode> getOperandList() { + return ImmutableNullableList.of(catalogName, comment); + } + + public SqlCharStringLiteral getComment() { + return comment; + } + + public String getCommentAsString() { + return comment.getValueAs(String.class); + } Review Comment: ```suggestion public String getComment() { return comment.getValueAs(NlsString.class).getValue(); } ``` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/CatalogDescriptor.java: ########## @@ -48,18 +51,29 @@ public Configuration getConfiguration() { return configuration; } - private CatalogDescriptor(String catalogName, Configuration configuration) { + public String getComment() { + return comment; + } Review Comment: ```suggestion public Optional<String> getComment() { return Optional.ofNullable(comment); } ``` ########## flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java: ########## @@ -84,8 +84,7 @@ public TableResultInternal execute(Context ctx) { "type", properties.getOrDefault( CommonCatalogOptions.CATALOG_TYPE.key(), "")), - // TODO: Show the catalog comment until FLINK-34918 is resolved - Arrays.asList("comment", ""))); + Arrays.asList("comment", catalogDescriptor.getComment()))); Review Comment: `Arrays.asList("comment", catalogDescriptor.getComment().orElse("")` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/CatalogDescriptor.java: ########## @@ -40,6 +40,9 @@ public class CatalogDescriptor { /* The configuration used to discover and construct the catalog. */ private final Configuration configuration; + /* Catalog comment. */ + private final String comment; Review Comment: Add `@Nullable` annotation since comment is not mandatory. ########## flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java: ########## @@ -327,11 +328,15 @@ public void createCatalog(String catalogName, CatalogDescriptor catalogDescripto * * @param catalogName the given catalog name under which to alter the given catalog * @param catalogUpdater catalog configuration updater to alter catalog + * @param catalogCommentUpdater catalog comment updater to alter catalog * @throws CatalogException If the catalog neither exists in the catalog store nor in the * initialized catalogs, or if an error occurs while creating the catalog or storing the * {@link CatalogDescriptor} */ - public void alterCatalog(String catalogName, Consumer<Configuration> catalogUpdater) + public void alterCatalog( + String catalogName, + Consumer<Configuration> catalogUpdater, + Function<String, String> catalogCommentUpdater) Review Comment: That's not a good idea. Maybe we should support something like `CatalogChange` to update the `Catalog`, similar to how `TableChange` works. ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/CatalogDescriptor.java: ########## @@ -48,18 +51,29 @@ public Configuration getConfiguration() { return configuration; } - private CatalogDescriptor(String catalogName, Configuration configuration) { + public String getComment() { + return comment; + } + + private CatalogDescriptor(String catalogName, Configuration configuration, String comment) { Review Comment: Add `@Nullable` to comment -- 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]
