[ 
https://issues.apache.org/jira/browse/SPARK-62356?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-62356:
-----------------------------------
    Labels: pull-request-available  (was: )

> SHOW TABLE EXTENDED fails with TABLE_OR_VIEW_NOT_FOUND when a table in the 
> namespace is dropped
> -----------------------------------------------------------------------------------------------
>
>                 Key: SPARK-62356
>                 URL: https://issues.apache.org/jira/browse/SPARK-62356
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.5.9, 4.3.0, 4.2.1, 4.0.5, 4.1.4
>            Reporter: Christoph Brücke
>            Priority: Major
>              Labels: pull-request-available
>
> h3. Problem
> {{SHOW TABLE EXTENDED IN <namespace> LIKE '*'}} lists the namespace first and 
> then loads every matching table, one by one. If any table is dropped between 
> the listing and its load, the whole command fails with 
> {{TABLE_OR_VIEW_NOT_FOUND}} for that table. The tables that are still there 
> are not returned either.
> The command should not fail because a table it was not asked about 
> disappeared: the dropped table can simply be left out, as if the listing had 
> happened a moment later.
> h3. Where
> v2 ({{ShowTablesExtendedExec}}, added by SPARK-33393 in 4.0.0), unchanged on 
> master:
> {code:scala}
> val tables = catalog.listTables(namespace.toArray)
> tables.map { tableIdent =>
>   if (StringUtils.filterPattern(Seq(tableIdent.name()), pattern).nonEmpty) {
>     val table = catalog.loadTable(tableIdent)   // throws 
> NoSuchTableException if dropped since listTables
>     ...
> {code}
> v1 ({{ShowTablesCommand}}, {{isExtended = true}}) has the same list-then-load 
> pattern:
> {code:scala}
> val tables =
>   tableIdentifierPattern.map(catalog.listTables(db, 
> _)).getOrElse(catalog.listTables(db))
> tables.map { tableIdent =>
>   ...
>   if (isExtended) {
>     val information = 
> catalog.getTempViewOrPermanentTableMetadata(tableIdent).simpleString
>     ...
> {code}
> The window covers the whole loop, so it grows with the number of tables in 
> the namespace and with the latency of each load (e.g. a remote catalog such 
> as AWS Glue plus reading each Iceberg table's metadata file).
> h3. Steps to reproduce
> Session 1, in a loop:
> {code:sql}
> CREATE TABLE ns.t_drop (id INT) USING iceberg;  -- any v2 catalog; also 
> reproducible with v1 tables
> DROP TABLE ns.t_drop;
> {code}
> Session 2, in a loop, against the same namespace with a few dozen other 
> tables:
> {code:sql}
> SHOW TABLE EXTENDED IN ns LIKE '*';
> {code}
> Session 2 intermittently fails with:
> {noformat}
> [TABLE_OR_VIEW_NOT_FOUND] The table or view `ns`.`t_drop` cannot be found. ...
> {noformat}
> A deterministic test can use a catalog whose {{listTables}} returns an 
> identifier that {{loadTable}} no longer finds.
> h3. Impact
> {{SHOW TABLE EXTENDED IN <namespace> LIKE '*'}} is a common way for tools to 
> discover a namespace's tables together with their metadata (provider, type, 
> location) in one statement. In a namespace where other jobs drop or replace 
> tables, this makes schema discovery fail intermittently, and the error is 
> misleading: it names a table the caller never asked for, and gives no hint 
> that a retry would succeed. Clients either fail, retry blindly, or misread 
> the error, e.g. as "the namespace is empty" [1].
> Since 4.0 this affects v2 catalogs such as Iceberg as well. Before 
> SPARK-33393 the statement was rejected for v2 tables, so clients fell back to 
> {{SHOW TABLES}} plus one {{DESCRIBE}} per table, which could skip a table 
> that had gone.
> [1] [https://github.com/dbt-labs/dbt-adapters/issues/2346]
> h3. Precedent
> {{spark.catalog.listTables}} already skips tables that disappear after 
> listing: {{resolveTable}} catches {{TABLE_OR_VIEW_NOT_FOUND}} and returns 
> {{None}} (SPARK-46145; SPARK-20439 for failures to load table metadata).
> h3. Proposed fix
> Skip a table that is not found when it is loaded, in both execs:
> * {{ShowTablesExtendedExec}}: wrap {{catalog.loadTable(tableIdent)}} and skip 
> the identifier on {{NoSuchTableException}}.
> * {{ShowTablesCommand}} ({{isExtended}}): same for 
> {{getTempViewOrPermanentTableMetadata(tableIdent)}}.
> Other errors still propagate, and a missing namespace still fails as today. 
> Plain {{SHOW TABLES}} is unaffected (it does not load tables). I'm happy to 
> open a PR with tests for both v1 and v2.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to