Skip to content

Commit

Permalink
[FLINK-36919][table] Add missing dropTable/dropView methods to TableE…
Browse files Browse the repository at this point in the history
…nvironment
  • Loading branch information
snuyanzin authored Dec 22, 2024
1 parent 7fa4f78 commit 37e25f2
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 228 deletions.
22 changes: 22 additions & 0 deletions docs/content.zh/docs/dev/python/table/table_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ TableEnvironment API
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_view" name="链接">}}
</td>
</tr>
<tr>
<td>
<strong>drop_view(view_path, ignore_if_not_exists=True)</strong>
</td>
<td>
Drops a view registered in the given path.
</td>
<td class="text-center">
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_view" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>drop_temporary_table(table_path)</strong>
Expand All @@ -144,6 +155,17 @@ TableEnvironment API
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_table" name="链接">}}
</td>
</tr>
<tr>
<td>
<strong>drop_table(table_path, ignore_if_not_exists=True)</strong>
</td>
<td>
Drops a table registered under the given path.
</td>
<td class="text-center">
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_table" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>execute_sql(stmt)</strong>
Expand Down
22 changes: 22 additions & 0 deletions docs/content/docs/dev/python/table/table_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ These APIs are used to create/remove Table API/SQL Tables and write queries:
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_view" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>drop_view(view_path, ignore_if_not_exists=True)</strong>
</td>
<td>
Drops a view registered in the given path.
</td>
<td class="text-center">
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_view" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>drop_temporary_table(table_path)</strong>
Expand All @@ -144,6 +155,17 @@ These APIs are used to create/remove Table API/SQL Tables and write queries:
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_temporary_table" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>drop_table(table_path, ignore_if_not_exists=True)</strong>
</td>
<td>
Drops a table registered under the given path.
</td>
<td class="text-center">
{{< pythondoc file="pyflink.table.html#pyflink.table.TableEnvironment.drop_table" name="link">}}
</td>
</tr>
<tr>
<td>
<strong>execute_sql(stmt)</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ keyword, thus must be escaped) in a catalog named 'cat.1' and database named 'db
TableEnvironment.create_temporary_table
TableEnvironment.create_temporary_view
TableEnvironment.drop_function
TableEnvironment.drop_table
TableEnvironment.drop_temporary_function
TableEnvironment.drop_temporary_system_function
TableEnvironment.drop_temporary_table
TableEnvironment.drop_temporary_view
TableEnvironment.drop_view
TableEnvironment.execute_sql
TableEnvironment.explain_sql
TableEnvironment.from_descriptor
Expand Down
33 changes: 33 additions & 0 deletions flink-python/pyflink/table/table_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,19 +657,52 @@ def drop_temporary_table(self, table_path: str) -> bool:
"""
return self._j_tenv.dropTemporaryTable(table_path)

def drop_table(self, table_path: str, ignore_if_not_exists: Optional[bool] = True) -> bool:
"""
Drops a table registered in the given path.
This method can only drop permanent objects. Temporary objects can shadow permanent ones.
If a temporary object exists in a given path,
make sure to drop the temporary object first using :func:`drop_temporary_table`.
:param table_path: The path of the registered table.
:param ignore_if_not_exists: Ignore if table does not exist.
:return: True if a table existed in the given path and was removed.
.. versionadded:: 2.0.0
"""
return self._j_tenv.dropTable(table_path, ignore_if_not_exists)

def drop_temporary_view(self, view_path: str) -> bool:
"""
Drops a temporary view registered in the given path.
If a permanent table or view with a given path exists, it will be used
from now on for any queries that reference this path.
:param view_path: The path of the registered temporary view.
:return: True if a view existed in the given path and was removed.
.. versionadded:: 1.10.0
"""
return self._j_tenv.dropTemporaryView(view_path)

def drop_view(self, view_path: str, ignore_if_not_exists: Optional[bool] = True) -> bool:
"""
Drops a view registered in the given path.
This method can only drop permanent objects. Temporary objects can shadow permanent ones.
If a temporary object exists in a given path,
make sure to drop the temporary object first using :func:`drop_temporary_view`.
:param view_path: The path of the registered view.
:param ignore_if_not_exists: Ignore if view does not exist.
:return: True if a view existed in the given path and was removed
.. versionadded:: 2.0.0
"""
return self._j_tenv.dropView(view_path, ignore_if_not_exists)

def explain_sql(self, stmt: str, *extra_details: ExplainDetail) -> str:
"""
Returns the AST of the specified statement and the execution plan.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,20 +1026,90 @@ void createTemporarySystemFunction(
* <p>If a permanent table with a given path exists, it will be used from now on for any queries
* that reference this path.
*
* @param path The given path under which the temporary table will be dropped. See also the
* {@link TableEnvironment} class description for the format of the path.
* @return true if a table existed in the given path and was removed
*/
boolean dropTemporaryTable(String path);

/**
* Drops a table registered in the given path.
*
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
* If a temporary object exists in a given path, make sure to drop the temporary object first
* using {@link #dropTemporaryTable}.
*
* <p>Compared to SQL, this method will not throw an error if the table does not exist. Use
* {@link #dropTable(java.lang.String, boolean)} to change the default behavior.
*
* @param path The given path under which the table will be dropped. See also the {@link
* TableEnvironment} class description for the format of the path.
* @return true if table existed in the given path and was dropped, false if table didn't exist
* in the given path.
*/
boolean dropTable(String path);

/**
* Drops a table registered in the given path.
*
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
* If a temporary object exists in a given path, make sure to drop the temporary object first
* using {@link #dropTemporaryTable}.
*
* @param path The given path under which the given table will be dropped. See also the {@link
* TableEnvironment} class description for the format of the path.
* @param ignoreIfNotExists If false exception will be thrown if the view to drop does not
* exist.
* @return true if table existed in the given path and was dropped, false if table didn't exist
* in the given path.
*/
boolean dropTable(String path, boolean ignoreIfNotExists);

/**
* Drops a temporary view registered in the given path.
*
* <p>If a permanent table or view with a given path exists, it will be used from now on for any
* queries that reference this path.
*
* @param path The given path under which the temporary view will be dropped. See also the
* {@link TableEnvironment} class description for the format of the path.
* @return true if a view existed in the given path and was removed
*/
boolean dropTemporaryView(String path);

/**
* Drops a view registered in the given path.
*
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
* If a temporary object exists in a given path, make sure to drop the temporary object first
* using {@link #dropTemporaryView}.
*
* <p>Compared to SQL, this method will not throw an error if the view does not exist. Use
* {@link #dropView(java.lang.String, boolean)} to change the default behavior.
*
* @param path The given path under which the view will be dropped. See also the {@link
* TableEnvironment} class description for the format of the path.
* @return true if view existed in the given path and was dropped, false if view didn't exist in
* the given path.
*/
boolean dropView(String path);

/**
* Drops a view registered in the given path.
*
* <p>This method can only drop permanent objects. Temporary objects can shadow permanent ones.
* If a temporary object exists in a given path, make sure to drop the temporary object first
* using {@link #dropTemporaryView}.
*
* @param path The given path under which the view will be dropped. See also the {@link
* TableEnvironment} class description for the format of the path.
* @param ignoreIfNotExists If false exception will be thrown if the view to drop does not
* exist.
* @return true if view existed in the given path and was dropped, false if view didn't exist in
* the given path and ignoreIfNotExists was true.
*/
boolean dropView(String path, boolean ignoreIfNotExists);

/**
* Returns the AST of the specified statement and the execution plan to compute the result of
* the given statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,18 @@ public boolean dropTemporaryTable(String path) {
}
}

@Override
public boolean dropTable(String path) {
return dropTable(path, true);
}

@Override
public boolean dropTable(String path, boolean ignoreIfNotExists) {
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
return catalogManager.dropTable(identifier, ignoreIfNotExists);
}

@Override
public boolean dropTemporaryView(String path) {
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
Expand All @@ -661,6 +673,18 @@ public boolean dropTemporaryView(String path) {
}
}

@Override
public boolean dropView(String path) {
return dropView(path, true);
}

@Override
public boolean dropView(String path, boolean ignoreIfNotExists) {
UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
return catalogManager.dropView(identifier, ignoreIfNotExists);
}

@Override
public String[] listUserDefinedFunctions() {
String[] functions = functionCatalog.getUserDefinedFunctions();
Expand Down
Loading

0 comments on commit 37e25f2

Please sign in to comment.