{"record":{"id":"24f3593e1e2a6bdb","repo":"apache/beam","slug":"encountered-an-unexpected-node-kind-node-getkind","errorCode":null,"errorMessage":"Encountered an unexpected node kind: ${node.getKind()}","messagePattern":"Encountered an unexpected node kind: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbTable.java","lineNumber":279,"sourceCode":"        switch (node.getKind()) {\n          case AND:\n            // Recursively construct filter for each operand of conjunction.\n            return Filters.and(\n                compositeNode.getOperands().stream()\n                    .map(this::translateRexNodeToBson)\n                    .collect(Collectors.toList()));\n          case OR:\n            // Recursively construct filter for each operand of disjunction.\n            return Filters.or(\n                compositeNode.getOperands().stream()\n                    .map(this::translateRexNodeToBson)\n                    .collect(Collectors.toList()));\n          default:\n            // Encountered an unexpected node kind, RuntimeException below.\n            break;\n        }\n      }\n      throw new RuntimeException(\n          \"Encountered an unexpected node kind: \" + node.getKind().toString());\n    } else if (node instanceof RexInputRef\n        && node.getType().getSqlTypeName().equals(SqlTypeName.BOOLEAN)) {\n      // Boolean field, must be true. Ex: `select * from table where bool_field`\n      return Filters.eq(fieldIdToName.apply(((RexInputRef) node).getIndex()), true);\n    }\n\n    throw new RuntimeException(\n        \"Was expecting a RexCall or a boolean RexInputRef, but received: \"\n            + node.getClass().getSimpleName());\n  }\n\n  private Object convertToExpectedType(RexInputRef inputRef, RexLiteral literal) {\n    FieldType beamFieldType = getSchema().getField(inputRef.getIndex()).getType();\n\n    return literal.getValueAs(\n        FieldTypeDescriptors.javaTypeForFieldType(beamFieldType).getRawType());\n  }","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbTable.java#L261-L297","documentation":"After the operand and AND/OR handling in MongoDbTable.translateRexNodeToBson, any remaining RexNode kind falls through the switch and reaches the terminal throw reporting the unhandled SqlKind. It is a catch-all for predicate shapes the BSON filter builder never learned to translate.","triggerScenarios":"A WHERE clause predicate whose RexNode kind is outside the implemented set (e.g. CASE, IS NULL/IS NOT NULL, IN with unusual shapes) reaches the fall-through 'throw new RuntimeException(\"Encountered an unexpected node kind: ...\")'.","commonSituations":"Using IS NULL / IS NOT NULL checks or IN lists against MongoDb external tables; complex boolean expressions produced by the Calcite optimizer's rewrites.","solutions":["Replace IS NULL/IS NOT NULL predicates with equivalent comparisons (e.g. field IS NOT NULL with a range check or handle client-side).","Restructure the query so unsupported predicates are evaluated post-scan by Beam rather than pushed down.","Extend the switch in translateRexNodeToBson to translate the missing SqlKind (e.g. Filters.exists for IS NOT NULL)."],"exampleFix":"// before\nSELECT * FROM t WHERE field IS NOT NULL\n// after\nSELECT * FROM t WHERE field >= 0 OR field < 0  -- or evaluate client-side","handlingStrategy":"validation","validationCode":"Set<SqlKind> known = EnumSet.of(SqlKind.EQUALS, SqlKind.NOT_EQUALS, SqlKind.LESS_THAN, SqlKind.GREATER_THAN, SqlKind.LESS_THAN_OR_EQUAL, SqlKind.GREATER_THAN_OR_EQUAL, SqlKind.AND, SqlKind.OR);\nif (!known.contains(node.getKind())) throw new IllegalArgumentException(\"Not pushable: \" + node.getKind());","typeGuard":null,"tryCatchPattern":"try { return MongoDbFilter.create(cnf); } catch (RuntimeException e) { return null; /* full scan */ }","preventionTips":["Avoid IS NULL/IS NOT NULL and IN in pushed predicates","Review optimized plans for unexpected rewrites","Keep predicates literal-column-simple"],"tags":["java","apache-beam","mongodb","sql","predicate-pushdown"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}