Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion java/vector/src/main/java/org/apache/arrow/vector/table/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}.
*
* <p>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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ void close() {
void getRowCount() {
List<FieldVector> vectorList = twoIntColumns(allocator);
try (Table t = new Table(vectorList)) {
// TODO: handle setting rowcount on Table construction
assertEquals(2, t.getRowCount());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -247,6 +258,9 @@ static List<FieldVector> 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;
}
Expand All @@ -266,6 +280,17 @@ static List<FieldVector> timezoneTemporalVectors(BufferAllocator allocator, int
return vectors;
}

static List<FieldVector> intervalVectors(BufferAllocator allocator, int rowCount) {
List<FieldVector> 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);
Expand All @@ -291,7 +316,6 @@ static ListVector simpleListVector(BufferAllocator allocator) {
}
listVector.setLastSet(outerCount - 1);
listVector.setValueCount(outerCount);

return listVector;
}

Expand Down Expand Up @@ -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();
Expand All @@ -343,6 +367,22 @@ static MapVector simpleMapVector(BufferAllocator allocator) {
return mapVector;
}

static List<FieldVector> decimalVector(BufferAllocator allocator, int rowCount) {
List<FieldVector> 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<FieldVector> bitVector(BufferAllocator allocator, int rowCount) {
List<FieldVector> 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();
Expand Down Expand Up @@ -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);
}

}