Skip to main content
PYSPARK • LESSON 121

Registering Views with createOrReplaceTempView()

How do we register a DataFrame as a temporary SQL view so it can be queried using standard ANSI SQL?

Advanced2 Minutes620 XP
🤔 THE QUESTION

How do we register a DataFrame as a temporary SQL view so it can be queried using standard ANSI SQL?

💡 WHAT IS IT?

createOrReplaceTempView(name) registers a DataFrame as a session-scoped temporary table in the Spark catalog.

🎯 WHAT IS IT USED FOR?

Enabling SQL queries on in-memory DataFrames without persisting tables to external storage.

💻 EXAMPLE
df.createOrReplaceTempView("v_customers")

🎯 Mission Objectives

Practice typing production-grade PySpark code for Registering Views with createOrReplaceTempView().

  • Register temporary SQL view
  • Name view in Spark catalog
  • Enable SQL querying on DataFrame