{"record":{"id":"fe9286679af9a19f","repo":"apache/beam","slug":"only-s-objects-with-the-same-number-of-years-month-of-year","errorCode":null,"errorMessage":"Only %s objects with the same number of years, month of year, day of month, start date and time zone are compatible.","messagePattern":"Only (.+?) objects with the same number of years, month of year, day of month, start date and time zone are compatible\\.","errorType":"exception","errorClass":"IncompatibleWindowException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/CalendarWindows.java","lineNumber":373,"sourceCode":"    }\n\n    @Override\n    public boolean isCompatible(WindowFn<?, ?> other) {\n      if (!(other instanceof YearsWindows)) {\n        return false;\n      }\n      YearsWindows that = (YearsWindows) other;\n      return number == that.number\n          && monthOfYear == that.monthOfYear\n          && dayOfMonth == that.dayOfMonth\n          && Objects.equals(startDate, that.startDate)\n          && Objects.equals(timeZone, that.timeZone);\n    }\n\n    @Override\n    public void verifyCompatibility(WindowFn<?, ?> other) throws IncompatibleWindowException {\n      if (!this.isCompatible(other)) {\n        throw new IncompatibleWindowException(\n            other,\n            String.format(\n                \"Only %s objects with the same number of years, month of year, \"\n                    + \"day of month, start date and time zone are compatible.\",\n                YearsWindows.class.getSimpleName()));\n      }\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);\n\n      builder\n          .add(DisplayData.item(\"numYears\", number).withLabel(\"Window Years\"))\n          .addIfNotDefault(\n              DisplayData.item(\"startDate\", new DateTime(startDate, timeZone).toInstant())\n                  .withLabel(\"Window Start Date\"),\n              new DateTime(DEFAULT_START_DATE, DateTimeZone.UTC).toInstant());","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/CalendarWindows.java#L355-L391","documentation":"CalendarWindows.YearsWindows.verifyCompatibility throws IncompatibleWindowException when grouping streams whose YearsWindows differ in number of years, month of year, day of month, startDate, or time zone. Identical window functions are required for element-wise window alignment in joins and merges.","triggerScenarios":"Merging/CoGroupByKey of PCollections windowed with CalendarWindows.years(n, ...) having different years(), months, days, startDate, or timeZone values.","commonSituations":"Yearly batch streams configured with different anchors (e.g. starting Jan 1 vs fiscal-year July 1) combined in a single pipeline.","solutions":["Use the exact same YearsWindows instance/values on both sides of the merge.","Define the yearly window once in shared configuration.","Re-window one input into the other's windows before joining.","Drop to GlobalWindows when calendar alignment is not needed for the merge."],"exampleFix":"// before\nPCollection<A> a = inA.apply(Window.into(CalendarWindows.years(1, Month.JANUARY, 1, START, ZONE)));\nPCollection<B> b = inB.apply(Window.into(CalendarWindows.years(1, Month.JULY, 1, START, ZONE)));\n// after\nCalendarWindows.YearsWindows win = CalendarWindows.years(1, Month.JANUARY, 1, START, ZONE);\nPCollection<A> a = inA.apply(Window.into(win));\nPCollection<B> b = inB.apply(Window.into(win));","handlingStrategy":"validation","validationCode":"YearsWindows a = CalendarWindows.years(n, month, day, START, ZONE);\nYearsWindows b = (YearsWindows) other;\nboolean compatible = a.getYears() == b.getYears()\n    && a.getMonth() == b.getMonth()\n    && a.getDayOfMonth() == b.getDayOfMonth()\n    && a.getStartDate().equals(b.getStartDate())\n    && a.getTimeZone().equals(b.getTimeZone());","typeGuard":null,"tryCatchPattern":"try {\n  windowFn1.verifyCompatibility(windowFn2);\n} catch (IncompatibleWindowException e) {\n  throw new IllegalStateException(\"YearsWindows differ (years/month/day/startDate/zone)\", e);\n}","preventionTips":["Use one shared YearsWindows instance for all yearly streams.","Document fiscal-year anchors (month/day) in shared config.","Fail fast in setup by calling verifyCompatibility across inputs.","Convert to GlobalWindows before merging when calendar alignment is not required."],"tags":["java","apache-beam","windowing","incompatibility"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}