Skip to content

Validate edge schema before bulk encoding - #379

Merged
em3s merged 3 commits into
mainfrom
fix/377-schema-validation
Jun 15, 2026
Merged

em3s merged 3 commits into
mainfrom
fix/377-schema-validation

Conversation

@eazyhozy

@eazyhozy eazyhozy commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Add schema validation in codec-java before bulk encoding. Edges that violate the schema are now rejected with a descriptive error instead of being silently written as invalid active data.

Closes #377

Changes

  • Edge.validate(EdgeSchema) (new method): iterates all declared schema fields and rejects:
    • required (nullable=false) fields that are missing or null
    • any field with a non-null value that cannot be cast to its declared type (prevents the silent null coercion in DataType.cast())
  • BulkEdgeEncoder.bulkEncodeAll: calls validate for active edges immediately after ensureType and before any byte encoding. Inactive (tombstone) edges skip validation since property values are irrelevant for key-based deletion.
  • EdgeValidationTest (new): unit tests covering required-missing, required-null, required-type-mismatch, nullable-type-mismatch, and happy-path cases.
  • BulkEdgeEncoderTests: two integration tests verifying the bulk path rejects required-null and required-missing edges end-to-end.

How to Test

./gradlew :codec-java:test

All existing tests continue to pass (no regression). New tests cover the failure cases from #377.

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code / claude-opus-4-8

#377)

Add Edge.validateAgainstSchema(EdgeSchema) which rejects:
- required (nullable=false) fields that are missing or null
- any field with a value that cannot be cast to its declared type
  (prevents the silent null coercion in DataType.cast())

Call validateAgainstSchema in BulkEdgeEncoder.bulkEncodeAll for active
edges immediately after ensureType and before any byte serialization.
Inactive (tombstone) edges skip validation since their properties are
irrelevant for key-based deletion.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy
eazyhozy requested a review from em3s as a code owner June 11, 2026 08:20
@eazyhozy eazyhozy self-assigned this Jun 11, 2026
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 11, 2026
@eazyhozy

Copy link
Copy Markdown
Member Author

Follow-up: the same silent null coercion affects the DML write path (nullable field type mismatch in AbstractLabel.mutate). Tracked in #380.

…move continue

- Rename Edge.validateAgainstSchema(EdgeSchema) to Edge.validate(EdgeSchema)
  for brevity; argument type already conveys what is validated against.
- Replace the early-continue guard with an if/else-if block to eliminate
  the mid-loop control flow jump.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
@em3s em3s changed the title fix: reject schema-violating edges before HFile generation in bulkload Validate edge schema before bulk encoding Jun 15, 2026
@em3s
em3s removed their request for review June 15, 2026 03:58
@em3s

em3s commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Post-review refactoring (09c8e09):

  • Rename: Edge.validateAgainstSchema(EdgeSchema) → Edge.validate(EdgeSchema). The argument type already conveys what is validated against, so the redundant suffix was dropped. Matches the style of the neighboring ensureType(schema).
  • Remove continue: replaced the early-continue guard inside the loop with an if / else if block, making the two branches structurally parallel and easier to read.
  • PR title/body: removed "HFile" references — codec-java only produces byte-encoded key/value pairs; the HFile write happens in the caller. Updated to "Validate edge schema before bulk encoding" to match the actual scope and the imperative style of other PRs in this repo.

@em3s
em3s merged commit 4399df9 into main Jun 15, 2026
2 checks passed
@em3s
em3s deleted the fix/377-schema-validation branch June 15, 2026 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add schema validation before HFile generation in bulkload (codec-java)

2 participants