Skip to main content
PYSPARK • LESSON 124

Creating Temporary Views via SQL DDL

How do we create a temporary view using SQL CREATE OR REPLACE TEMP VIEW statements?

Advanced2 Minutes660 XP
🤔 THE QUESTION

How do we create a temporary view using SQL CREATE OR REPLACE TEMP VIEW statements?

💡 WHAT IS IT?

Executing standard SQL DDL syntax to define filtered or transformed views directly in the session catalog.

🎯 WHAT IS IT USED FOR?

Porting enterprise SQL stored procedures and multi-view ETL workflows into Apache Spark.

💻 EXAMPLE
spark.sql("""
    CREATE OR REPLACE TEMP VIEW v_high_salary AS
    SELECT name, department, salary
    FROM employees
    WHERE salary > 100000
""")

🎯 Mission Objectives

Practice typing production-grade PySpark code for Creating Temporary Views via SQL DDL.

  • Execute SQL DDL statement
  • Create filtered temporary view in catalog
  • Encapsulate business logic in SQL view