Skip to content

Commit 37e25f2

Browse files
authored
[FLINK-36919][table] Add missing dropTable/dropView methods to TableEnvironment
1 parent 7fa4f78 commit 37e25f2

File tree

8 files changed

+371
-228
lines changed

8 files changed

+371
-228
lines changed

docs/content.zh/docs/dev/python/table/table_environment.md

+22
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ TableEnvironment API
132132
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_view" name="链接">}}
133133
</td>
134134
</tr>
135+
<tr>
136+
<td>
137+
<strong>drop_view(view_path, ignore_if_not_exists=True)</strong>
138+
</td>
139+
<td>
140+
Drops a view registered in the given path.
141+
</td>
142+
<td class="text-center">
143+
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_view" name="link">}}
144+
</td>
145+
</tr>
135146
<tr>
136147
<td>
137148
<strong>drop_temporary_table(table_path)</strong>
@@ -144,6 +155,17 @@ TableEnvironment API
144155
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_table" name="链接">}}
145156
</td>
146157
</tr>
158+
<tr>
159+
<td>
160+
<strong>drop_table(table_path, ignore_if_not_exists=True)</strong>
161+
</td>
162+
<td>
163+
Drops a table registered under the given path.
164+
</td>
165+
<td class="text-center">
166+
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_table" name="link">}}
167+
</td>
168+
</tr>
147169
<tr>
148170
<td>
149171
<strong>execute_sql(stmt)</strong>

docs/content/docs/dev/python/table/table_environment.md

+22
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ These APIs are used to create/remove Table API/SQL Tables and write queries:
132132
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_view" name="link">}}
133133
</td>
134134
</tr>
135+
<tr>
136+
<td>
137+
<strong>drop_view(view_path, ignore_if_not_exists=True)</strong>
138+
</td>
139+
<td>
140+
Drops a view registered in the given path.
141+
</td>
142+
<td class="text-center">
143+
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_view" name="link">}}
144+
</td>
145+
</tr>
135146
<tr>
136147
<td>
137148
<strong>drop_temporary_table(table_path)</strong>
@@ -144,6 +155,17 @@ These APIs are used to create/remove Table API/SQL Tables and write queries:
144155
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_table" name="link">}}
145156
</td>
146157
</tr>
158+
<tr>
159+
<td>
160+
<strong>drop_table(table_path, ignore_if_not_exists=True)</strong>
161+
</td>
162+
<td>
163+
Drops a table registered under the given path.
164+
</td>
165+
<td class="text-center">
166+
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_table" name="link">}}
167+
</td>
168+
</tr>
147169
<tr>
148170
<td>
149171
<strong>execute_sql(stmt)</strong>

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

+2
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
162162
TableEnvironment.create_temporary_table
163163
TableEnvironment.create_temporary_view
164164
TableEnvironment.drop_function
165+
TableEnvironment.drop_table
165166
TableEnvironment.drop_temporary_function
166167
TableEnvironment.drop_temporary_system_function
167168
TableEnvironment.drop_temporary_table
168169
TableEnvironment.drop_temporary_view
170+
TableEnvironment.drop_view
169171
TableEnvironment.execute_sql
170172
TableEnvironment.explain_sql
171173
TableEnvironment.from_descriptor

flink-python/pyflink/table/table_environment.py

+33
Original file line numberDiff line numberDiff line change
@@ -657,19 +657,52 @@ def drop_temporary_table(self, table_path: str) -> bool:
657657
"""
658658
return self._j_tenv.dropTemporaryTable(table_path)
659659

660+
def drop_table(self, table_path: str, ignore_if_not_exists: Optional[bool] = True) -> bool:
661+
"""
662+
Drops a table registered in the given path.
663+
664+
This method can only drop permanent objects. Temporary objects can shadow permanent ones.
665+
If a temporary object exists in a given path,
666+
make sure to drop the temporary object first using :func:`drop_temporary_table`.
667+
668+
:param table_path: The path of the registered table.
669+
:param ignore_if_not_exists: Ignore if table does not exist.
670+
:return: True if a table existed in the given path and was removed.
671+
672+
.. versionadded:: 2.0.0
673+
"""
674+
return self._j_tenv.dropTable(table_path, ignore_if_not_exists)
675+
660676
def drop_temporary_view(self, view_path: str) -> bool:
661677
"""
662678
Drops a temporary view registered in the given path.
663679
664680
If a permanent table or view with a given path exists, it will be used
665681
from now on for any queries that reference this path.
666682
683+
:param view_path: The path of the registered temporary view.
667684
:return: True if a view existed in the given path and was removed.
668685
669686
.. versionadded:: 1.10.0
670687
"""
671688
return self._j_tenv.dropTemporaryView(view_path)
672689

690+
def drop_view(self, view_path: str, ignore_if_not_exists: Optional[bool] = True) -> bool:
691+
"""
692+
Drops a view registered in the given path.
693+
694+
This method can only drop permanent objects. Temporary objects can shadow permanent ones.
695+
If a temporary object exists in a given path,
696+
make sure to drop the temporary object first using :func:`drop_temporary_view`.
697+
698+
:param view_path: The path of the registered view.
699+
:param ignore_if_not_exists: Ignore if view does not exist.
700+
:return: True if a view existed in the given path and was removed
701+
702+
.. versionadded:: 2.0.0
703+
"""
704+
return self._j_tenv.dropView(view_path, ignore_if_not_exists)
705+
673706
def explain_sql(self, stmt: str, *extra_details: ExplainDetail) -> str:
674707
"""
675708
Returns the AST of the specified statement and the execution plan.

flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/TableEnvironment.java

+70
Original file line numberDiff line numberDiff line change
@@ -1026,20 +1026,90 @@ void createTemporarySystemFunction(
10261026
* <p>If a permanent table with a given path exists, it will be used from now on for any queries
10271027
* that reference this path.
10281028
*
1029+
* @param path The given path under which the temporary table will be dropped. See also the
1030+
* {@link TableEnvironment} class description for the format of the path.
10291031
* @return true if a table existed in the given path and was removed
10301032
*/
10311033
boolean dropTemporaryTable(String path);
10321034

1035+
/**
1036+
* Drops a table registered in the given path.
1037+
*
1038+
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
1039+
* If a temporary object exists in a given path, make sure to drop the temporary object first
1040+
* using {@link #dropTemporaryTable}.
1041+
*
1042+
* <p>Compared to SQL, this method will not throw an error if the table does not exist. Use
1043+
* {@link #dropTable(java.lang.String, boolean)} to change the default behavior.
1044+
*
1045+
* @param path The given path under which the table will be dropped. See also the {@link
1046+
* TableEnvironment} class description for the format of the path.
1047+
* @return true if table existed in the given path and was dropped, false if table didn't exist
1048+
* in the given path.
1049+
*/
1050+
boolean dropTable(String path);
1051+
1052+
/**
1053+
* Drops a table registered in the given path.
1054+
*
1055+
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
1056+
* If a temporary object exists in a given path, make sure to drop the temporary object first
1057+
* using {@link #dropTemporaryTable}.
1058+
*
1059+
* @param path The given path under which the given table will be dropped. See also the {@link
1060+
* TableEnvironment} class description for the format of the path.
1061+
* @param ignoreIfNotExists If false exception will be thrown if the view to drop does not
1062+
* exist.
1063+
* @return true if table existed in the given path and was dropped, false if table didn't exist
1064+
* in the given path.
1065+
*/
1066+
boolean dropTable(String path, boolean ignoreIfNotExists);
1067+
10331068
/**
10341069
* Drops a temporary view registered in the given path.
10351070
*
10361071
* <p>If a permanent table or view with a given path exists, it will be used from now on for any
10371072
* queries that reference this path.
10381073
*
1074+
* @param path The given path under which the temporary view will be dropped. See also the
1075+
* {@link TableEnvironment} class description for the format of the path.
10391076
* @return true if a view existed in the given path and was removed
10401077
*/
10411078
boolean dropTemporaryView(String path);
10421079

1080+
/**
1081+
* Drops a view registered in the given path.
1082+
*
1083+
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
1084+
* If a temporary object exists in a given path, make sure to drop the temporary object first
1085+
* using {@link #dropTemporaryView}.
1086+
*
1087+
* <p>Compared to SQL, this method will not throw an error if the view does not exist. Use
1088+
* {@link #dropView(java.lang.String, boolean)} to change the default behavior.
1089+
*
1090+
* @param path The given path under which the view will be dropped. See also the {@link
1091+
* TableEnvironment} class description for the format of the path.
1092+
* @return true if view existed in the given path and was dropped, false if view didn't exist in
1093+
* the given path.
1094+
*/
1095+
boolean dropView(String path);
1096+
1097+
/**
1098+
* Drops a view registered in the given path.
1099+
*
1100+
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
1101+
* If a temporary object exists in a given path, make sure to drop the temporary object first
1102+
* using {@link #dropTemporaryView}.
1103+
*
1104+
* @param path The given path under which the view will be dropped. See also the {@link
1105+
* TableEnvironment} class description for the format of the path.
1106+
* @param ignoreIfNotExists If false exception will be thrown if the view to drop does not
1107+
* exist.
1108+
* @return true if view existed in the given path and was dropped, false if view didn't exist in
1109+
* the given path and ignoreIfNotExists was true.
1110+
*/
1111+
boolean dropView(String path, boolean ignoreIfNotExists);
1112+
10431113
/**
10441114
* Returns the AST of the specified statement and the execution plan to compute the result of
10451115
* the given statement.

flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java

+24
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,18 @@ public boolean dropTemporaryTable(String path) {
649649
}
650650
}
651651

652+
@Override
653+
public boolean dropTable(String path) {
654+
return dropTable(path, true);
655+
}
656+
657+
@Override
658+
public boolean dropTable(String path, boolean ignoreIfNotExists) {
659+
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
660+
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
661+
return catalogManager.dropTable(identifier, ignoreIfNotExists);
662+
}
663+
652664
@Override
653665
public boolean dropTemporaryView(String path) {
654666
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
@@ -661,6 +673,18 @@ public boolean dropTemporaryView(String path) {
661673
}
662674
}
663675

676+
@Override
677+
public boolean dropView(String path) {
678+
return dropView(path, true);
679+
}
680+
681+
@Override
682+
public boolean dropView(String path, boolean ignoreIfNotExists) {
683+
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
684+
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
685+
return catalogManager.dropView(identifier, ignoreIfNotExists);
686+
}
687+
664688
@Override
665689
public String[] listUserDefinedFunctions() {
666690
String[] functions = functionCatalog.getUserDefinedFunctions();

0 commit comments

Comments
 (0)