lihaosky commented on code in PR #26577: URL: https://github.com/apache/flink/pull/26577#discussion_r2098342931
########## 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: ml -> machine learning sounds more generic. ml is not limited to models. Reference: https://github.com/apache/flink-ml/tree/master/flink-ml-core/src/main/java/org/apache/flink/ml I can move it to `org.apache.flink.table.ml` ########## 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: From `getFactory`'s comment, looks it's mainly for table factory even though it returns `Factory` which can be `ModelFactory`. Because there's `getFunctionDefinitionFactory`, I feel it's ok to add `getModelProviderFactory` so that a catalog can provide all of them. Otherwise, it's hard to provide both table factory and model factory? But I have no strong opinion here and it can be added later on as well. Will remove it ########## 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: Record can have PII but I'm ok adding it in open source to be consistent with others ########## 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: Sure. We can use `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