{"record":{"id":"4b5b19f19e887e32","repo":"apache/beam","slug":"s-is-not-valid-beamaggregationrule","errorCode":null,"errorMessage":"[%s] is not valid.","messagePattern":"\\[(.+?)\\] is not valid\\.","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rule/BeamAggregationRule.java","lineNumber":208,"sourceCode":"              \"Specifying alignment (offset) is not supported for session windows\");\n        }\n\n        return sessions;\n      default:\n        return null;\n    }\n  }\n\n  private static Duration durationParameter(List<RexNode> parameters, int parameterIndex) {\n    return Duration.millis(longValue(parameters.get(parameterIndex)));\n  }\n\n  private static long longValue(RexNode operand) {\n    if (operand instanceof RexLiteral) {\n      // @TODO: this can be simplified after CALCITE-2837\n      return ((Number) RexLiteral.value(operand)).longValue();\n    } else {\n      throw new IllegalArgumentException(String.format(\"[%s] is not valid.\", operand));\n    }\n  }\n}\n","sourceCodeStart":190,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rule/BeamAggregationRule.java#L190-L212","documentation":"Beam SQL's aggregation rule converter only accepts Calcite RexLiteral operands when extracting a long value (e.g. for window duration parameters). If the operand is any other RexNode type (e.g. a RexCall or RexInputRef), it throws IllegalArgumentException because it cannot statically evaluate it to a number.","triggerScenarios":"Passing a non-literal expression where a numeric literal is required, e.g. TUMBLE(interval_column, duration_expression) where the duration is a column reference or computed expression instead of a constant literal.","commonSituations":"Windowing SQL queries where the user writes an interval as a computed expression or a referenced field rather than an inline literal like INTERVAL '60' SECOND; also seen after Calcite version changes alter how literals are represented.","solutions":["Replace the duration/offset operand with a constant SQL literal, e.g. INTERVAL '1' MINUTE","Precompute the value in application code and inline it into the query","Check the Calcite version; CALCITE-2837 tracks simplifying this literal handling"],"exampleFix":"// before\nSELECT COUNT(*) FROMPCOLLECTION GROUP BY TUMBLE(ts, my_duration_column)\n// after\nSELECT COUNT(*) FROM PCOLLECTION GROUP BY TUMBLE(ts, INTERVAL '1' MINUTE)","handlingStrategy":"validation","validationCode":"if (!(operand instanceof RexLiteral)) { throw new IllegalArgumentException(\"Duration must be a SQL interval literal\"); }","typeGuard":"boolean isLiteral(RexNode n) { return n instanceof RexLiteral; }","tryCatchPattern":"try { ... } catch (IllegalArgumentException e) { /* fall back to literal-only windowing */ }","preventionTips":["Always pass constant interval literals for window parameters","Avoid computed expressions in GROUP BY window functions","Pin Calcite/Beam versions together"],"tags":["sql","calcite","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}