snuyanzin commented on code in PR #26385: URL: https://github.com/apache/flink/pull/26385#discussion_r2031877160
########## flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/ModelDescriptor.java: ########## @@ -0,0 +1,244 @@ +/* + * 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; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigurationUtils; +import org.apache.flink.table.catalog.CatalogModel; +import org.apache.flink.table.factories.FactoryUtil; +import org.apache.flink.table.utils.EncodingUtils; +import org.apache.flink.util.Preconditions; + +import javax.annotation.Nullable; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Describes a {@link CatalogModel} representing a model. + * + * <p>A {@link ModelDescriptor} is a template for creating a {@link CatalogModel} instance. It + * closely resembles the "CREATE MODEL" SQL DDL statement, containing input schema, output schema, + * and other characteristics. + * + * <p>This can be used to register a Model in the Table API. + */ +@PublicEvolving +public class ModelDescriptor { + private final @Nullable Schema inputSchema; + private final @Nullable Schema outputSchema; + private final Map<String, String> modelOptions; + private final @Nullable String comment; + + protected ModelDescriptor( + @Nullable Schema inputSchema, + @Nullable Schema outputSchema, + Map<String, String> modelOptions, + @Nullable String comment) { + this.inputSchema = inputSchema; + this.outputSchema = outputSchema; + this.modelOptions = modelOptions; + this.comment = comment; + } + + /** Converts this descriptor into a {@link CatalogModel}. */ + public CatalogModel toCatalogModel() { + final Schema inputSchema = + getInputSchema() + .orElseThrow( + () -> + new ValidationException( + "Input schema missing in ModelDescriptor. Input schema cannot be null.")); + final Schema outputSchema = + getOutputSchema() + .orElseThrow( + () -> + new ValidationException( + "Output schema missing in ModelDescriptor. Output schema cannot be null.")); + return CatalogModel.of(inputSchema, outputSchema, modelOptions, comment); + } + + /** Converts this immutable instance into a mutable {@link Builder}. */ + public Builder toBuilder() { + return new Builder(this); + } + + /** + * Returns a map of string-based model options. + * + * @return options of the model. + */ + Map<String, String> getOptions() { + return modelOptions; Review Comment: I wonder whether we need to make it unmodifiable before exposing like that -- 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