Skip to main content
PYSPARK • LESSON 134

Boolean Flags with BooleanType

How do we define schemas containing boolean feature flags, verification states, and opt-in preferences?

Advanced2 Minutes700 XP
🤔 THE QUESTION

How do we define schemas containing boolean feature flags, verification states, and opt-in preferences?

💡 WHAT IS IT?

BooleanType represents true/false boolean values stored compactly in memory and Parquet files.

🎯 WHAT IS IT USED FOR?

User consent flags, GDPR compliance preferences, and account verification indicators.

💻 EXAMPLE
from pyspark.sql.types import StructType, StructField, StringType, BooleanType

status_schema = StructType([
    StructField("account_id", StringType(), False),
    StructField("is_verified", BooleanType(), False),
    StructField("opt_in_marketing", BooleanType(), True)
])

🎯 Mission Objectives

Practice typing production-grade PySpark code for Boolean Flags with BooleanType.

  • Import BooleanType
  • Define boolean verification and opt-in flags
  • Enforce boolean types in schema