Skip to main content
PCollection
Revision GuideActive Topic

Cheatsheet: PCollection

Recommended reading: 3 mins

Core Description

Understand the core data container, its properties, and state representations.

beam.Create()
returns: PCollection
Purpose

Generates a PCollection from an in-memory iterable (lists, sets, dictionary lists).

Syntax Signaturebeam.Create(iterable)
Usage Example
import apache_beam as beam

with beam.Pipeline() as p:
    elements = p | "Create Elements" >> beam.Create([10, 20, 30])
    elements | beam.Map(print)
Expected Stdout / Output
10
20
30
Time Complexity

O(N) where N is the number of elements in the iterable

Used In

Testing, loading configurations, and quick sandbox runs.

Related Methods

ReadFromText(), ReadFromPubSub()

Remember:

Avoid creating very large PCollections using beam.Create since the entire list is held in driver memory.

PCollection Attributes
returns: Data Representation
Purpose

Understanding core immutability, distributed elements, and schemas.

Syntax SignaturePCollection Characteristics (Immutable, Distributed, Bounded/Unbounded)
Usage Example
import apache_beam as beam

# PCollections are immutable; transforms return new collections
inputs = p | beam.Create([1, 2, 3, 4])
evens = inputs | "FilterEvens" >> beam.Filter(lambda x: x % 2 == 0)
Used In

Architecting streaming or batch pipelines.

Common Pitfall

Attempting to modify elements in-place inside user code processes.

Remember:

PCollections do not support index lookups or random access. All access must flow through transforms.

Support