You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "lihaosky (via GitHub)" <gi...@apache.org> on 2025/05/20 06:23:37 UTC
[PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
lihaosky opened a new pull request, #26577:
URL: https://github.com/apache/flink/pull/26577
## What is the purpose of the change
Add model provider related interfaces proposed in https://cwiki.apache.org/confluence/display/FLINK/FLIP-525%3A+Model+ML_PREDICT%2C+ML_EVALUATE+Implementation+Design
## Brief change log
Introduce following classes:
* `ModelProviderFactory`
* `ModelProvider`
* `PredictRuntimeProvider`
* `AsyncPredictRuntimeProvider`
* `PredictFunction`
* `AsyncPredictFunction`
Modified
* `Catalog` to add `getModelProviderFactory`
* `Module` to add `getModelProviderFactory`
## Verifying this change
All new interfaces. Test will be added in following up PRs using these interfaces
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes)
- The serializers: (no)
- The runtime per-record code paths (performance sensitive): (no)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (yes)
- If yes, how is the feature documented? (JavaDocs)
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "fsk119 (via GitHub)" <gi...@apache.org>.
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "fsk119 (via GitHub)" <gi...@apache.org>.
fsk119 merged PR #26577:
URL: https://github.com/apache/flink/pull/26577
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "lihaosky (via GitHub)" <gi...@apache.org>.
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #26577:
URL: https://github.com/apache/flink/pull/26577#discussion_r2097413063
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/PredictFunction.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.util.FlinkRuntimeException;
+
+import java.util.Collection;
+
+/**
+ * A wrapper class of {@link TableFunction} for synchronously model inference.
Review Comment:
nit:synchronously -> synchronous
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "lihaosky (via GitHub)" <gi...@apache.org>.
lihaosky commented on code in PR #26577:
URL: https://github.com/apache/flink/pull/26577#discussion_r2097042431
##########
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:
This is newly added which is not in FLIP
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-37790][4/N] introduce model provider related interfaces [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26577:
URL: https://github.com/apache/flink/pull/26577#issuecomment-2893115080
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "15e9b065fe0085465812652a70190c05e2ab5cd4",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "15e9b065fe0085465812652a70190c05e2ab5cd4",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 15e9b065fe0085465812652a70190c05e2ab5cd4 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org