snuyanzin commented on code in PR #25834: URL: https://github.com/apache/flink/pull/25834#discussion_r1957366433
########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/converters/SqlAlterModelSetConverter.java: ########## @@ -0,0 +1,105 @@ +/* + * 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.planner.operations.converters; + +import org.apache.flink.sql.parser.ddl.SqlAlterModelSet; +import org.apache.flink.table.api.ValidationException; +import org.apache.flink.table.catalog.CatalogManager; +import org.apache.flink.table.catalog.ContextResolvedModel; +import org.apache.flink.table.catalog.ModelChange; +import org.apache.flink.table.catalog.ObjectIdentifier; +import org.apache.flink.table.catalog.ResolvedCatalogModel; +import org.apache.flink.table.catalog.UnresolvedIdentifier; +import org.apache.flink.table.operations.Operation; +import org.apache.flink.table.operations.ddl.AlterModelChangeOperation; +import org.apache.flink.table.planner.utils.OperationConverterUtils; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.stream.Collectors; + +/** A converter for {@link org.apache.flink.sql.parser.ddl.SqlAlterModelSet}. */ +public class SqlAlterModelSetConverter implements SqlNodeConverter<SqlAlterModelSet> { + + @Override + public Operation convertSqlNode(SqlAlterModelSet sqlAlterModelSet, ConvertContext context) { + final CatalogManager catalogManager = context.getCatalogManager(); + UnresolvedIdentifier unresolvedIdentifier = + UnresolvedIdentifier.of(sqlAlterModelSet.fullModelName()); + ObjectIdentifier modelIdentifier = catalogManager.qualifyIdentifier(unresolvedIdentifier); + Optional<ContextResolvedModel> optionalCatalogModel = + catalogManager.getModel(modelIdentifier); + if (optionalCatalogModel.isEmpty() || optionalCatalogModel.get().isTemporary()) { + if (optionalCatalogModel.isEmpty()) { + if (!sqlAlterModelSet.ifModelExists()) { + throw new ValidationException( + String.format("Model %s doesn't exist.", modelIdentifier)); + } + } else if (optionalCatalogModel.get().isTemporary()) { + throw new ValidationException( + String.format("Model %s is a temporary model.", modelIdentifier)); + } + } + ResolvedCatalogModel existingModel = + optionalCatalogModel.map(ContextResolvedModel::getResolvedModel).orElse(null); Review Comment: This code seems to be same for `SqlAlterModelRenameConverter`, `SqlAlterModelResetConverter`, `SqlAlterModelSetConverter` should we extract the common logic into some utils or base class for those 3? -- 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]
