SQL 语句出错:AnalysisException: Table or view not foundError in SQL statement: AnalysisException: Table or view not found


当您尝试查询表或视图时,会收到以下错误:When you try to query a table or view, you get this error:

AnalysisException:Table or view not found when trying to query a global temp view


通常会创建全局 temp 视图,以便可以从不同的会话中访问它们,并保持活动状态,直到应用程序结束。You typically create global temp views so they can be accessed from different sessions and kept alive until the application ends. 您可以 temp 使用以下语句创建全局视图:You can create a global temp view with the following statement:


此处 dfDataFrameHere, df is the DataFrame. 创建视图的另一种方法是:Another way to create the view is with:

CREATE GLOBAL TEMP VIEW <global-view-name>

所有全局临时视图都与名为的系统临时数据库相关联 global_tempAll global temporary views are tied to a system temporary database named global_temp. 如果在未显式提到数据库的情况下查询全局表或视图 global_temp ,则会发生错误。If you query the global table or view without explicitly mentioning the global_temp database, then the error occurs.


请始终在数据库中使用限定的表名 global_temp ,以便可以成功查询全局视图数据。Always use the qualified table name with the global_temp database, so that you can query the global view data successfully.

例如:For example:

select * from global_temp.<global-view-name>;