'How to read a table which is saved by saveAsTable in Apache Spark?

I am trying to save a dataframe by using df.write.saveAsTable("table_name")

but i am unable to retrieve this table again (not in the same run).

I tried

spark.read.table("table_name")

and

spark.sql("select * from table_name")

but both didn't worked give error

 Table or view not found: table_name


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source