Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Improve type coverage of DefaultVectorComparators #37701

Closed
lidavidm opened this issue Sep 13, 2023 · 5 comments · Fixed by #37748
Closed

[Java] Improve type coverage of DefaultVectorComparators #37701

lidavidm opened this issue Sep 13, 2023 · 5 comments · Fixed by #37748

Comments

@lidavidm
Copy link
Member

Describe the enhancement requested

It appears booleans and the various date/time/timestamp types are missing: https://github.com/apache/arrow/blob/main/java/algorithm/src/main/java/org/apache/arrow/algorithm/sort/DefaultVectorComparators.java

Ideally we would support all Arrow types.

Component(s)

Java

@jduo
Copy link
Member

jduo commented Sep 13, 2023

take

@jduo
Copy link
Member

jduo commented Sep 14, 2023

On VectorValueComparator, there is a field for tracking the width of a value that applies to fixed-width vectors. For BitVectors this is a bit problematic since the width is an integer and BitVectors store use a single bit for values. It looks like this can be used for sorting algorithms.

What should be the behavior here? It seems that for variable-width types this gets ignored.

@lidavidm
Copy link
Member Author

Right, I only see it used when sorting.

I think for now, it can have a default nonsensical value (-1, or something), and we can have the sorter explicitly error if it gets a BitVector. A follow-up task could be to refactor getValueWidth to return Optional or similar, and then specialize FixedWidthOutOfPlaceVectorSorter on BitVector.

@jduo
Copy link
Member

jduo commented Sep 14, 2023

IntervalMonthDayNanoVector has its values represented externally (when calling getObject()) as PeriodDurations, which are a composition of Period and Duration objects. However Periods are not comparable by design (since months are units of periods but have variable numbers of days).

So this type seems like it is not really comparable.

@lidavidm
Copy link
Member Author

That's fair. C++ only sorts these types:

// Visit all physical types for which sorting is implemented.
#define VISIT_SORTABLE_PHYSICAL_TYPES(VISIT) \
VISIT(BooleanType) \
VISIT(Int8Type) \
VISIT(Int16Type) \
VISIT(Int32Type) \
VISIT(Int64Type) \
VISIT(UInt8Type) \
VISIT(UInt16Type) \
VISIT(UInt32Type) \
VISIT(UInt64Type) \
VISIT(FloatType) \
VISIT(DoubleType) \
VISIT(BinaryType) \
VISIT(LargeBinaryType) \
VISIT(FixedSizeBinaryType) \
VISIT(Decimal128Type) \
VISIT(Decimal256Type)

I think some types (like timestamps, dates) map onto those types, though (as that lists 'physical' types) but I agree intervals probably aren't (easily) sortable, then.

lidavidm pushed a commit that referenced this issue Sep 15, 2023
### Rationale for this change

Add default comparators for more vector types to make algorithms easier to use and provide more consistency for Java compared to other languages.

### What changes are included in this PR?

Add default type comparators for:
- BitVector
- DateDayVector
- DateMilliVector
- Decimal256Vector
- DecimalVector
- DurationVector
- IntervalDayVector
- TimeMicroVector
- TimeMilliVector
- TimeNanoVector
- TimeSecVector
- TimeStampVector

IntervalMonthDayNanoVector is not supported due to its public type PeriodDuration not being Comparable.
BitVector's getWidth() method does not return valid data by design since its length is smaller than 1 byte. Using a BitVector with a fixed-width type's algorithm will throw an IllegalArgumentException.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: #37701

Authored-by: James Duong <duong.james@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
@lidavidm lidavidm added this to the 14.0.0 milestone Sep 15, 2023
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…#37748)

### Rationale for this change

Add default comparators for more vector types to make algorithms easier to use and provide more consistency for Java compared to other languages.

### What changes are included in this PR?

Add default type comparators for:
- BitVector
- DateDayVector
- DateMilliVector
- Decimal256Vector
- DecimalVector
- DurationVector
- IntervalDayVector
- TimeMicroVector
- TimeMilliVector
- TimeNanoVector
- TimeSecVector
- TimeStampVector

IntervalMonthDayNanoVector is not supported due to its public type PeriodDuration not being Comparable.
BitVector's getWidth() method does not return valid data by design since its length is smaller than 1 byte. Using a BitVector with a fixed-width type's algorithm will throw an IllegalArgumentException.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#37701

Authored-by: James Duong <duong.james@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
…#37748)

### Rationale for this change

Add default comparators for more vector types to make algorithms easier to use and provide more consistency for Java compared to other languages.

### What changes are included in this PR?

Add default type comparators for:
- BitVector
- DateDayVector
- DateMilliVector
- Decimal256Vector
- DecimalVector
- DurationVector
- IntervalDayVector
- TimeMicroVector
- TimeMilliVector
- TimeNanoVector
- TimeSecVector
- TimeStampVector

IntervalMonthDayNanoVector is not supported due to its public type PeriodDuration not being Comparable.
BitVector's getWidth() method does not return valid data by design since its length is smaller than 1 byte. Using a BitVector with a fixed-width type's algorithm will throw an IllegalArgumentException.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#37701

Authored-by: James Duong <duong.james@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants