fsk119 commented on code in PR #26577: URL: https://github.com/apache/flink/pull/26577#discussion_r2097313226
########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/connector/ml/ModelProvider.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.connector.ml; Review Comment: org.apache.flink.table.model? ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/AsyncPredictFunction.java: ########## @@ -0,0 +1,61 @@ +/* + * 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.functions; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.table.api.TableException; +import org.apache.flink.table.data.GenericRowData; +import org.apache.flink.table.data.RowData; + +import java.util.Collection; +import java.util.concurrent.CompletableFuture; + +/** + * A wrapper class of {@link AsyncTableFunction} for asynchronously model inference. + * + * <p>The output type of this table function is fixed as {@link RowData}. + */ +@PublicEvolving +public abstract class AsyncPredictFunction extends AsyncTableFunction<RowData> { + + /** + * Asynchronously predict result based on input row. + * + * @param inputRow - A {@link RowData} that wraps input for predict function. + * @return A collection of all predicted results. + */ + public abstract CompletableFuture<Collection<RowData>> asyncPredict(RowData inputRow); + + /** Invokes {@link #asyncPredict} and chains futures. */ + public void eval(CompletableFuture<Collection<RowData>> future, Object... args) { + GenericRowData argsData = GenericRowData.of(args); + asyncPredict(argsData) + .whenComplete( + (result, exception) -> { + if (exception != null) { + future.completeExceptionally( + new TableException( + "Failed to execute asynchronously prediction.", Review Comment: nit: we can add record information in the error message. ``` future.completeExceptionally( new TableException( String.format( "Failed to asynchronously lookup entries with key '%s'", keyRow), exception)); return; ``` ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/module/Module.java: ########## @@ -111,5 +113,27 @@ default Optional<DynamicTableSinkFactory> getTableSinkFactory() { return Optional.empty(); } + /** + * Returns a {@link ModelProviderFactory} for creating model providers. + * + * <p>A factory is determined with the following precedence rule: + * + * <ul> + * <li>1. Factory provided by the corresponding catalog of a persisted model. See {@link + * Catalog#getModelProviderFactory()} Review Comment: I perfer to use Catalog#getFactory ########## flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/Catalog.java: ########## @@ -96,6 +98,16 @@ default Optional<FunctionDefinitionFactory> getFunctionDefinitionFactory() { return Optional.empty(); } + /** + * Get an optional {@link ModelProviderFactory} instance that's responsible for creating {@link + * ModelProvider}. + * + * @return an optional ModelProviderFactory instance + */ + default Optional<ModelProviderFactory> getModelProviderFactory() { Review Comment: Could you explain the motivation to add this? Why we can not reuse `Catalog#getFactory` -- 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