You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by di...@apache.org on 2022/06/10 10:58:11 UTC
[flink] branch master updated: [FLINK-27935][python][docs] Add Pyflink example of create temporary view document
This is an automated email from the ASF dual-hosted git repository.
dianfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new e50e66fe9fd [FLINK-27935][python][docs] Add Pyflink example of create temporary view document
e50e66fe9fd is described below
commit e50e66fe9fd848cccada278936937614136d9911
Author: Mingde Peng <pe...@gmail.com>
AuthorDate: Thu Jun 9 10:52:30 2022 +0800
[FLINK-27935][python][docs] Add Pyflink example of create temporary view document
This closes #19918.
---
docs/content.zh/docs/dev/table/common.md | 51 +++++++++++++++++++++++++++++---
docs/content/docs/dev/table/common.md | 43 +++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/docs/content.zh/docs/dev/table/common.md b/docs/content.zh/docs/dev/table/common.md
index 83d0ddacdcc..bf6772f3f61 100644
--- a/docs/content.zh/docs/dev/table/common.md
+++ b/docs/content.zh/docs/dev/table/common.md
@@ -322,6 +322,8 @@ table_env.register_table("projectedTable", proj_table)
Such tables can either be created using the Table API directly, or by switching to SQL DDL.
+{{< tabs "059e9a56-282c-5e78-98d3-85be5abd04a2" >}}
+{{< tab "Java" >}}
```java
// Using table descriptors
final TableDescriptor sourceDescriptor = TableDescriptor.forConnector("datagen")
@@ -337,6 +339,25 @@ tableEnv.createTemporaryTable("SourceTableB", sourceDescriptor);
// Using SQL DDL
tableEnv.executeSql("CREATE [TEMPORARY] TABLE MyTable (...) WITH (...)");
```
+{{< /tab >}}
+{{< tab "Python" >}}
+```python
+# Using table descriptors
+source_descriptor = TableDescriptor.for_connector("datagen") \
+ .schema(Schema.new_builder()
+ .column("f0", DataTypes.STRING())
+ .build()) \
+ .option("rows-per-second", "100") \
+ .build()
+
+t_env.create_table("SourceTableA", source_descriptor)
+t_env.create_temporary_table("SourceTableB", source_descriptor)
+
+# Using SQL DDL
+t_env.execute_sql("CREATE [TEMPORARY] TABLE MyTable (...) WITH (...)")
+```
+{{< /tab >}}
+{{< /tabs >}}
<a name="expanding-table-identifiers"></a>
@@ -386,22 +407,44 @@ tEnv.useDatabase("custom_database")
val table: Table = ...
// register the view named 'exampleView' in the catalog named 'custom_catalog'
-// in the database named 'custom_database'
+// in the database named 'custom_database'
tableEnv.createTemporaryView("exampleView", table)
// register the view named 'exampleView' in the catalog named 'custom_catalog'
-// in the database named 'other_database'
+// in the database named 'other_database'
tableEnv.createTemporaryView("other_database.exampleView", table)
// register the view named 'example.View' in the catalog named 'custom_catalog'
-// in the database named 'custom_database'
+// in the database named 'custom_database'
tableEnv.createTemporaryView("`example.View`", table)
// register the view named 'exampleView' in the catalog named 'other_catalog'
-// in the database named 'other_database'
+// in the database named 'other_database'
tableEnv.createTemporaryView("other_catalog.other_database.exampleView", table)
```
{{< /tab >}}
+{{< tab "Python" >}}
+```python
+# get a TableEnvironment
+t_env = TableEnvironment.create(...)
+t_env.use_catalog("custom_catalog")
+t_env.use_database("custom_database")
+
+table = ...
+
+# register the view named 'exampleView' in the catalog named 'custom_catalog'
+# in the database named 'custom_database'
+t_env.create_temporary_view("other_database.exampleView", table)
+
+# register the view named 'example.View' in the catalog named 'custom_catalog'
+# in the database named 'custom_database'
+t_env.create_temporary_view("`example.View`", table)
+
+# register the view named 'exampleView' in the catalog named 'other_catalog'
+# in the database named 'other_database'
+t_env.create_temporary_view("other_catalog.other_database.exampleView", table)
+```
+{{< /tab >}}
{{< /tabs >}}
<a name="query-a-table"></a>
diff --git a/docs/content/docs/dev/table/common.md b/docs/content/docs/dev/table/common.md
index 3aad29f7e01..607d7e7c174 100644
--- a/docs/content/docs/dev/table/common.md
+++ b/docs/content/docs/dev/table/common.md
@@ -331,6 +331,8 @@ The connector describes the external system that stores the data of a table. Sto
Such tables can either be created using the Table API directly, or by switching to SQL DDL.
+{{< tabs "059e9a56-282c-5e78-98d3-85be5abd04a2" >}}
+{{< tab "Java" >}}
```java
// Using table descriptors
final TableDescriptor sourceDescriptor = TableDescriptor.forConnector("datagen")
@@ -346,6 +348,25 @@ tableEnv.createTemporaryTable("SourceTableB", sourceDescriptor);
// Using SQL DDL
tableEnv.executeSql("CREATE [TEMPORARY] TABLE MyTable (...) WITH (...)");
```
+{{< /tab >}}
+{{< tab "Python" >}}
+```python
+# Using table descriptors
+source_descriptor = TableDescriptor.for_connector("datagen") \
+ .schema(Schema.new_builder()
+ .column("f0", DataTypes.STRING())
+ .build()) \
+ .option("rows-per-second", "100") \
+ .build()
+
+t_env.create_table("SourceTableA", source_descriptor)
+t_env.create_temporary_table("SourceTableB", source_descriptor)
+
+# Using SQL DDL
+t_env.execute_sql("CREATE [TEMPORARY] TABLE MyTable (...) WITH (...)")
+```
+{{< /tab >}}
+{{< /tabs >}}
### Expanding Table identifiers
@@ -411,6 +432,28 @@ tableEnv.createTemporaryView("`example.View`", table)
tableEnv.createTemporaryView("other_catalog.other_database.exampleView", table)
```
{{< /tab >}}
+{{< tab "Python" >}}
+```python
+# get a TableEnvironment
+t_env = TableEnvironment.create(...)
+t_env.use_catalog("custom_catalog")
+t_env.use_database("custom_database")
+
+table = ...
+
+# register the view named 'exampleView' in the catalog named 'custom_catalog'
+# in the database named 'custom_database'
+t_env.create_temporary_view("other_database.exampleView", table)
+
+# register the view named 'example.View' in the catalog named 'custom_catalog'
+# in the database named 'custom_database'
+t_env.create_temporary_view("`example.View`", table)
+
+# register the view named 'exampleView' in the catalog named 'other_catalog'
+# in the database named 'other_database'
+t_env.create_temporary_view("other_catalog.other_database.exampleView", table)
+```
+{{< /tab >}}
{{< /tabs >}}
Query a Table