You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "bgeng777 (via GitHub)" <gi...@apache.org> on 2026/02/28 09:38:54 UTC

[PR] [FLINK-39163][python] Support ML_PREDICT in Python API [flink]

bgeng777 opened a new pull request, #27710:
URL: https://github.com/apache/flink/pull/27710

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   Add ML_PREDICT in PyFlink API
   
   
   ## Brief change log
   
     - Add `Model` wrapper in Python API
     - Add pytests for ML_PREDICT
   
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   
   This change added tests and can be verified as follows:
   
     - add pytests for ML_PREDICT
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (**yes** / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "bgeng777 (via GitHub)" <gi...@apache.org>.
bgeng777 commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-6147529095

   CI has been passed. Could you please help merge this pr thanks~ @dianfu 


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #27710: [FLINK-39163][python] Support ML_PREDICT in Python API
URL: https://github.com/apache/flink/pull/27710


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-4999959814

   This PR has been closed since it has not had any activity in 120 days. 
   If you feel like this was a mistake, or you would like to continue working on it, 
   please feel free to re-open the PR and ask for a review.


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-4716427161

   This PR is being marked as stale since it has not had any activity in the last 90 days. 
   If you would like to keep this PR alive, please leave a comment asking for a review. 
   If the PR has merge conflicts, update it with the latest from the base branch.
   
   If you are having difficulty finding a reviewer, please reach out to the 
   community, contact details can be found here: https://flink.apache.org/what-is-flink/community/
   
   If this PR is no longer valid or desired, please feel free to close it. 
   If no activity occurs in the next 30 days, it will be automatically closed.


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "bgeng777 (via GitHub)" <gi...@apache.org>.
bgeng777 commented on code in PR #27710:
URL: https://github.com/apache/flink/pull/27710#discussion_r4257085103


##########
flink-python/pyflink/table/model.py:
##########
@@ -0,0 +1,102 @@
+################################################################################
+#  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.
+################################################################################
+from typing import List, Dict, Optional
+
+from pyflink.java_gateway import get_gateway
+from pyflink.table.catalog import ResolvedSchema
+from pyflink.table.table import Table
+
+
+class Model(object):
+    """
+    A model object represents a machine learning model registered in the catalog.
+    It provides a way to perform predictions on input tables using the predict method.
+    """
+
+    def __init__(self, j_model):
+        self._j_model = j_model
+
+    def predict(self,
+                input_table: Table,
+                input_columns: List[str],
+                options: Optional[Dict[str, str]] = None) -> Table:
+        """
+        Performs prediction on the given input table using this model.
+
+        Example:
+        ::
+
+            >>> model = t_env.from_model("my_model")
+            >>> input_table = t_env.from_path("src")
+            >>> result_table = model.predict(input_table, ["user_comment"])
+            >>> result_table.execute_insert("prediction_result").wait()
+
+        :param input_table: The input table to perform prediction on.
+        :param input_columns: The column names from the input table to use as features.
+        :param options: Optional runtime configuration for the prediction.
+        :return: The resulting table with prediction results appended.
+        """
+        gateway = get_gateway()
+
+        # Convert input columns to Java ColumnList
+        j_input_columns = gateway.jvm.java.util.ArrayList()
+        for col_item in input_columns:
+            if isinstance(col_item, str):
+                j_input_columns.add(col_item)
+            else:
+                j_input_columns.add(str(col_item))
+        j_column_list = gateway.jvm.org.apache.flink.types.ColumnList.of(j_input_columns)
+
+        # Convert config to Java map if provided
+        if options is not None:
+            j_config = gateway.jvm.java.util.HashMap()
+            for key, value in options.items():
+                j_config.put(str(key), str(value))
+        else:
+            j_config = gateway.jvm.java.util.Collections.emptyMap()
+
+        j_result_table = self._j_model.predict(input_table._j_table, j_column_list, j_config)
+        return Table(j_result_table, input_table._t_env)
+
+    def get_resolved_input_schema(self) -> 'ResolvedSchema':
+        """
+        Returns the resolved input schema of this model.
+
+        The input schema describes the structure and data types of the input columns that the
+        model expects for inference operations.
+
+        :return: the resolved input schema.
+        """
+        j_resolved_schema = self._j_model.getResolvedInputSchema()
+        return ResolvedSchema(j_resolved_schema=j_resolved_schema)
+
+    def get_resolved_output_schema(self) -> 'ResolvedSchema':
+        """
+        Returns the resolved output schema of this model.
+
+        The output schema describes the structure and data types of the output columns that the
+        model produces during inference operations.
+
+        :return: the resolved output schema.
+        """
+        j_resolved_schema = self._j_model.getResolvedOutputSchema()
+        return ResolvedSchema(j_resolved_schema=j_resolved_schema)
+
+    @property
+    def j_model(self):

Review Comment:
   Yes, removed.



-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "bgeng777 (via GitHub)" <gi...@apache.org>.
bgeng777 commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-3982902379

   @flinkbot run azure


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-3976754881

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "71c6339537de5ef70440d04d528539950d7723ca",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "71c6339537de5ef70440d04d528539950d7723ca",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 71c6339537de5ef70440d04d528539950d7723ca 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


Re: [PR] [FLINK-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "bgeng777 (via GitHub)" <gi...@apache.org>.
bgeng777 commented on PR #27710:
URL: https://github.com/apache/flink/pull/27710#issuecomment-6142623059

   @flinkbot run azure


-- 
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-39163][python] Support ML_PREDICT in Python API [flink]

Posted by "dianfu (via GitHub)" <gi...@apache.org>.
dianfu merged PR #27710:
URL: https://github.com/apache/flink/pull/27710


-- 
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