Skip to content

Commit 3c31e64

Browse files
authored
[FLINK-25986][python] Add remaining FLIP-190 API methods to Python Table API
This closes #26281.
1 parent c89c416 commit 3c31e64

28 files changed

+948
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.. ################################################################################
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
################################################################################
18+
19+
20+
==============
21+
Compiled Plans
22+
==============
23+
24+
CompiledPlan
25+
------------
26+
27+
Represents an immutable, fully optimized, and executable entity that has been compiled from a
28+
Table & SQL API pipeline definition. It encodes operators, expressions, functions, data types,
29+
and table connectors.
30+
31+
Every new Flink version might introduce improved optimizer rules, more efficient operators,
32+
and other changes that impact the behavior of previously defined pipelines. In order to ensure
33+
backwards compatibility and enable stateful streaming job upgrades, compiled plans can be
34+
persisted and reloaded across Flink versions. See the
35+
`website documentation <https://flink.apache.org/documentation/>`_ for more information about
36+
provided guarantees during stateful pipeline upgrades.
37+
38+
A plan can be compiled from a SQL query using
39+
:func:`~pyflink.table.TableEnvironment.compile_plan_sql`.
40+
It can be persisted using :func:`~pyflink.table.CompiledPlan.write_to_file` or by manually
41+
extracting the JSON representation with func:`~pyflink.table.CompiledPlan.as_json_string`.
42+
A plan can be loaded back from a file or a string using
43+
:func:`~pyflink.table.TableEnvironment.load_plan` with a :class:`~pyflink.table.PlanReference`.
44+
Instances can be executed using :func:`~pyflink.table.CompiledPlan.execute`.
45+
46+
Depending on the configuration, permanent catalog metadata (such as information about tables
47+
and functions) will be persisted in the plan as well. Anonymous/inline objects will be
48+
persisted (including schema and options) if possible or fail the compilation otherwise.
49+
For temporary objects, only the identifier is part of the plan and the object needs to be
50+
present in the session context during a restore.
51+
52+
JSON encoding is assumed to be the default representation of a compiled plan in all API
53+
endpoints, and is the format used to persist the plan to files by default.
54+
For advanced use cases, :func:`~pyflink.table.CompiledPlan.as_smile_bytes` provides a binary
55+
format representation of the compiled plan.
56+
57+
.. note::
58+
Plan restores assume a stable session context. Configuration, loaded modules and
59+
catalogs, and temporary objects must not change. Schema evolution and changes of function
60+
signatures are not supported.
61+
62+
.. currentmodule:: pyflink.table
63+
64+
.. autosummary::
65+
:toctree: api/
66+
67+
CompiledPlan.as_json_string
68+
CompiledPlan.as_smile_bytes
69+
CompiledPlan.write_to_file
70+
CompiledPlan.get_flink_version
71+
CompiledPlan.print_json_string
72+
CompiledPlan.execute
73+
CompiledPlan.explain
74+
CompiledPlan.print_explain
75+
76+
PlanReference
77+
-------------
78+
79+
Unresolved pointer to a persisted plan.
80+
81+
A plan represents a static, executable entity that has been compiled from a Table & SQL API
82+
pipeline definition.
83+
84+
You can load the content of this reference into a :class:`~pyflink.table.CompiledPlan`
85+
using :func:`~pyflink.table.TableEnvironment.load_plan` with a
86+
:class:`~pyflink.table.PlanReference`, or you can directly load and execute it with
87+
:func:`~pyflink.table.TableEnvironment.execute_plan`.
88+
89+
.. seealso:: :class:`~pyflink.table.CompiledPlan`
90+
91+
.. currentmodule:: pyflink.table
92+
93+
.. autosummary::
94+
:toctree: api/
95+
96+
PlanReference.from_file
97+
PlanReference.from_json_string
98+
PlanReference.from_smile_bytes

flink-python/docs/reference/pyflink.table/descriptors.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TableSchema
111111

112112
A table schema that represents a table's structure with field names and data types.
113113

114-
.. currentmodule:: pyflink.table.table_schema
114+
.. currentmodule:: pyflink.table
115115

116116
.. autosummary::
117117
:toctree: api/
@@ -132,7 +132,7 @@ ChangelogMode
132132

133133
The set of changes contained in a changelog.
134134

135-
.. currentmodule:: pyflink.table.changelog_mode
135+
.. currentmodule:: pyflink.table
136136

137137
.. autosummary::
138138
:toctree: api/
@@ -147,11 +147,13 @@ TablePipeline
147147

148148
Describes a complete pipeline from one or more source tables to a sink table.
149149

150-
.. currentmodule:: pyflink.table.table_pipeline
150+
.. currentmodule:: pyflink.table
151151

152152
.. autosummary::
153153
:toctree: api/
154154

155+
TablePipeline.compile_plan
155156
TablePipeline.execute
156157
TablePipeline.explain
158+
TablePipeline.print_explain
157159
TablePipeline.get_sink_identifier

flink-python/docs/reference/pyflink.table/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ This page gives an overview of all public PyFlink Table API.
3434
descriptors
3535
statement_set
3636
catalog
37+
compiled_plans

flink-python/docs/reference/pyflink.table/statement_set.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ The planner can optimize all added statements together and then submit them as o
2828

2929
The added statements will be cleared when calling the :func:`~StatementSet.execute` method.
3030

31-
.. currentmodule:: pyflink.table.statement_set
31+
.. currentmodule:: pyflink.table
3232

3333
.. autosummary::
3434
:toctree: api/
3535

3636
StatementSet.add_insert_sql
3737
StatementSet.attach_as_datastream
3838
StatementSet.add_insert
39+
StatementSet.compile_plan
3940
StatementSet.explain
41+
StatementSet.print_explain
4042
StatementSet.execute
4143

4244

@@ -45,7 +47,7 @@ TableResult
4547

4648
A :class:`~pyflink.table.TableResult` is the representation of the statement execution result.
4749

48-
.. currentmodule:: pyflink.table.table_result
50+
.. currentmodule:: pyflink.table
4951

5052
.. autosummary::
5153
:toctree: api/
@@ -73,7 +75,7 @@ The statement (e.g. DDL, USE) executes successfully, and the result only contain
7375
The statement (e.g. DML, DQL, SHOW) executes successfully, and the result contains important
7476
content.
7577

76-
.. currentmodule:: pyflink.table.table_result
78+
.. currentmodule:: pyflink.table
7779

7880
.. autosummary::
7981
:toctree: api/

flink-python/docs/reference/pyflink.table/table.rst

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Example:
8888
Table.execute
8989
Table.execute_insert
9090
Table.explain
91+
Table.print_explain
9192
Table.fetch
9293
Table.filter
9394
Table.flat_aggregate

flink-python/docs/reference/pyflink.table/table_environment.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Example:
4242
:func:`~EnvironmentSettings.in_streaming_mode` or :func:`~EnvironmentSettings.in_batch_mode`
4343
might be convenient as shortcuts.
4444

45-
.. currentmodule:: pyflink.table.environment_settings
45+
.. currentmodule:: pyflink.table
4646

4747
.. autosummary::
4848
:toctree: api/
@@ -144,13 +144,14 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
144144
other Flink APIs, it might be necessary to use one of the available language-specific table
145145
environments in the corresponding bridging modules.
146146

147-
.. currentmodule:: pyflink.table.table_environment
147+
.. currentmodule:: pyflink.table
148148

149149
.. autosummary::
150150
:toctree: api/
151151

152152
TableEnvironment.add_python_archive
153153
TableEnvironment.add_python_file
154+
TableEnvironment.compile_plan_sql
154155
TableEnvironment.create
155156
TableEnvironment.create_java_function
156157
TableEnvironment.create_java_temporary_function
@@ -169,6 +170,7 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
169170
TableEnvironment.drop_temporary_table
170171
TableEnvironment.drop_temporary_view
171172
TableEnvironment.drop_view
173+
TableEnvironment.execute_plan
172174
TableEnvironment.execute_sql
173175
TableEnvironment.explain_sql
174176
TableEnvironment.from_descriptor
@@ -190,6 +192,7 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
190192
TableEnvironment.list_user_defined_functions
191193
TableEnvironment.list_views
192194
TableEnvironment.load_module
195+
TableEnvironment.load_plan
193196
TableEnvironment.create_catalog
194197
TableEnvironment.register_catalog
195198
TableEnvironment.set_python_requirements
@@ -202,7 +205,7 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
202205
StreamTableEnvironment
203206
----------------------
204207

205-
.. currentmodule:: pyflink.table.table_environment
208+
.. currentmodule:: pyflink.table
206209

207210
.. autosummary::
208211
:toctree: api/

flink-python/pyflink/table/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@
113113
from __future__ import absolute_import
114114

115115
from pyflink.table.changelog_mode import ChangelogMode
116+
from pyflink.table.compiled_plan import CompiledPlan
116117
from pyflink.table.data_view import DataView, ListView, MapView
117118
from pyflink.table.environment_settings import EnvironmentSettings
118119
from pyflink.table.explain_detail import ExplainDetail
119120
from pyflink.table.expression import Expression
120121
from pyflink.table.module import Module, ModuleEntry
122+
from pyflink.table.plan_reference import PlanReference
121123
from pyflink.table.result_kind import ResultKind
122124
from pyflink.table.schema import Schema
123125
from pyflink.table.sql_dialect import SqlDialect
@@ -127,6 +129,7 @@
127129
from pyflink.table.table_config import TableConfig
128130
from pyflink.table.table_descriptor import TableDescriptor, FormatDescriptor
129131
from pyflink.table.table_environment import (TableEnvironment, StreamTableEnvironment)
132+
from pyflink.table.table_pipeline import TablePipeline
130133
from pyflink.table.table_result import TableResult
131134
from pyflink.table.table_schema import TableSchema
132135
from pyflink.table.types import DataTypes, UserDefinedType, Row, RowKind
@@ -168,4 +171,7 @@
168171
'ChangelogMode',
169172
'ExplainDetail',
170173
'ResultKind',
174+
'CompiledPlan',
175+
'PlanReference',
176+
'TablePipeline'
171177
]

0 commit comments

Comments
 (0)