All Products
Search
Document Center

Realtime Compute for Apache Flink:UNION ALL

Last Updated:Mar 26, 2026

Modifying UNION ALL in a Flink SQL deployment can affect whether downstream stateful operators resume from existing state. The compatibility outcome depends on what you change.

ModificationCompatibilityEffect on downstream stateful operators
Reorder input queriesCompatibleNo impact — state is preserved
Add or remove an input queryIncompatibleState cannot be reused

Compatible modification: reordering input queries

Changing the order of input queries in UNION ALL does not break state compatibility for downstream stateful operators. The deployment resumes from existing state after the change.

Example: The two queries below are compatible. Switching from the original to the modified query does not require a state reset.

-- Original
SELECT a, sum(b), max(c) FROM (
  SELECT a, b, c FROM MyTable UNION ALL SELECT a, b, c FROM MyTable2
) GROUP BY a;

-- Modified: input query order changed — state is preserved
SELECT a, sum(b), max(c) FROM (
  SELECT a, b, c FROM MyTable2 UNION ALL SELECT a, b, c FROM MyTable
) GROUP BY a;

Incompatible modification: adding or removing an input query

Adding or removing an input query in UNION ALL breaks state compatibility for downstream stateful operators. The deployment cannot resume from existing state after this change.

Example: Adding MyTable3 as a third input makes the deployment incompatible with state produced by the original two-input query.

-- Original
SELECT a, sum(b), max(c) FROM (
  SELECT a, b, c FROM MyTable UNION ALL SELECT a, b, c FROM MyTable2
) GROUP BY a;

-- Modified: third input query added — state is incompatible
SELECT a, sum(b), max(c) FROM (
  SELECT a, b, c FROM MyTable
  UNION ALL
  SELECT a, b, c FROM MyTable2
  UNION ALL
  SELECT a, b, c FROM MyTable3
) GROUP BY a;