apache/beam · error · java.lang.IllegalArgumentException

inputs of ${opType} have different window strategy: ${leftWi

Error message

inputs of ${opType} have different window strategy: ${leftWindow} VS ${rightWindow}

What it means

BeamSetOperatorRelBase (UNION/INTERSECT/EXCEPT) requires both input PCollections to use compatible window functions so rows can be aligned element-wise. If left and right WindowFn are not compatible (WindowFn.isCompatible returns false), expand throws IllegalArgumentException describing both strategies.

Source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSetOperatorRelBase.java:73

    this.beamRelNode = beamRelNode;
    this.opType = opType;
    this.all = all;
  }

  @Override
  public PCollection<Row> expand(PCollectionList<Row> inputs) {
    checkArgument(
        inputs.size() == 2,
        "Wrong number of arguments to %s: %s",
        beamRelNode.getClass().getSimpleName(),
        inputs);
    PCollection<Row> leftRows = inputs.get(0);
    PCollection<Row> rightRows = inputs.get(1);

    WindowFn leftWindow = leftRows.getWindowingStrategy().getWindowFn();
    WindowFn rightWindow = rightRows.getWindowingStrategy().getWindowFn();
    if (!leftWindow.isCompatible(rightWindow)) {
      throw new IllegalArgumentException(
          "inputs of "
              + opType
              + " have different window strategy: "
              + leftWindow
              + " VS "
              + rightWindow);
    }

    // TODO: We may want to preaggregate the counts first using Group instead of calling CoGroup and
    // measuring the
    // iterable size. If on average there are duplicates in the input, this will be faster.
    final String lhsTag = "lhs";
    final String rhsTag = "rhs";
    PCollection<Row> joined =
        PCollectionTuple.of(lhsTag, leftRows, rhsTag, rightRows)
            .apply("CoGroup", CoGroup.join(By.fieldNames("*")));
    return joined
        .apply(

View on GitHub (pinned to 12126d8942)

Solutions

  1. Apply the same WindowFn (and trigger) to both inputs before the set operation, e.g. via Window.into(...) on one or both sides
  2. Re-window one input into the other's windowing using Window.configure() / re-windowing transforms
  3. Ensure neither side accidentally uses the default GlobalWindows when the other is windowed

Example fix

// before
PCollection<Row> right = rows.apply(Window.into(FixedWindows.of(Duration.standardMinutes(5))));
union = left.apply(SqlTransform...); // left in GlobalWindows
// after
left = left.apply(Window.into(FixedWindows.of(Duration.standardMinutes(5))));
right = right.apply(Window.into(FixedWindows.of(Duration.standardMinutes(5))));
Defensive patterns

Strategy: validation

Validate before calling

// Validate window compatibility before the set operation
WindowFn l = left.getWindowingStrategy().getWindowFn();
WindowFn r = right.getWindowingStrategy().getWindowFn();
if (!l.isCompatible(r)) {
  throw new IllegalArgumentException("Re-window both inputs identically before UNION/INTERSECT/EXCEPT");
}

Try / catch

try {
  result = sqlEnv.sqlQuery(unionQuery).evaluate();
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("have different window strategy")) {
    inputs = reWindowBothSides(inputs, commonWindowFn);
    // retry
  } else throw e;
}

Prevention

When it happens

Trigger: A UNION (ALL)/INTERSECT/EXCEPT query where one input is windowed differently from the other, e.g. fixed windows on one side and sliding/global windows on the other, or one side unwindowed (global) while the other is windowed.

Common situations: Joining a batch PCollection (global window) with a streaming windowed PCollection; mixing window assignments from different sources before a set operation; PCollections built programmatically with mismatched WindowFns.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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