Skip to content

Remove custom UDT marshaling code, rely on gocql defaults#102

Merged
mliu33 merged 1 commit intomainfrom
claude/investigate-cassandra-marshaling-nV45x
Apr 20, 2026
Merged

Remove custom UDT marshaling code, rely on gocql defaults#102
mliu33 merged 1 commit intomainfrom
claude/investigate-cassandra-marshaling-nV45x

Conversation

@GITMateuszCharczuk
Copy link
Copy Markdown
Collaborator

@GITMateuszCharczuk GITMateuszCharczuk commented Apr 20, 2026

Summary

This PR removes the custom User-Defined Type (UDT) marshaling/unmarshaling implementation and helper functions, allowing gocql's built-in reflection-based UDT marshaler to handle the serialization automatically. The cql struct tags on all UDT types already provide the necessary field mapping information.

Key Changes

  • Removed files:

    • pkg/model/cassandra/udt.go - Custom marshaling helper functions (unmarshalUDTField, marshalUDTField, verifyUDTTags)
    • pkg/model/cassandra/udt_test.go - All associated unit tests
  • Modified pkg/model/cassandra/message.go:

    • Removed init() function that called verifyUDTTags() for each UDT type
    • Removed UnmarshalUDT() and MarshalUDT() method implementations from Participant, File, Card, CardAction, and QuotedParentMessage types
    • Added clarifying comment explaining that cql struct tags are used by gocql's reflection-based marshaler to map Go fields to Cassandra UDT field names
    • Minor formatting adjustments to struct tag alignment
  • Modified pkg/model/cassandra/message_test.go:

    • Removed integration tests for UnmarshalUDT() and MarshalUDT() methods

Implementation Details

The cql struct tags on all UDT struct fields already contain the correct Cassandra column name mappings (e.g., cql:"eng_name" for the EngName field). gocql's default reflection-based UDT marshaler uses these tags automatically, making the custom implementation redundant. This simplification reduces code complexity while maintaining the same functionality.

https://claude.ai/code/session_01XKyoiWJDNWWkNc29RixBqJ

Summary by CodeRabbit

  • Refactor
    • Simplified Cassandra data serialization by removing custom marshal/unmarshal implementations and relying on standard reflection-based marshaling. Updated struct field mappings to use standardized conventions. This change streamlines the codebase while maintaining existing functionality.

gocql already provides a reflection-based UDT marshaler that reads the
`cql:"..."` struct tag. The custom marshalUDTField/unmarshalUDTField
helpers and the per-UDT MarshalUDT/UnmarshalUDT methods delegating to
them were reimplementing behaviour the driver does natively — all that
was actually needed was the existing `cql` tags.

This mirrors the same simplification applied to message-worker's
cassParticipant in PR #95.

- Delete pkg/model/cassandra/udt.go (helpers + verifyUDTTags)
- Delete pkg/model/cassandra/udt_test.go
- Remove MarshalUDT/UnmarshalUDT methods and init() from message.go
- Drop two obsolete tests in message_test.go

https://claude.ai/code/session_01XKyoiWJDNWWkNc29RixBqJ
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2d5866c-6ca2-4154-acb4-3aa106c1a645

📥 Commits

Reviewing files that changed from the base of the PR and between eacf517 and fba2094.

📒 Files selected for processing (4)
  • pkg/model/cassandra/message.go
  • pkg/model/cassandra/message_test.go
  • pkg/model/cassandra/udt.go
  • pkg/model/cassandra/udt_test.go
💤 Files with no reviewable changes (3)
  • pkg/model/cassandra/message_test.go
  • pkg/model/cassandra/udt_test.go
  • pkg/model/cassandra/udt.go

📝 Walkthrough

Walkthrough

This change removes custom UDT marshaling/unmarshaling method implementations from Participant, File, Card, CardAction, and QuotedParentMessage types, along with their reflection-based helper utilities. The code now relies on gocql's built-in reflection-based UDT marshaling, requiring only properly normalized cql:"" struct tags.

Changes

Cohort / File(s) Summary
Production Code Refactoring
pkg/model/cassandra/message.go
Removed init() function with verifyUDTTags calls, deleted 10 custom MarshalUDT/UnmarshalUDT method implementations across 5 types, removed gocql import, and normalized cql:"" struct tags on Participant, Card, and QuotedParentMessage.
UDT Helper Functions Removal
pkg/model/cassandra/udt.go
Removed all UDT field marshaling/unmarshaling helper functions (unmarshalUDTField, marshalUDTField) and verifyUDTTags verification logic that relied on reflection and cql struct tag inspection.
Test Suite Cleanup
pkg/model/cassandra/message_test.go, pkg/model/cassandra/udt_test.go
Deleted two test cases exercising custom marshal/unmarshal behavior and entire UDT helper test suite covering tag verification, field marshaling/unmarshaling, and error handling scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • yenta
  • mliu33

Poem

🐰 With custom marshaling cast aside,
We trust gocql's reflection tide—
No more hand-wrought encode/decode,
Just tags that light the native road! ✨
Simpler code, the same result,
Refactoring is an art adult! 🎯

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing custom UDT marshaling code and relying on gocql's built-in reflection-based marshaler instead.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/investigate-cassandra-marshaling-nV45x

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Collaborator

@mliu33 mliu33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mliu33 mliu33 merged commit 9e483ff into main Apr 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants