{"record":{"id":"3adf9cc048775d35","repo":"apache/beam","slug":"error-mapping-neo4j-result","errorCode":null,"errorMessage":"Error mapping Neo4J result","messagePattern":"Error mapping Neo4J result","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java","lineNumber":825,"sourceCode":"      }\n      executeReadCypherStatement(context, parametersMap);\n    }\n\n    private void executeReadCypherStatement(\n        final ProcessContext processContext, Map<String, Object> parametersMap) {\n      // The actual \"reading\" work needs to happen in a transaction.\n      // We could actually read and write here depending on the type of transaction\n      // we picked.  As long as the Cypher statement returns values it's fine.\n      //\n      TransactionWork<Long> transactionWork =\n          transaction -> {\n            long count = 0L;\n            Result result = transaction.run(cypher, parametersMap);\n            while (result.hasNext()) {\n              try {\n                processContext.output(rowMapper.mapRow(result.next()));\n              } catch (Exception e) {\n                throw new RuntimeException(\"Error mapping Neo4J result\", e);\n              }\n              count++;\n            }\n            return count;\n          };\n\n      if (logCypher) {\n        String parametersString = getParametersString(parametersMap);\n\n        String readWrite = writeTransaction ? \"write\" : \"read\";\n        LOG.info(\n            \"Starting a {} transaction for cypher: {}, parameters: {}\",\n            readWrite,\n            cypher,\n            parametersString);\n      }\n\n      // There are 2 ways to do a transaction on Neo4j: read or write","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/neo4j/src/main/java/org/apache/beam/sdk/io/neo4j/Neo4jIO.java#L807-L843","documentation":"Inside ReadFn's transaction work, each Result record is converted via the user-supplied rowMapper. If mapRow throws for any record (bad field access, wrong type, ClassCastException in extraction), the DoFn wraps it in a RuntimeException to add context and abort the transaction, causing the whole read to retry/fail.","triggerScenarios":"rowMapper accesses a column not present in the Cypher result (typo or changed RETURN clause), or calls typed getters (asInt/asString) on values of a different or NULL type.","commonSituations":"Cypher query edited to rename/alias a returned column while the mapper still uses the old name; nodes with missing properties returning NullValue; type changes after schema/DB migration.","solutions":["Align the rowMapper with the exact RETURN clause: use record.get(\"alias\") with aliases matching the Cypher.","Defensively check record.get(\"field\").isNull() / containsKey before typed extraction.","Catch and log per-record mapping issues inside the mapper if partial results are acceptable; otherwise fix the query/mismatch and rerun."],"exampleFix":"// before\nrecord -> record.get(\"person_name\").asString()\n// cypher returns: RETURN n.name AS name\n// after\nrecord -> {\n  Value v = record.get(\"name\");\n  return v.isNull() ? null : v.asString();\n}","handlingStrategy":"try-catch","validationCode":"// Validate the mapper against the query result in a test: try (Result r = session.run(cypher)) { rowMapper.mapRow(r.next()); }","typeGuard":null,"tryCatchPattern":"try { output(rowMapper.mapRow(record)); } catch (Exception e) { LOG.error(\"mapRow failed for record %s\", record); throw new RuntimeException(\"Error mapping Neo4J result\", e); }","preventionTips":["Keep Cypher RETURN aliases in sync with mapper field names via a shared constant or test.","Null-check Value extraction with isNull() before typed getters.","Add a unit test running the actual Cypher against an embedded/test instance."],"tags":["java","neo4j","apache-beam","row-mapping"],"backgroundTag":"unexpected-response-shape","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"}