Record.compareTo() throws ClassCastException when comparing records

Open Beginner friendly
#813 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
data

Research direction

Start in wayang-commons/wayang-basic/src/main/java/org/apache/wayang/basic/data/Record.java around lines 184-185 and inspect how compareTo() handles values. Reproduce the equal-record case first, then verify element-by-element comparison for ordering, tie-breaking, single-field records, and dissimilar field types; done means these comparisons no longer throw ClassCastException and equal records return 0.

Written by the indexing model from the issue text.

Description

Description

Record.compareTo() throws a ClassCastException when comparing records containing Comparable values.

The issue occurs because Record.values is an Object[], but compareTo() attempts to cast the entire array to Comparable[].

Location

wayang-commons/wayang-basic/src/main/java/org/apache/wayang/basic/data/Record.java

Around lines 184-185.

Steps to Reproduce

Record first = new Record(1, 2);
Record second = new Record(1, 2);

first.compareTo(second);

This results in a ClassCastException.

Expected Behavior

Record.compareTo() should compare the record values without throwing a ClassCastException.

For the example above, comparing two equal records should return 0.

Proposed Solution

Compare the record values element-by-element instead of casting the entire Object[] to Comparable[].

I have implemented a fix locally and added regression tests covering equal records, ordering, tie-breaking, single-field records, and dissimilar field types.

Dominant language
Java
Stars
274
Forks
141
Avg merge
5d 16h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/wayang

All issues in apache/wayang

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.