There's more...

Once you have created a temporary view, you cannot create another view with the same name. However, Spark provides another method that allows us to either create or update a view: .createOrReplaceTempView(...). As the name suggests, by calling this method, we either create a new view if one does not exist, or we replace an already existing one with the new one:

sample_data_schema.createOrReplaceTempView('sample_data_view')

As before, we can now use it to interact with the data using SQL queries:

spark.sql('''
SELECT Model
, Year
, RAM
, HDD
, ScreenSize
FROM sample_data_view
''').show()

Here's what we get back:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset