Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.apache.arrow.vector.util.ValueVectorUtility;

/**
* UInt1Vector implements a fixed width (1 bytes) vector of
Expand Down Expand Up @@ -328,7 +329,10 @@ public long getValueAsLong(int index) {
return this.get(index) & PROMOTION_MASK;
}


@Override
public String toString() {
return ValueVectorUtility.getToString(this, 0, getValueCount(), (v, i) -> v.getObjectNoOverflow(i));
}

private class TransferImpl implements TransferPair {
UInt1Vector to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.apache.arrow.vector.util.ValueVectorUtility;

/**
* UInt2Vector implements a fixed width (2 bytes) vector of
Expand Down Expand Up @@ -305,6 +306,12 @@ public long getValueAsLong(int index) {
return this.get(index);
}

@Override
public String toString() {
return ValueVectorUtility.getToString(this, 0, getValueCount(), (v, i) ->
v.isNull(i) ? "null" : Integer.toString(v.get(i) & 0x0000ffff));
}

private class TransferImpl implements TransferPair {
UInt2Vector to;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.apache.arrow.vector.util.ValueVectorUtility;

/**
* UInt4Vector implements a fixed width (4 bytes) vector of
Expand Down Expand Up @@ -300,6 +301,11 @@ public long getValueAsLong(int index) {
return this.get(index) & PROMOTION_MASK;
}

@Override
public String toString() {
return ValueVectorUtility.getToString(this, 0, getValueCount(), (v, i) -> v.getObjectNoOverflow(i));
}

private class TransferImpl implements TransferPair {
UInt4Vector to;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.util.TransferPair;
import org.apache.arrow.vector.util.ValueVectorUtility;

/**
* UInt8Vector implements a fixed width vector (8 bytes) of
Expand Down Expand Up @@ -296,6 +297,11 @@ public long getValueAsLong(int index) {
return this.get(index);
}

@Override
public String toString() {
return ValueVectorUtility.getToString(this, 0, getValueCount(), (v, i) -> v.getObjectNoOverflow(i));
}

private class TransferImpl implements TransferPair {
UInt8Vector to;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import static org.apache.arrow.vector.validate.ValidateUtil.validateOrThrow;

import java.util.function.BiFunction;

import org.apache.arrow.util.Preconditions;
import org.apache.arrow.vector.BaseFixedWidthVector;
import org.apache.arrow.vector.ValueVector;
Expand All @@ -37,7 +39,7 @@ private ValueVectorUtility() {

/**
* Get the toString() representation of vector suitable for debugging.
* Note since vectors may have millions of values, this method only show max 20 values.
* Note since vectors may have millions of values, this method only shows max 20 values.
* Examples as below (v represents value):
* <li>
* vector with 0 value:
Expand All @@ -52,7 +54,20 @@ private ValueVectorUtility() {
* [v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, ..., v90, v91, v92, v93, v94, v95, v96, v97, v98, v99]
* </li>
*/
public static String getToString(ValueVector vector, int start, int end) {
public static <V extends ValueVector> String getToString(V vector, int start, int end) {
return getToString(vector, start, end, (v, i) -> v.getObject(i));
}

/**
* Get the toString() representation of vector suitable for debugging.
* Note since vectors may have millions of values, this method only shows at most 20 values.
* @param vector the vector for which to get toString representation.
* @param start the starting index, inclusive.
* @param end the end index, exclusive.
* @param valueToString the function to transform individual elements to strings.
*/
public static <V extends ValueVector> String getToString(
V vector, int start, int end, BiFunction<V, Integer, Object> valueToString) {
Preconditions.checkNotNull(vector);
final int length = end - start;
Preconditions.checkArgument(length >= 0);
Expand All @@ -77,7 +92,7 @@ public static String getToString(ValueVector vector, int start, int end) {
i = end - window - 1;
skipComma = true;
} else {
sb.append(vector.getObject(i));
sb.append(valueToString.apply(vector, i));
}

if (i == end - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,38 @@ public void testToString() {
}
}

@Test
public void testUInt1VectorToString() {
try (final UInt1Vector uInt1Vector = new UInt1Vector("uInt1Vector", allocator)) {
setVector(uInt1Vector, (byte) 0xff);
assertEquals("[255]", uInt1Vector.toString());
}
}

@Test
public void testUInt2VectorToString() {
try (final UInt2Vector uInt2Vector = new UInt2Vector("uInt2Vector", allocator)) {
setVector(uInt2Vector, (char) 0xffff);
assertEquals("[65535]", uInt2Vector.toString());
}
}

@Test
public void testUInt4VectorToString() {
try (final UInt4Vector uInt4Vector = new UInt4Vector("uInt4Vector", allocator)) {
setVector(uInt4Vector, 0xffffffff);
assertEquals("[4294967295]", uInt4Vector.toString());
}
}

@Test
public void testUInt8VectorToString() {
try (final UInt8Vector uInt8Vector = new UInt8Vector("uInt8Vector", allocator)) {
setVector(uInt8Vector, 0xffffffffffffffffL);
assertEquals("[18446744073709551615]", uInt8Vector.toString());
}
}

@Test
public void testUnloadVariableWidthVector() {
try (final VarCharVector varCharVector = new VarCharVector("var char", allocator)) {
Expand Down