{"record":{"id":"acfc7516c89f6547","repo":"apache/beam","slug":"unexpected-join-type-realjointype","errorCode":null,"errorMessage":"Unexpected join type ${realJoinType}","messagePattern":"Unexpected join type (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSideInputJoinRel.java","lineNumber":191,"sourceCode":"\n    PCollection<Row> joined;\n    switch (realJoinType) {\n      case INNER:\n        joined =\n            realLeftRows.apply(\n                org.apache.beam.sdk.schemas.transforms.Join.<Row, Row>innerBroadcastJoin(\n                        realRightRows)\n                    .on(FieldsEqual.left(realLeftKeyFields).right(realRightKeyFields)));\n        break;\n      case LEFT:\n        joined =\n            realLeftRows.apply(\n                org.apache.beam.sdk.schemas.transforms.Join.<Row, Row>leftOuterBroadcastJoin(\n                        realRightRows)\n                    .on(FieldsEqual.left(realLeftKeyFields).right(realRightKeyFields)));\n        break;\n      default:\n        throw new RuntimeException(\"Unexpected join type \" + realJoinType);\n    }\n    Schema schema = CalciteUtils.toSchema(getRowType());\n\n    String lhsSelect = org.apache.beam.sdk.schemas.transforms.Join.LHS_TAG + \".*\";\n    String rhsSelect = org.apache.beam.sdk.schemas.transforms.Join.RHS_TAG + \".*\";\n    PCollection<Row> selected =\n        !swapped\n            ? joined.apply(Select.<Row>fieldNames(lhsSelect, rhsSelect).withOutputSchema(schema))\n            : joined.apply(Select.<Row>fieldNames(rhsSelect, lhsSelect).withOutputSchema(schema));\n    return selected;\n  }\n}\n","sourceCodeStart":173,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSideInputJoinRel.java#L173-L204","documentation":"Inside BeamSideInputJoinRel's sideInputJoin transform, after handling INNER, LEFT OUTER and RIGHT OUTER joins, a default branch throws this RuntimeException for any other join type. It is an internal invariant check: the planner should never route a join of this type to the side-input join implementation.","triggerScenarios":"The switch over realJoinType in BeamSideInputJoinRel.sideInputJoin reaches default — i.e. a join type other than INNER/LEFT/RIGHT OUTER reaches the side-input join path (e.g. FULL OUTER due to a planning bug or unsafe rewrite).","commonSituations":"Hitting it is usually a sign of a Calcite rule mismatch or a custom/vendored Beam version where a new join type got planned to BeamSideInputJoinRel; rarely user-triggered directly.","solutions":["Rewrite the query to use INNER or LEFT/RIGHT OUTER JOIN (with the unbounded side on the outer side) instead of the unsupported join type.","Check the Beam version and upgrade — if FULL OUTER reaches this path it is likely a planner bug; verify against the latest release.","Inspect the plan (explain) to see why BeamSideInputJoinRel was chosen and adjust predicates/queries.","If using custom join rules, fix them to exclude join types the side-input implementation cannot handle."],"exampleFix":"-- before\nSELECT * FROM a FULL OUTER JOIN b ON a.k = b.k\n-- after\nSELECT * FROM a LEFT OUTER JOIN b ON a.k = b.k\nUNION ALL\nSELECT * FROM a RIGHT OUTER JOIN b ON a.k = b.k WHERE a.k IS NULL","handlingStrategy":"try-catch","validationCode":"Set<JoinRelType> supported = EnumSet.of(JoinRelType.INNER, JoinRelType.LEFT, JoinRelType.RIGHT); if (!supported.contains(joinType)) { throw new IllegalArgumentException(\"Side-input join supports only INNER/LEFT/RIGHT\"); }","typeGuard":"boolean supportedJoinType = joinType == JoinRelType.INNER || joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT;","tryCatchPattern":"try { result = pipeline.apply(SqlTransform.query(sql)); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unexpected join type\")) { /* rewrite query to supported join types */ } else { throw e; } }","preventionTips":["Restrict queries to INNER/LEFT/RIGHT OUTER joins for side-input paths","Treat this as a planner bug signal — capture the query and file/inspect a Beam issue","Run explain() on the query to confirm which join strategy is selected","Pin and test a Beam version where planner behavior is known"],"tags":["sql","join","internal-error","invariant"],"backgroundTag":"internal-invariant-violation","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"}