Skip to content

fix(mybatis): XML mapper READS/WRITES edges not matching Function nodes (2793 parsed → 68 written) #890

Closed

Description

@k282

Problem

When indexing a large Java codebase with 475 MyBatis XML mapper files, the pipeline parsed 2,793 operation records but only wrote 68 READS/WRITES edges to the graph — a 97% drop.

Root cause (hypothesis)

write_mybatis_links() in writer.py matches by:

MATCH (fn:Function {name: q.method_name, path: q.method_path})

But MyBatis mapper XML <select id="findByUserId"> doesn't correspond to actual Java method declarations at a known path. The mapper interface methods are:

  • Defined on a Java interface (e.g. UserMapper.java), not a concrete class
  • The XML mapper path ≠ the Java interface path
  • method_path is set to the XML file path, not the Java interface path

So the MATCH finds no Function nodes and writes 0 edges.

Fix direction

  1. XML → interface resolution: mybatis.py should find the corresponding Java mapper interface (same base name, e.g. UserMapper.xml → look for UserMapper.java in the repo) and set method_path to the Java file path
  2. Fallback by class_name + method_name: write_mybatis_links() should try a looser match: MATCH (fn:Function {name: q.method_name}) WHERE fn.path CONTAINS q.mapper_class — using the mapper class name as a path hint
  3. Interface method nodes: Ensure interface_declaration method nodes are indexed as Function nodes (they currently may be skipped)

Validation data

Tested against Codebase B (285K functions):

  • 475 *Mapper.xml files found
  • 2,793 operation records parsed (<select>, <insert>, <update>, <delete>)
  • 68 READS/WRITES edges written (all from fallback class_context matching)
  • Expected: ~2,000+ edges if Java interface paths are resolved correctly

Related

Activity

  1. added
    bugSomething isn't working
    on May 7, 2026
  2. github-actions commented on May 7, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  3. bindhurapana-2828 commented on Jun 8, 2026

    @bindhurapana-2828

    Hi

    I'd like to work on this issue!

    My approach:

    1. XML → interface resolution in mybatis.py: When parsing *Mapper.xml, scan the repo for a matching *Mapper.java interface file (same base name) and set method_path to the Java file path instead of the XML path
    2. Fallback match in write_mybatis_links(): Add a secondary Cypher query using MATCH (fn:Function {name: q.method_name}) WHERE fn.path CONTAINS q.mapper_class so edges are written even when the exact path resolution misses
    3. Interface method indexing: Verify that methods declared on Java interface nodes are emitted as Function nodes during parsing — fixing the root cause of class_context=None on interface methods

    I'll validate against the numbers from the issue (2,793 parsed operations → target ~2,000+ READS/WRITES edges).

    Could you please assign this to me? I'm participating in GSSoC '26.

  4. Shashankss1205 commented on Oct 15, 2026

    @Shashankss1205
    Collaborator

    Maintenance review — 15 October 2026

    The key test is XML namespace/method resolution to the Java mapper interface, including overloaded or missing methods. Compare parsed operations with written READS/WRITES edges and expose unmatched counts.

  5. Shashankss1205 commented on Oct 15, 2026

    @Shashankss1205
    Collaborator

    Continuing the fix with native regressions. Current code matches only class_context, which SCIP functions can lack. Resolution now uses each XML namespace against unique Java declarations already parsed for this repository, then writes by exact source path + method name; duplicate FQNs and unknown sources stay unresolved rather than guessing by basename or leaking into another repository. Native testing additionally exposed DbTable MERGEs keyed by name even though the schema's primary key is fqn; this affects the related ORM mapping/query writers too. Fixing and testing those paths together before publishing.

  6. Shashankss1205 commented on Oct 15, 2026

    @Shashankss1205
    Collaborator

    Published #1778. Native Kuzu and Ladybug checks now confirm actual READS/WRITES edges, exact Java namespace/path matching, package/repository isolation, MAPS_TO and datasource backfill/preservation. The writer uses the DbTable fqn primary key in all three affected paths. Full local unit suite: 1,698 passed, 8 skipped; targeted writer scope: 63 passed, 1 skipped. CI is running. Existing indexes need a force reindex to recover previously omitted edges; troubleshooting documents this.

  7. moved this from Backlog tasks to In progress in CGC Progress Boardon Oct 15, 2026
  8. Shashankss1205 commented on Oct 15, 2026

    @Shashankss1205
    Collaborator

    Fixed and merged in #1778 after every current-head CI check passed. Native Kuzu and Ladybug tests confirm real namespace/path-scoped READS/WRITES edges without class_context, no cross-package/repository matches, correct fqn-keyed ORM table writes, MAPS_TO and datasource backfill/preservation. The complete combined fast suite passes 1,828 tests (8 skipped). Re-index affected repositories with cgc index . --force after upgrading to regenerate previously missing links; unresolved/ambiguous namespace warnings explain intentionally skipped records.

  9. moved this from In progress to Done in CGC Progress Boardon Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions