diff --git a/java/vector/src/main/java/org/apache/arrow/vector/table/Row.java b/java/vector/src/main/java/org/apache/arrow/vector/table/Row.java index 053d6735572..dcc5a4dd5cc 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/table/Row.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/table/Row.java @@ -30,6 +30,8 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.vector.BigIntVector; import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; import org.apache.arrow.vector.DecimalVector; import org.apache.arrow.vector.DurationVector; import org.apache.arrow.vector.FieldVector; @@ -70,6 +72,8 @@ import org.apache.arrow.vector.complex.UnionVector; import org.apache.arrow.vector.holders.NullableBigIntHolder; import org.apache.arrow.vector.holders.NullableBitHolder; +import org.apache.arrow.vector.holders.NullableDateDayHolder; +import org.apache.arrow.vector.holders.NullableDateMilliHolder; import org.apache.arrow.vector.holders.NullableDecimalHolder; import org.apache.arrow.vector.holders.NullableDurationHolder; import org.apache.arrow.vector.holders.NullableFloat4Holder; @@ -98,7 +102,7 @@ import org.apache.arrow.vector.holders.NullableUInt8Holder; /** - * Row is a positionable, immutable cursor backed by a {@link Table}. + * Row is a positionable, immutable cursor backed by a {@link Table}. * *

Getters are provided for most vector types. The exceptions being {@link org.apache.arrow.vector.NullVector}, * which only contains null values and has no getter, and {@link org.apache.arrow.vector.ZeroVector}, @@ -740,6 +744,87 @@ public void getBit(int columnIndex, NullableBitHolder holder) { vector.get(rowNumber, holder); } + /** + * Returns a long from the column of the given name at the current row. An IllegalArgumentException + * is thrown if the column is not present, and a ClassCastException is thrown if it is + * present but has a different type. + */ + public long getDateMilli(String columnName) { + DateMilliVector vector = (DateMilliVector) table.getVector(columnName); + return vector.get(rowNumber); + } + + /** + * Returns a long from the column with the given index at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type. + */ + public long getDateMilli(int columnIndex) { + DateMilliVector vector = (DateMilliVector) table.getVector(columnIndex); + return vector.get(rowNumber); + } + + /** + * Updates the holder with the value in the column of the given name at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type + */ + public void getDateMilli(String columnName, NullableDateMilliHolder holder) { + DateMilliVector vector = (DateMilliVector) table.getVector(columnName); + vector.get(rowNumber, holder); + } + + /** + * Updates the holder with the value in the column with the given index at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type + */ + public void getDateMilli(int columnIndex, NullableDateMilliHolder holder) { + DateMilliVector vector = (DateMilliVector) table.getVector(columnIndex); + vector.get(rowNumber, holder); + } + + /** + * Returns an int from the column of the given name at the current row. An IllegalArgumentException + * is thrown if the column is not present, and a ClassCastException is thrown if it is + * present but has a different type. + */ + public int getDateDay(String columnName) { + DateDayVector vector = (DateDayVector) table.getVector(columnName); + return vector.get(rowNumber); + } + + /** + * Returns an int from the column with the given index at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type. + */ + public int getDateDay(int columnIndex) { + DateDayVector vector = (DateDayVector) table.getVector(columnIndex); + return vector.get(rowNumber); + } + + + /** + * Updates the holder with the value in the column of the given name at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type + */ + public void getDateDay(String columnName, NullableDateDayHolder holder) { + DateDayVector vector = (DateDayVector) table.getVector(columnName); + vector.get(rowNumber, holder); + } + + /** + * Updates the holder with the value in the column with the given index at the current row. An + * IllegalArgumentException is thrown if the column is not present, and a ClassCastException + * is thrown if it is present but has a different type + */ + public void getDateDay(int columnIndex, NullableDateDayHolder holder) { + DateDayVector vector = (DateDayVector) table.getVector(columnIndex); + vector.get(rowNumber, holder); + } + /** * Returns a long from the column of the given name at the current row. An IllegalArgumentException * is thrown if the column is not present, and a ClassCastException is thrown if it is @@ -1505,6 +1590,8 @@ public Duration getIntervalDayObj(String columnName) { * Returns a Period from the column of the given name at the current row. An IllegalArgumentException * is thrown if the column is not present, and a ClassCastException is thrown if it is * present but has a different type + * + * @return a Period of n MONTHS, not YEARS */ public Period getIntervalYearObj(String columnName) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnName); @@ -1515,6 +1602,8 @@ public Period getIntervalYearObj(String columnName) { * Returns a Period from the column with the given index at the current row. An * IllegalArgumentException is thrown if the column is not present, and a ClassCastException * is thrown if it is present but has a different type + * + * @return a Period of n MONTHS, not YEARS */ public Period getIntervalYearObj(int columnIndex) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnIndex); @@ -1525,6 +1614,8 @@ public Period getIntervalYearObj(int columnIndex) { * Returns an int from the column of the given name at the current row. An IllegalArgumentException * is thrown if the column is not present, and a ClassCastException is thrown if it is * present but has a different type + * + * @return the number of MONTHS in the interval (not YEARS) */ public int getIntervalYear(String columnName) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnName); @@ -1535,6 +1626,8 @@ public int getIntervalYear(String columnName) { * Returns an int from the column with the given index at the current row. An * IllegalArgumentException is thrown if the column is not present, and a ClassCastException * is thrown if it is present but has a different type + * + * @return the number of MONTHS in the interval (not YEARS) */ public int getIntervalYear(int columnIndex) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnIndex); @@ -1545,6 +1638,8 @@ public int getIntervalYear(int columnIndex) { * Updates the holder with the value from the column of the given name at the current row. An * IllegalArgumentException is thrown if the column is not present, and a ClassCastException * is thrown if it is present but has a different type + * + * @param holder a holder to store the interval. Note that the value of the holder represents MONTHS not years */ public void getIntervalYear(String columnName, NullableIntervalYearHolder holder) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnName); @@ -1555,6 +1650,8 @@ public void getIntervalYear(String columnName, NullableIntervalYearHolder holder * Updates the holder with the value from the column with the given index at the current row. An * IllegalArgumentException is thrown if the column is not present, and a ClassCastException * is thrown if it is present but has a different type + * + * @param holder a holder to store the interval. Note that the value of the holder represents MONTHS not years */ public void getIntervalYear(int columnIndex, NullableIntervalYearHolder holder) { IntervalYearVector vector = (IntervalYearVector) table.getVector(columnIndex); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/table/Table.java b/java/vector/src/main/java/org/apache/arrow/vector/table/Table.java index a981a775fa5..5768bb0ec75 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/table/Table.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/table/Table.java @@ -127,8 +127,7 @@ public Table copy() { } return new Table(vectorCopies, (int) getRowCount(), providerCopy); } - - + /** * Returns a new Table created by adding the given vector to the vectors in this Table. * diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java index 3bdaef712ce..78f2ee51b89 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/BaseTableTest.java @@ -143,7 +143,6 @@ void close() { void getRowCount() { List vectorList = twoIntColumns(allocator); try (Table t = new Table(vectorList)) { - // TODO: handle setting rowcount on Table construction assertEquals(2, t.getRowCount()); } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java index b64f8b1a057..cb0b7b8eb6b 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/table/TestUtils.java @@ -19,18 +19,27 @@ import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.OFFSET_WIDTH; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; import org.apache.arrow.vector.BitVectorHelper; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.DurationVector; import org.apache.arrow.vector.FieldVector; import org.apache.arrow.vector.FixedSizeBinaryVector; import org.apache.arrow.vector.Float4Vector; import org.apache.arrow.vector.Float8Vector; import org.apache.arrow.vector.GenerateSampleData; import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.IntervalDayVector; +import org.apache.arrow.vector.IntervalMonthDayNanoVector; +import org.apache.arrow.vector.IntervalYearVector; import org.apache.arrow.vector.LargeVarBinaryVector; import org.apache.arrow.vector.LargeVarCharVector; import org.apache.arrow.vector.SmallIntVector; @@ -63,7 +72,9 @@ import org.apache.arrow.vector.complex.writer.Float8Writer; import org.apache.arrow.vector.complex.writer.IntWriter; import org.apache.arrow.vector.holders.NullableUInt4Holder; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.Types; +import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; @@ -247,6 +258,9 @@ static List simpleTemporalVectors( vectors.add(new TimeStampMicroVector("timeStampMicro_vector", allocator)); vectors.add(new TimeStampNanoVector("timeStampNano_vector", allocator)); + vectors.add(new DateMilliVector("dateMilli_vector", allocator)); + vectors.add(new DateDayVector("dateDay_vector", allocator)); + vectors.forEach(vec -> GenerateSampleData.generateTestData(vec, rowCount)); return vectors; } @@ -266,6 +280,17 @@ static List timezoneTemporalVectors(BufferAllocator allocator, int return vectors; } + static List intervalVectors(BufferAllocator allocator, int rowCount) { + List vectors = new ArrayList<>(); + vectors.add(new IntervalDayVector("intervalDay_vector", allocator)); + vectors.add(new IntervalYearVector("intervalYear_vector", allocator)); + vectors.add(new IntervalMonthDayNanoVector("intervalMonthDayNano_vector", allocator)); + vectors.add(new DurationVector("duration_vector", + new FieldType(true, new ArrowType.Duration(TimeUnit.SECOND), null), allocator)); + vectors.forEach(vec -> GenerateSampleData.generateTestData(vec, rowCount)); + return vectors; + } + /** Returns a list vector of ints. */ static ListVector simpleListVector(BufferAllocator allocator) { ListVector listVector = ListVector.empty(INT_LIST_VECTOR_NAME, allocator); @@ -291,7 +316,6 @@ static ListVector simpleListVector(BufferAllocator allocator) { } listVector.setLastSet(outerCount - 1); listVector.setValueCount(outerCount); - return listVector; } @@ -323,7 +347,7 @@ static StructVector simpleStructVector(BufferAllocator allocator) { return structVector; } - /** Returns a MapVector of ints to doubles. */ + /** Returns a MapVector of longs to doubles. */ static MapVector simpleMapVector(BufferAllocator allocator) { MapVector mapVector = MapVector.empty(BIGINT_INT_MAP_VECTOR_NAME, allocator, false); mapVector.allocateNew(); @@ -343,6 +367,22 @@ static MapVector simpleMapVector(BufferAllocator allocator) { return mapVector; } + static List decimalVector(BufferAllocator allocator, int rowCount) { + List vectors = new ArrayList<>(); + vectors.add(new DecimalVector("decimal_vector", + new FieldType(true, new ArrowType.Decimal(38, 10, 128), null), + allocator)); + vectors.forEach(vec -> generateDecimalData((DecimalVector) vec, rowCount)); + return vectors; + } + + static List bitVector(BufferAllocator allocator, int rowCount) { + List vectors = new ArrayList<>(); + vectors.add(new BitVector("bit_vector", allocator)); + vectors.forEach(vec -> GenerateSampleData.generateTestData(vec, rowCount)); + return vectors; + } + /** Returns a UnionVector. */ static UnionVector simpleUnionVector(BufferAllocator allocator) { final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder(); @@ -380,4 +420,18 @@ static DenseUnionVector simpleDenseUnionVector(BufferAllocator allocator) { unionVector.setValueCount(4); return unionVector; } + + private static void generateDecimalData(DecimalVector vector, int valueCount) { + final BigDecimal even = new BigDecimal("0.0543278923"); + final BigDecimal odd = new BigDecimal("2.0543278923"); + for (int i = 0; i < valueCount; i++) { + if (i % 2 == 0) { + vector.setSafe(i, even); + } else { + vector.setSafe(i, odd); + } + } + vector.setValueCount(valueCount); + } + }