confluent-pyflink 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- confluent_pyflink-1.0.0/MANIFEST.in +22 -0
- confluent_pyflink-1.0.0/PKG-INFO +95 -0
- confluent_pyflink-1.0.0/README.md +76 -0
- confluent_pyflink-1.0.0/confluent-flink-jars/version.py +24 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/PKG-INFO +95 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/SOURCES.txt +44 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/dependency_links.txt +1 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/not-zip-safe +1 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/requires.txt +4 -0
- confluent_pyflink-1.0.0/confluent_pyflink.egg-info/top_level.txt +1 -0
- confluent_pyflink-1.0.0/pyproject.toml +74 -0
- confluent_pyflink-1.0.0/setup.cfg +4 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/__init__.py +0 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/context/__init__.py +4 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/context/confluent_context.py +92 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/context/context.py +120 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/context/java_gateway_manager.py +417 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/context/local_context.py +58 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/__init__.py +76 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/catalog.py +47 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/changelog_mode.py +20 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/data_view.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/descriptors.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/environment_settings.py +216 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/explain_detail.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/expression.py +39 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/expressions.py +127 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/functions.py +63 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/module.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/result_kind.py +20 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/schema.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/serializers.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/sql_dialect.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/statement_set.py +20 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table.py +33 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table_config.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table_descriptor.py +192 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table_environment.py +215 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table_result.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/table_schema.py +21 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/types.py +28 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/udf.py +41 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/utils/__init__.py +18 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/utils/confluent_settings.py +230 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/utils/confluent_tools.py +213 -0
- confluent_pyflink-1.0.0/src/confluent_pyflink/table/window.py +21 -0
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
global-exclude *.py[cod] __pycache__ .DS_Store
|
|
20
|
+
graft deps/bin
|
|
21
|
+
include README.md confluent-flink-jars/version.py
|
|
22
|
+
recursive-exclude pyflink/fn_execution *
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: confluent-pyflink
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Confluent Apache Flink Table API Python
|
|
5
|
+
Author-email: Confluent <dev@confluent.io>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://confluent.io
|
|
8
|
+
Project-URL: Examples, https://github.com/confluentinc/flink-table-api-python-examples
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: apache-flink~=2.2.0
|
|
16
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
17
|
+
Requires-Dist: pyyaml
|
|
18
|
+
Requires-Dist: confluent-flink-jars==2.2.14
|
|
19
|
+
|
|
20
|
+
# Confluent Apache Flink Table API Python
|
|
21
|
+
|
|
22
|
+
This package contains the client library for running Apache Flink's Table API on Confluent Cloud.
|
|
23
|
+
|
|
24
|
+
The [Table API](https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/python/table_api_tutorial/) enables a programmatic
|
|
25
|
+
way of developing, testing, and submitting Flink pipelines for processing data streams.
|
|
26
|
+
Streams can be finite or infinite, with insert-only or changelog data. The latter allows for dealing with *Change Data
|
|
27
|
+
Capture* (CDC) events.
|
|
28
|
+
|
|
29
|
+
Within the API, you conceptually work with tables that change over time - inspired by relational databases. Write
|
|
30
|
+
a *Table Program* as a declarative and structured graph of data transformations. Table API is inspired by SQL and complements
|
|
31
|
+
it with additional tools for juggling real-time data. You can mix and match Flink SQL with Table API at any time as they
|
|
32
|
+
go hand in hand.
|
|
33
|
+
|
|
34
|
+
## Table API on Confluent Cloud
|
|
35
|
+
|
|
36
|
+
Table API on Confluent Cloud is a client-side library that delegates Flink API calls to Confluent’s public
|
|
37
|
+
REST API. It submits [Statements](https://docs.confluent.io/cloud/current/api.html#tag/Statements-(sqlv1)) and retrieves
|
|
38
|
+
[StatementResults](https://docs.confluent.io/cloud/current/api.html#tag/Statement-Results-(sqlv1)).
|
|
39
|
+
|
|
40
|
+
Table programs are implemented against [Flink's open source Table API for Python](https://github.com/apache/flink/tree/master/flink-python/pyflink/table).
|
|
41
|
+
This package repackages Flink's Python API and bundles the Confluent-specific components for powering the `TableEnvironment` without the need
|
|
42
|
+
for a local Flink cluster. While using those packages, Flink internal components such as
|
|
43
|
+
`CatalogStore`, `Catalog`, `Planner`, `Executor`, and configuration are managed by the plugin and fully integrate with
|
|
44
|
+
Confluent Cloud. Including access to Apache Kafka®, Schema Registry, and Flink Compute Pools.
|
|
45
|
+
|
|
46
|
+
Note: The Table API plugin is in Open Preview stage.
|
|
47
|
+
|
|
48
|
+
### Motivating Example
|
|
49
|
+
|
|
50
|
+
The following code shows how a Table API program is structured. Subsequent sections will go into more details how you
|
|
51
|
+
can use the examples of this repository to play around with Flink on Confluent Cloud.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from confluent_pyflink.table.utils import ConfluentSettings, ConfluentTools
|
|
55
|
+
from confluent_pyflink.table import TableEnvironment, Row
|
|
56
|
+
from confluent_pyflink.table.expressions import col, row
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def run():
|
|
60
|
+
# Setup connection properties to Confluent Cloud
|
|
61
|
+
settings = ConfluentSettings.from_global_variables()
|
|
62
|
+
env = TableEnvironment.create(settings)
|
|
63
|
+
|
|
64
|
+
# Run your first Flink statement in Table API
|
|
65
|
+
env.from_elements([row("Hello world!")]).execute().print()
|
|
66
|
+
|
|
67
|
+
# Or use SQL
|
|
68
|
+
env.sql_query("SELECT 'Hello world!'").execute().print()
|
|
69
|
+
|
|
70
|
+
# Structure your code with Table objects - the main ingredient of Table API.
|
|
71
|
+
table = (
|
|
72
|
+
env.from_path("examples.marketplace.clicks")
|
|
73
|
+
.filter(col("user_agent").like("Mozilla%"))
|
|
74
|
+
.select(col("click_id"), col("user_id"))
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
table.print_schema()
|
|
78
|
+
print(table.explain())
|
|
79
|
+
|
|
80
|
+
# Use the provided tools to test on a subset of the streaming data
|
|
81
|
+
expected = ConfluentTools.collect_materialized_limit(table, 50)
|
|
82
|
+
actual = [Row(42, 500)]
|
|
83
|
+
if expected != actual:
|
|
84
|
+
print("Results don't match!")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
run()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Further Examples
|
|
92
|
+
|
|
93
|
+
For further examples, please see Confluent's
|
|
94
|
+
[Apache Flink® Table API on Confluent Cloud Examples](https://github.com/confluentinc/flink-table-api-python-examples)
|
|
95
|
+
repository.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Confluent Apache Flink Table API Python
|
|
2
|
+
|
|
3
|
+
This package contains the client library for running Apache Flink's Table API on Confluent Cloud.
|
|
4
|
+
|
|
5
|
+
The [Table API](https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/python/table_api_tutorial/) enables a programmatic
|
|
6
|
+
way of developing, testing, and submitting Flink pipelines for processing data streams.
|
|
7
|
+
Streams can be finite or infinite, with insert-only or changelog data. The latter allows for dealing with *Change Data
|
|
8
|
+
Capture* (CDC) events.
|
|
9
|
+
|
|
10
|
+
Within the API, you conceptually work with tables that change over time - inspired by relational databases. Write
|
|
11
|
+
a *Table Program* as a declarative and structured graph of data transformations. Table API is inspired by SQL and complements
|
|
12
|
+
it with additional tools for juggling real-time data. You can mix and match Flink SQL with Table API at any time as they
|
|
13
|
+
go hand in hand.
|
|
14
|
+
|
|
15
|
+
## Table API on Confluent Cloud
|
|
16
|
+
|
|
17
|
+
Table API on Confluent Cloud is a client-side library that delegates Flink API calls to Confluent’s public
|
|
18
|
+
REST API. It submits [Statements](https://docs.confluent.io/cloud/current/api.html#tag/Statements-(sqlv1)) and retrieves
|
|
19
|
+
[StatementResults](https://docs.confluent.io/cloud/current/api.html#tag/Statement-Results-(sqlv1)).
|
|
20
|
+
|
|
21
|
+
Table programs are implemented against [Flink's open source Table API for Python](https://github.com/apache/flink/tree/master/flink-python/pyflink/table).
|
|
22
|
+
This package repackages Flink's Python API and bundles the Confluent-specific components for powering the `TableEnvironment` without the need
|
|
23
|
+
for a local Flink cluster. While using those packages, Flink internal components such as
|
|
24
|
+
`CatalogStore`, `Catalog`, `Planner`, `Executor`, and configuration are managed by the plugin and fully integrate with
|
|
25
|
+
Confluent Cloud. Including access to Apache Kafka®, Schema Registry, and Flink Compute Pools.
|
|
26
|
+
|
|
27
|
+
Note: The Table API plugin is in Open Preview stage.
|
|
28
|
+
|
|
29
|
+
### Motivating Example
|
|
30
|
+
|
|
31
|
+
The following code shows how a Table API program is structured. Subsequent sections will go into more details how you
|
|
32
|
+
can use the examples of this repository to play around with Flink on Confluent Cloud.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from confluent_pyflink.table.utils import ConfluentSettings, ConfluentTools
|
|
36
|
+
from confluent_pyflink.table import TableEnvironment, Row
|
|
37
|
+
from confluent_pyflink.table.expressions import col, row
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def run():
|
|
41
|
+
# Setup connection properties to Confluent Cloud
|
|
42
|
+
settings = ConfluentSettings.from_global_variables()
|
|
43
|
+
env = TableEnvironment.create(settings)
|
|
44
|
+
|
|
45
|
+
# Run your first Flink statement in Table API
|
|
46
|
+
env.from_elements([row("Hello world!")]).execute().print()
|
|
47
|
+
|
|
48
|
+
# Or use SQL
|
|
49
|
+
env.sql_query("SELECT 'Hello world!'").execute().print()
|
|
50
|
+
|
|
51
|
+
# Structure your code with Table objects - the main ingredient of Table API.
|
|
52
|
+
table = (
|
|
53
|
+
env.from_path("examples.marketplace.clicks")
|
|
54
|
+
.filter(col("user_agent").like("Mozilla%"))
|
|
55
|
+
.select(col("click_id"), col("user_id"))
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
table.print_schema()
|
|
59
|
+
print(table.explain())
|
|
60
|
+
|
|
61
|
+
# Use the provided tools to test on a subset of the streaming data
|
|
62
|
+
expected = ConfluentTools.collect_materialized_limit(table, 50)
|
|
63
|
+
actual = [Row(42, 500)]
|
|
64
|
+
if expected != actual:
|
|
65
|
+
print("Results don't match!")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
run()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Further Examples
|
|
73
|
+
|
|
74
|
+
For further examples, please see Confluent's
|
|
75
|
+
[Apache Flink® Table API on Confluent Cloud Examples](https://github.com/confluentinc/flink-table-api-python-examples)
|
|
76
|
+
repository.
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
The confluent-flink-jars version will be consistent with the flink version and follow the PEP440.
|
|
21
|
+
.. seealso:: https://www.python.org/dev/peps/pep-0440
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__version__ = "2.1.dev0"
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: confluent-pyflink
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Confluent Apache Flink Table API Python
|
|
5
|
+
Author-email: Confluent <dev@confluent.io>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://confluent.io
|
|
8
|
+
Project-URL: Examples, https://github.com/confluentinc/flink-table-api-python-examples
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: apache-flink~=2.2.0
|
|
16
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
17
|
+
Requires-Dist: pyyaml
|
|
18
|
+
Requires-Dist: confluent-flink-jars==2.2.14
|
|
19
|
+
|
|
20
|
+
# Confluent Apache Flink Table API Python
|
|
21
|
+
|
|
22
|
+
This package contains the client library for running Apache Flink's Table API on Confluent Cloud.
|
|
23
|
+
|
|
24
|
+
The [Table API](https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/python/table_api_tutorial/) enables a programmatic
|
|
25
|
+
way of developing, testing, and submitting Flink pipelines for processing data streams.
|
|
26
|
+
Streams can be finite or infinite, with insert-only or changelog data. The latter allows for dealing with *Change Data
|
|
27
|
+
Capture* (CDC) events.
|
|
28
|
+
|
|
29
|
+
Within the API, you conceptually work with tables that change over time - inspired by relational databases. Write
|
|
30
|
+
a *Table Program* as a declarative and structured graph of data transformations. Table API is inspired by SQL and complements
|
|
31
|
+
it with additional tools for juggling real-time data. You can mix and match Flink SQL with Table API at any time as they
|
|
32
|
+
go hand in hand.
|
|
33
|
+
|
|
34
|
+
## Table API on Confluent Cloud
|
|
35
|
+
|
|
36
|
+
Table API on Confluent Cloud is a client-side library that delegates Flink API calls to Confluent’s public
|
|
37
|
+
REST API. It submits [Statements](https://docs.confluent.io/cloud/current/api.html#tag/Statements-(sqlv1)) and retrieves
|
|
38
|
+
[StatementResults](https://docs.confluent.io/cloud/current/api.html#tag/Statement-Results-(sqlv1)).
|
|
39
|
+
|
|
40
|
+
Table programs are implemented against [Flink's open source Table API for Python](https://github.com/apache/flink/tree/master/flink-python/pyflink/table).
|
|
41
|
+
This package repackages Flink's Python API and bundles the Confluent-specific components for powering the `TableEnvironment` without the need
|
|
42
|
+
for a local Flink cluster. While using those packages, Flink internal components such as
|
|
43
|
+
`CatalogStore`, `Catalog`, `Planner`, `Executor`, and configuration are managed by the plugin and fully integrate with
|
|
44
|
+
Confluent Cloud. Including access to Apache Kafka®, Schema Registry, and Flink Compute Pools.
|
|
45
|
+
|
|
46
|
+
Note: The Table API plugin is in Open Preview stage.
|
|
47
|
+
|
|
48
|
+
### Motivating Example
|
|
49
|
+
|
|
50
|
+
The following code shows how a Table API program is structured. Subsequent sections will go into more details how you
|
|
51
|
+
can use the examples of this repository to play around with Flink on Confluent Cloud.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from confluent_pyflink.table.utils import ConfluentSettings, ConfluentTools
|
|
55
|
+
from confluent_pyflink.table import TableEnvironment, Row
|
|
56
|
+
from confluent_pyflink.table.expressions import col, row
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def run():
|
|
60
|
+
# Setup connection properties to Confluent Cloud
|
|
61
|
+
settings = ConfluentSettings.from_global_variables()
|
|
62
|
+
env = TableEnvironment.create(settings)
|
|
63
|
+
|
|
64
|
+
# Run your first Flink statement in Table API
|
|
65
|
+
env.from_elements([row("Hello world!")]).execute().print()
|
|
66
|
+
|
|
67
|
+
# Or use SQL
|
|
68
|
+
env.sql_query("SELECT 'Hello world!'").execute().print()
|
|
69
|
+
|
|
70
|
+
# Structure your code with Table objects - the main ingredient of Table API.
|
|
71
|
+
table = (
|
|
72
|
+
env.from_path("examples.marketplace.clicks")
|
|
73
|
+
.filter(col("user_agent").like("Mozilla%"))
|
|
74
|
+
.select(col("click_id"), col("user_id"))
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
table.print_schema()
|
|
78
|
+
print(table.explain())
|
|
79
|
+
|
|
80
|
+
# Use the provided tools to test on a subset of the streaming data
|
|
81
|
+
expected = ConfluentTools.collect_materialized_limit(table, 50)
|
|
82
|
+
actual = [Row(42, 500)]
|
|
83
|
+
if expected != actual:
|
|
84
|
+
print("Results don't match!")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
run()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Further Examples
|
|
92
|
+
|
|
93
|
+
For further examples, please see Confluent's
|
|
94
|
+
[Apache Flink® Table API on Confluent Cloud Examples](https://github.com/confluentinc/flink-table-api-python-examples)
|
|
95
|
+
repository.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
confluent-flink-jars/version.py
|
|
5
|
+
confluent_pyflink.egg-info/PKG-INFO
|
|
6
|
+
confluent_pyflink.egg-info/SOURCES.txt
|
|
7
|
+
confluent_pyflink.egg-info/dependency_links.txt
|
|
8
|
+
confluent_pyflink.egg-info/not-zip-safe
|
|
9
|
+
confluent_pyflink.egg-info/requires.txt
|
|
10
|
+
confluent_pyflink.egg-info/top_level.txt
|
|
11
|
+
src/confluent_pyflink/__init__.py
|
|
12
|
+
src/confluent_pyflink/context/__init__.py
|
|
13
|
+
src/confluent_pyflink/context/confluent_context.py
|
|
14
|
+
src/confluent_pyflink/context/context.py
|
|
15
|
+
src/confluent_pyflink/context/java_gateway_manager.py
|
|
16
|
+
src/confluent_pyflink/context/local_context.py
|
|
17
|
+
src/confluent_pyflink/table/__init__.py
|
|
18
|
+
src/confluent_pyflink/table/catalog.py
|
|
19
|
+
src/confluent_pyflink/table/changelog_mode.py
|
|
20
|
+
src/confluent_pyflink/table/data_view.py
|
|
21
|
+
src/confluent_pyflink/table/descriptors.py
|
|
22
|
+
src/confluent_pyflink/table/environment_settings.py
|
|
23
|
+
src/confluent_pyflink/table/explain_detail.py
|
|
24
|
+
src/confluent_pyflink/table/expression.py
|
|
25
|
+
src/confluent_pyflink/table/expressions.py
|
|
26
|
+
src/confluent_pyflink/table/functions.py
|
|
27
|
+
src/confluent_pyflink/table/module.py
|
|
28
|
+
src/confluent_pyflink/table/result_kind.py
|
|
29
|
+
src/confluent_pyflink/table/schema.py
|
|
30
|
+
src/confluent_pyflink/table/serializers.py
|
|
31
|
+
src/confluent_pyflink/table/sql_dialect.py
|
|
32
|
+
src/confluent_pyflink/table/statement_set.py
|
|
33
|
+
src/confluent_pyflink/table/table.py
|
|
34
|
+
src/confluent_pyflink/table/table_config.py
|
|
35
|
+
src/confluent_pyflink/table/table_descriptor.py
|
|
36
|
+
src/confluent_pyflink/table/table_environment.py
|
|
37
|
+
src/confluent_pyflink/table/table_result.py
|
|
38
|
+
src/confluent_pyflink/table/table_schema.py
|
|
39
|
+
src/confluent_pyflink/table/types.py
|
|
40
|
+
src/confluent_pyflink/table/udf.py
|
|
41
|
+
src/confluent_pyflink/table/window.py
|
|
42
|
+
src/confluent_pyflink/table/utils/__init__.py
|
|
43
|
+
src/confluent_pyflink/table/utils/confluent_settings.py
|
|
44
|
+
src/confluent_pyflink/table/utils/confluent_tools.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
confluent_pyflink
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=75.8", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "confluent-pyflink"
|
|
7
|
+
description = "Confluent Apache Flink Table API Python"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
version = "1.0.0"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"apache-flink~=2.2.0",
|
|
12
|
+
"pydantic-settings>=2.10.1",
|
|
13
|
+
"pyyaml",
|
|
14
|
+
"confluent-flink-jars==2.2.14"
|
|
15
|
+
]
|
|
16
|
+
authors = [
|
|
17
|
+
{name = "Confluent", email = "dev@confluent.io"}
|
|
18
|
+
]
|
|
19
|
+
license = "Apache-2.0"
|
|
20
|
+
requires-python = ">=3.9"
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
]
|
|
27
|
+
dynamic = ["scripts"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://confluent.io"
|
|
31
|
+
Examples = "https://github.com/confluentinc/flink-table-api-python-examples"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"ruff",
|
|
36
|
+
"pytest>=8.4.1"
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools]
|
|
40
|
+
zip-safe = false
|
|
41
|
+
include-package-data = true
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src", "deps"]
|
|
45
|
+
include = [
|
|
46
|
+
'confluent_pyflink',
|
|
47
|
+
'confluent_pyflink.context',
|
|
48
|
+
'confluent_pyflink.table',
|
|
49
|
+
'confluent_pyflink.table.utils',
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 101
|
|
54
|
+
indent-width = 4
|
|
55
|
+
target-version = "py39"
|
|
56
|
+
extend-exclude = ["setup_pyshell.py"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff.lint]
|
|
59
|
+
select = ["E", "F"]
|
|
60
|
+
ignore = []
|
|
61
|
+
fixable = ["ALL"]
|
|
62
|
+
unfixable = []
|
|
63
|
+
|
|
64
|
+
[tool.ruff.format]
|
|
65
|
+
quote-style = "double"
|
|
66
|
+
indent-style = "space"
|
|
67
|
+
skip-magic-trailing-comma = false
|
|
68
|
+
line-ending = "auto"
|
|
69
|
+
|
|
70
|
+
[tool.uv.sources]
|
|
71
|
+
confluent-flink-jars = { path = "confluent-flink-jars" }
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
addopts = ["--junit-xml", "TEST-result.xml",]
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from .context import Context, FlinkDirectories, InvalidFlinkHomeException
|
|
2
|
+
import os
|
|
3
|
+
import logging
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ConfluentContext(Context):
|
|
10
|
+
"""
|
|
11
|
+
An implementation of the Context class for Confluent PyFlink applications.
|
|
12
|
+
Loads classes and jars from the Confluent Flink distribution, for use with Confluent Cloud.
|
|
13
|
+
|
|
14
|
+
Use it as a context manager::
|
|
15
|
+
|
|
16
|
+
with ConfluentContext():
|
|
17
|
+
settings = ConfluentSettings(...)
|
|
18
|
+
env = TableEnvironment.create(settings)
|
|
19
|
+
env.from_elements([row("Hello world!")]).execute().print()
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def _find_confluent_flink_home(self) -> Path:
|
|
23
|
+
"""
|
|
24
|
+
Find and return the Confluent Flink home directory.
|
|
25
|
+
|
|
26
|
+
Searches for Confluent Flink home in the following order:
|
|
27
|
+
1. CONFLUENT_FLINK_HOME environment variable
|
|
28
|
+
2. PyFlink module path
|
|
29
|
+
"""
|
|
30
|
+
# If the environment has set CONFLUENT_FLINK_HOME, trust it.
|
|
31
|
+
if "CONFLUENT_FLINK_HOME" in os.environ:
|
|
32
|
+
return Path(os.environ["CONFLUENT_FLINK_HOME"])
|
|
33
|
+
else:
|
|
34
|
+
try:
|
|
35
|
+
CONFLUENT_FLINK_HOME = None
|
|
36
|
+
for module_home in __import__("confluent_pyflink").__path__:
|
|
37
|
+
CONFLUENT_FLINK_HOME = module_home
|
|
38
|
+
if CONFLUENT_FLINK_HOME is not None:
|
|
39
|
+
return Path(CONFLUENT_FLINK_HOME)
|
|
40
|
+
else:
|
|
41
|
+
raise InvalidFlinkHomeException(
|
|
42
|
+
"Could not find valid CONFLUENT_FLINK_HOME (Flink distribution directory) "
|
|
43
|
+
"in current environment."
|
|
44
|
+
)
|
|
45
|
+
except Exception as exception:
|
|
46
|
+
raise InvalidFlinkHomeException(
|
|
47
|
+
"Unable to find CONFLUENT_FLINK_HOME (Flink distribution directory) due to:"
|
|
48
|
+
) from exception
|
|
49
|
+
|
|
50
|
+
def _get_flink_directories(self) -> FlinkDirectories:
|
|
51
|
+
flink_home = self._find_flink_home()
|
|
52
|
+
confluent_flink_home = self._find_confluent_flink_home()
|
|
53
|
+
flink_dirs = FlinkDirectories.build_flink_dirs(
|
|
54
|
+
home=flink_home, default_lib=confluent_flink_home / "lib"
|
|
55
|
+
)
|
|
56
|
+
logger.debug(f"Using the following Flink directories:\n{flink_dirs}")
|
|
57
|
+
return flink_dirs
|
|
58
|
+
|
|
59
|
+
def _classes_to_load(self) -> set[str]:
|
|
60
|
+
return {
|
|
61
|
+
"org.apache.flink.table.api.*",
|
|
62
|
+
"org.apache.flink.table.legacy.api.*",
|
|
63
|
+
"org.apache.flink.table.api.config.*",
|
|
64
|
+
"org.apache.flink.table.api.java.*",
|
|
65
|
+
"org.apache.flink.table.api.bridge.java.*",
|
|
66
|
+
"org.apache.flink.table.api.dataview.*",
|
|
67
|
+
"org.apache.flink.table.catalog.*",
|
|
68
|
+
"org.apache.flink.table.descriptors.*",
|
|
69
|
+
"org.apache.flink.table.legacy.descriptors.*",
|
|
70
|
+
"org.apache.flink.table.descriptors.python.*",
|
|
71
|
+
"org.apache.flink.table.expressions.*",
|
|
72
|
+
"org.apache.flink.table.sources.*",
|
|
73
|
+
"org.apache.flink.table.legacy.sources.*",
|
|
74
|
+
"org.apache.flink.table.sinks.*",
|
|
75
|
+
"org.apache.flink.table.legacy.sinks.*",
|
|
76
|
+
"org.apache.flink.table.types.*",
|
|
77
|
+
"org.apache.flink.table.types.logical.*",
|
|
78
|
+
"org.apache.flink.table.util.python.*",
|
|
79
|
+
"org.apache.flink.api.common.python.*",
|
|
80
|
+
"org.apache.flink.api.common.typeinfo.TypeInformation",
|
|
81
|
+
"org.apache.flink.api.common.typeinfo.Types",
|
|
82
|
+
"org.apache.flink.api.java.ExecutionEnvironment",
|
|
83
|
+
"org.apache.flink.streaming.api.environment.StreamExecutionEnvironment",
|
|
84
|
+
"org.apache.flink.python.util.PythonDependencyUtils",
|
|
85
|
+
"org.apache.flink.python.PythonOptions",
|
|
86
|
+
"org.apache.flink.client.python.PythonGatewayServer",
|
|
87
|
+
"org.apache.flink.streaming.api.functions.python.*",
|
|
88
|
+
"org.apache.flink.streaming.api.operators.python.process.*",
|
|
89
|
+
"org.apache.flink.streaming.api.operators.python.embedded.*",
|
|
90
|
+
"org.apache.flink.streaming.api.typeinfo.python.*",
|
|
91
|
+
"io.confluent.flink.plugin.*",
|
|
92
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Optional
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import logging
|
|
6
|
+
from py4j.java_gateway import JavaGateway
|
|
7
|
+
import pyflink
|
|
8
|
+
from contextvars import ContextVar
|
|
9
|
+
|
|
10
|
+
from .java_gateway_manager import JavaGatewayManager, FlinkDirectories
|
|
11
|
+
|
|
12
|
+
CURRENT_CONTEXT: ContextVar[Optional["Context"]] = ContextVar("CURRENT_CONTEXT", default=None)
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_gateway_of_current_context():
|
|
17
|
+
"""
|
|
18
|
+
Get the Java gateway of the current context.
|
|
19
|
+
|
|
20
|
+
Returns the Java gateway from the current active context. If no context is set,
|
|
21
|
+
creates a ConfluentContext as the default for backward compatibility.
|
|
22
|
+
"""
|
|
23
|
+
context = CURRENT_CONTEXT.get()
|
|
24
|
+
if context is None:
|
|
25
|
+
# Inline import to avoid circular import.
|
|
26
|
+
from .confluent_context import ConfluentContext
|
|
27
|
+
|
|
28
|
+
context = ConfluentContext()
|
|
29
|
+
return context.get_gateway()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class InvalidFlinkHomeException(Exception):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Context(ABC):
|
|
37
|
+
"""
|
|
38
|
+
Abstract base class for Confluent PyFlink execution contexts.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self):
|
|
42
|
+
self._manager = JavaGatewayManager(self._get_flink_directories(), self._classes_to_load())
|
|
43
|
+
self._parent_context = None
|
|
44
|
+
context = CURRENT_CONTEXT.get()
|
|
45
|
+
if context is not None:
|
|
46
|
+
self._parent_context = context
|
|
47
|
+
CURRENT_CONTEXT.set(self)
|
|
48
|
+
|
|
49
|
+
def __enter__(self):
|
|
50
|
+
return self
|
|
51
|
+
|
|
52
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
53
|
+
self._manager.close_gateway()
|
|
54
|
+
CURRENT_CONTEXT.set(self._parent_context)
|
|
55
|
+
|
|
56
|
+
def get_gateway(self) -> JavaGateway:
|
|
57
|
+
"""
|
|
58
|
+
Get the Java gateway for this context.
|
|
59
|
+
"""
|
|
60
|
+
return self._manager.get_gateway()
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def _is_flink_home(path: Path) -> bool:
|
|
64
|
+
"""
|
|
65
|
+
Check if the given path is a valid Flink home directory.
|
|
66
|
+
"""
|
|
67
|
+
flink_script_file = path / "bin" / "flink"
|
|
68
|
+
return flink_script_file.exists()
|
|
69
|
+
|
|
70
|
+
@classmethod
|
|
71
|
+
def _find_flink_home(cls) -> Path:
|
|
72
|
+
"""
|
|
73
|
+
Find and return the Flink home directory.
|
|
74
|
+
|
|
75
|
+
Searches for Flink home in the following order:
|
|
76
|
+
1. FLINK_HOME environment variable
|
|
77
|
+
3. PyFlink module path
|
|
78
|
+
"""
|
|
79
|
+
# If the environment has set FLINK_HOME, trust it.
|
|
80
|
+
if "FLINK_HOME" in os.environ:
|
|
81
|
+
return Path(os.environ["FLINK_HOME"])
|
|
82
|
+
else:
|
|
83
|
+
try:
|
|
84
|
+
FLINK_HOME = None
|
|
85
|
+
for module_home in pyflink.__path__:
|
|
86
|
+
module_path = Path(module_home)
|
|
87
|
+
if cls._is_flink_home(module_path):
|
|
88
|
+
FLINK_HOME = module_path
|
|
89
|
+
|
|
90
|
+
if FLINK_HOME is not None:
|
|
91
|
+
return FLINK_HOME
|
|
92
|
+
else:
|
|
93
|
+
raise InvalidFlinkHomeException(
|
|
94
|
+
"Could not find valid FLINK_HOME (Flink distribution directory) "
|
|
95
|
+
"in current environment."
|
|
96
|
+
)
|
|
97
|
+
except Exception as exception:
|
|
98
|
+
raise InvalidFlinkHomeException(
|
|
99
|
+
"Unable to find FLINK_HOME (Flink distribution directory) due to:"
|
|
100
|
+
) from exception
|
|
101
|
+
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def _get_flink_directories(self) -> FlinkDirectories:
|
|
104
|
+
"""
|
|
105
|
+
Get the Flink directories configuration for this context.
|
|
106
|
+
|
|
107
|
+
Abstract method that must be implemented by subclasses to specify
|
|
108
|
+
the Flink directory structure to use.
|
|
109
|
+
"""
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
@abstractmethod
|
|
113
|
+
def _classes_to_load(self) -> set[str]:
|
|
114
|
+
"""
|
|
115
|
+
Get the set of Java classes to load for this context.
|
|
116
|
+
|
|
117
|
+
Abstract method that must be implemented by subclasses to specify
|
|
118
|
+
which Java classes should be loaded into the gateway.
|
|
119
|
+
"""
|
|
120
|
+
pass
|