Problem: Error in SQL statement: AnalysisException: Table or view not found

Problem

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

Cause

You typically create global temp views so they can be accessed from different sessions and kept alive until the application ends. You can create a global temp view with the following statement:

df.createOrReplaceGlobalTempView("<global-view-name>")

Here, df is the DataFrame. Another way to create the view is with:

CREATE GLOBAL TEMP VIEW <global-view-name>

All global temporary views are tied to a system temporary database named global_temp. If you query the global table or view without explicitly mentioning the global_temp database, then the error occurs.

Solution

Always use the qualified table name with the global_temp database, so that you can query the global view data successfully.

For example:

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