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?

Advancedโฑ 2 Minutesโญ 620 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