apache/beam · error · UnsupportedOperationException

Sessions is not allowed in side inputs

Error message

Sessions is not allowed in side inputs

What it means

Sessions windows are data-driven (gap duration extends on each element), so there is no static function mapping an arbitrary main window to a Sessions side-input window. Beam therefore refuses to use Sessions as a side input by throwing UnsupportedOperationException in getDefaultWindowMappingFn.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/Sessions.java:97

  @Override
  public void verifyCompatibility(WindowFn<?, ?> other) throws IncompatibleWindowException {
    if (!this.isCompatible(other)) {
      throw new IncompatibleWindowException(
          other,
          String.format(
              "%s is only compatible with %s.",
              Sessions.class.getSimpleName(), Sessions.class.getSimpleName()));
    }
  }

  @Override
  public TypeDescriptor<IntervalWindow> getWindowTypeDescriptor() {
    return TypeDescriptor.of(IntervalWindow.class);
  }

  @Override
  public WindowMappingFn<IntervalWindow> getDefaultWindowMappingFn() {
    throw new UnsupportedOperationException("Sessions is not allowed in side inputs");
  }

  public Duration getGapDuration() {
    return gapDuration;
  }

  @Override
  public void populateDisplayData(DisplayData.Builder builder) {
    super.populateDisplayData(builder);
    builder.add(DisplayData.item("gapDuration", gapDuration).withLabel("Session Gap Duration"));
  }

  @Override
  public boolean equals(@Nullable Object object) {
    if (!(object instanceof Sessions)) {
      return false;
    }
    Sessions other = (Sessions) object;

View on GitHub (pinned to 12126d8942)

Solutions

  1. Re-window the side input to FixedWindows or GlobalWindows before creating the view
  2. If a global snapshot is acceptable, apply Window.into(new GlobalWindows()) then View.asList()
  3. Restructure the pipeline to join within Sessions windows instead of using side inputs

Example fix

// before
PCollectionView<List<T>> view = sessionsPco.apply(Window.into(Sessions.withGapDuration(g))).apply(View.asList());
// after
PCollectionView<List<T>> view = sessionsPco.apply(Window.into(new GlobalWindows())).apply(View.asList());
Defensive patterns

Strategy: validation

Validate before calling

if (sideWindowFn instanceof Sessions) throw new IllegalArgumentException("Sessions cannot back a side input; re-window first");

Type guard

boolean usableAsSideInput(WindowFn<?,?> fn) { try { fn.getDefaultWindowMappingFn(); return true; } catch (UnsupportedOperationException e) { return false; } }

Prevention

When it happens

Trigger: Calling Sessions.getDefaultWindowMappingFn() directly, or using a Sessions-windowed PCollection as a side input (View.asList/asMap) while the main input is in a different window.

Common situations: Trying sideInput(view) where the view was built from a Sessions-windowed collection; pipeline validation failures during PTransform expansion when window mapping is needed.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/495f037da0c8cfc6. Report an issue: GitHub.