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?

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