Skip to content

Commit

Permalink
GH-35733: [Java] Fix minor type in IntervalMonthDayNanoVector ctor (#…
Browse files Browse the repository at this point in the history
…35734)

### Rationale for this change

The constructor of IntervalMonthDayNanoVector does not set minor type correctly.

```java
  public IntervalMonthDayNanoVector(String name, BufferAllocator allocator) {
    this(name, FieldType.nullable(MinorType.INTERVALDAY.getType()), allocator);
  }
```

It should be `MinorType.INTERVALMONTHDAYNANO`.

### What changes are included in this PR?

Change it to set `MinorType.INTERVALMONTHDAYNANO`.

### Are these changes tested?

Added test to verify vector type.

### Are there any user-facing changes?

No.
* Closes: #35733

Authored-by: Gang Wu <ustcwg@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
wgtmac committed May 24, 2023
1 parent 53c0d33 commit 5582605
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class IntervalMonthDayNanoVector extends BaseFixedWidthVector {
* @param allocator allocator for memory management.
*/
public IntervalMonthDayNanoVector(String name, BufferAllocator allocator) {
this(name, FieldType.nullable(MinorType.INTERVALDAY.getType()), allocator);
this(name, FieldType.nullable(MinorType.INTERVALMONTHDAYNANO.getType()), allocator);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.holders.IntervalMonthDayNanoHolder;
import org.apache.arrow.vector.holders.NullableIntervalMonthDayNanoHolder;
import org.apache.arrow.vector.types.IntervalUnit;
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -94,6 +97,12 @@ public void testBasics() {

assertEquals(0, vector.isSet(1));
assertEquals(1, vector.isSet(2));

assertEquals(Types.MinorType.INTERVALMONTHDAYNANO, vector.getMinorType());
ArrowType fieldType = vector.getField().getType();
assertEquals(ArrowType.ArrowTypeID.Interval, fieldType.getTypeID());
ArrowType.Interval intervalType = (ArrowType.Interval) fieldType;
assertEquals(IntervalUnit.MONTH_DAY_NANO, intervalType.getUnit());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import static org.junit.Assert.assertEquals;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.types.IntervalUnit;
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -53,6 +56,11 @@ public void testGetAsStringBuilder() {
assertEquals("1 year 8 months ", vector.getAsStringBuilder(20).toString());
assertEquals("2 years 6 months ", vector.getAsStringBuilder(30).toString());

assertEquals(Types.MinorType.INTERVALYEAR, vector.getMinorType());
ArrowType fieldType = vector.getField().getType();
assertEquals(ArrowType.ArrowTypeID.Interval, fieldType.getTypeID());
ArrowType.Interval intervalType = (ArrowType.Interval) fieldType;
assertEquals(IntervalUnit.YEAR_MONTH, intervalType.getUnit());
}
}
}

0 comments on commit 5582605

Please sign in to comment.