Monday 29 July 2019

Create a temporary view from Spark DataFrame

Once a temporary view has been created, it can be queried as if it were a table.


peopleDF.createOrReplaceTempView("People10M")

To view the contents of temporary view, use select notation.

display(spark.sql("SELECT * FROM  People10M where firstName = 'Donna' "))



Temporary Views

In DataFrames, temporary views are used to make the DataFrame available to SQL, and work with SQL syntax seamlessly.
A temporary view gives you a name to query from SQL, but unlike a table it exists only for the duration of your Spark Session. As a result, the temporary view will not carry over when you restart the cluster or switch to a new notebook. It also won't show up in the Data button on the menu on the left side of a Databricks notebook which provides easy access to databases and tables.
The statement in the following cells create a temporary view containing the same data.

No comments:

Post a Comment