LuciferYang opened a new pull request, #14297: URL: https://github.com/apache/gravitino/pull/14297
### What changes were proposed in this pull request? - `SparkHiveView` parses the view SQL and qualifies its table names before running it, with the new `ViewRelationQualifier`. As in Spark's own view resolution, a one-part name gets the catalog and namespace, and a name whose first part is not a registered catalog gets the catalog. CTE names are substituted first, and names inside subqueries and time travel clauses (`VERSION AS OF`, `TIMESTAMP AS OF (subquery)`) are qualified too. - The namespace is the one Spark recorded in `view.catalogAndNamespace.*` when it created the view, with `spark_catalog` mapped to the Gravitino catalog the view was loaded from. Without a recorded namespace, it is the view's own database. - When the view has no Spark SQL, the Hive fallback uses the view's expanded text, in which Hive qualifies the table names. - The session's current catalog and database are not changed. ### Why are the changes needed? The view SQL ran in the session's current catalog and database, so a view read the wrong table, or failed with `TABLE_OR_VIEW_NOT_FOUND`, whenever the session was not in the view's database. Fix: #14293 ### Does this PR introduce _any_ user-facing change? Views return the rows of the tables they were defined on, regardless of the session's current database. Function names, names written with `IDENTIFIER(...)` and the SQL configs Spark records with a view are still taken from the session, as before. ### How was this patch tested? - New `TestViewRelationQualifier` covers one- and two-part names, names that start with a catalog, subqueries, CTE names, `VERSION AS OF` and a `TIMESTAMP AS OF` subquery, and nested `WITH` under the legacy CTE precedence policy. - `SparkHiveCatalogIT.testSelectViewWithUnqualifiedSqlResolvesInViewNamespace` switches the session to `spark_catalog.default` and reads three views whose SQL has no database name, with a same-named table in another database: one without a recorded namespace (its SQL has a CTE and a subquery), one with a recorded Spark namespace, and one created by `hive -e`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
