diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java index 0c61ad70721..223ae9aa8cb 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java @@ -580,6 +580,14 @@ public TransferPair getTransferPair(BufferAllocator allocator) { */ public abstract TransferPair getTransferPair(String ref, BufferAllocator allocator); + /** + * Construct a transfer pair of this vector and another vector of same type. + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return TransferPair + */ + public abstract TransferPair getTransferPair(Field field, BufferAllocator allocator); + /** * Transfer this vector'data to another vector. The memory associated * with this vector is transferred to the allocator of target vector diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java index 22fe4254ffd..679e5d06c01 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseValueVector.java @@ -24,6 +24,7 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.ReferenceManager; import org.apache.arrow.util.Preconditions; +import org.apache.arrow.vector.complex.reader.FieldReader; import org.apache.arrow.vector.util.DataSizeRoundingUtil; import org.apache.arrow.vector.util.TransferPair; import org.apache.arrow.vector.util.ValueVectorUtility; @@ -50,6 +51,8 @@ public abstract class BaseValueVector implements ValueVector { protected final BufferAllocator allocator; + protected volatile FieldReader fieldReader; + protected BaseValueVector(BufferAllocator allocator) { this.allocator = Preconditions.checkNotNull(allocator, "allocator cannot be null"); } @@ -143,6 +146,35 @@ long computeCombinedBufferSize(int valueCount, int typeWidth) { return allocator.getRoundingPolicy().getRoundedSize(bufferSize); } + /** + * Each vector has a different reader that implements the FieldReader interface. Overridden methods must make + * sure to return the correct concrete reader implementation. + * + * @return Returns a lambda that initializes a reader when called. + */ + protected abstract FieldReader getReaderImpl(); + + /** + * Default implementation to create a reader for the vector. Depends on the individual vector + * class' implementation of {@link #getReaderImpl} to initialize the reader appropriately. + * + * @return Concrete instance of FieldReader by using double-checked locking. + */ + public FieldReader getReader() { + FieldReader reader = fieldReader; + + if (reader != null) { + return reader; + } + synchronized (this) { + if (fieldReader == null) { + fieldReader = getReaderImpl(); + } + + return fieldReader; + } + } + /** * Container for primitive vectors (1 for the validity bit-mask and one to hold the values). */ diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java index c19955b54e5..b0052e7e330 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BigIntVector.java @@ -37,7 +37,6 @@ */ public final class BigIntVector extends BaseFixedWidthVector implements BaseIntVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; /** * Instantiate a BigIntVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public BigIntVector(String name, FieldType fieldType, BufferAllocator allocator) */ public BigIntVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new BigIntReaderImpl(BigIntVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new BigIntReaderImpl(BigIntVector.this); } /** @@ -286,7 +279,7 @@ public static long get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -298,6 +291,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising of this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -331,6 +337,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new BigIntVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new BigIntVector(field, allocator); + } + public TransferImpl(BigIntVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java index 3bcfd983e64..104819147b1 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java @@ -46,8 +46,6 @@ public final class BitVector extends BaseFixedWidthVector { private static final int HASH_CODE_FOR_ONE = 19; - private final FieldReader reader; - /** * Instantiate a BitVector. This doesn't allocate any memory for * the data in vector. @@ -80,17 +78,11 @@ public BitVector(String name, FieldType fieldType, BufferAllocator allocator) { */ public BitVector(Field field, BufferAllocator allocator) { super(field, allocator, 0); - reader = new BitReaderImpl(BitVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new BitReaderImpl(BitVector.this); } /** @@ -542,7 +534,7 @@ public void setRangeToOne(int firstBitIndex, int count) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -554,6 +546,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -572,6 +577,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new BitVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new BitVector(field, allocator); + } + public TransferImpl(BitVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java index 3e88268450a..c99c5786058 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DateDayVector.java @@ -38,7 +38,6 @@ public final class DateDayVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a DateDayVector. This doesn't allocate any memory for @@ -72,17 +71,11 @@ public DateDayVector(String name, FieldType fieldType, BufferAllocator allocator */ public DateDayVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new DateDayReaderImpl(DateDayVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new DateDayReaderImpl(DateDayVector.this); } /** @@ -290,7 +283,7 @@ public static int get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -302,6 +295,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -320,6 +326,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new DateDayVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new DateDayVector(field, allocator); + } + public TransferImpl(DateDayVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java index 73738d77176..6ab8ac4eed2 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DateMilliVector.java @@ -40,7 +40,6 @@ */ public final class DateMilliVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; /** * Instantiate a DateMilliVector. This doesn't allocate any memory for @@ -74,17 +73,11 @@ public DateMilliVector(String name, FieldType fieldType, BufferAllocator allocat */ public DateMilliVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new DateMilliReaderImpl(DateMilliVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new DateMilliReaderImpl(DateMilliVector.this); } /** @@ -293,7 +286,7 @@ public static long get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -305,6 +298,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -323,6 +329,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new DateMilliVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new DateMilliVector(field, allocator); + } + public TransferImpl(DateMilliVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java index 5a1526b0c49..4ccee50d680 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Decimal256Vector.java @@ -46,7 +46,6 @@ public final class Decimal256Vector extends BaseFixedWidthVector { public static final int MAX_PRECISION = 76; public static final byte TYPE_WIDTH = 32; private static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; - private final FieldReader reader; private final int precision; private final int scale; @@ -85,19 +84,13 @@ public Decimal256Vector(String name, FieldType fieldType, BufferAllocator alloca public Decimal256Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); ArrowType.Decimal arrowType = (ArrowType.Decimal) field.getFieldType().getType(); - reader = new Decimal256ReaderImpl(Decimal256Vector.this); this.precision = arrowType.getPrecision(); this.scale = arrowType.getScale(); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new Decimal256ReaderImpl(Decimal256Vector.this); } /** @@ -532,7 +525,7 @@ public void setSafe(int index, int isSet, long start, ArrowBuf buffer) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -544,6 +537,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -563,6 +569,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { Decimal256Vector.this.scale); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new Decimal256Vector(field, allocator); + } + public TransferImpl(Decimal256Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java index 3fa9152a260..db04563df24 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DecimalVector.java @@ -45,7 +45,6 @@ public final class DecimalVector extends BaseFixedWidthVector { public static final int MAX_PRECISION = 38; public static final byte TYPE_WIDTH = 16; private static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; - private final FieldReader reader; private final int precision; private final int scale; @@ -84,19 +83,13 @@ public DecimalVector(String name, FieldType fieldType, BufferAllocator allocator public DecimalVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); ArrowType.Decimal arrowType = (ArrowType.Decimal) field.getFieldType().getType(); - reader = new DecimalReaderImpl(DecimalVector.this); this.precision = arrowType.getPrecision(); this.scale = arrowType.getScale(); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new DecimalReaderImpl(DecimalVector.this); } /** @@ -531,7 +524,7 @@ public void setSafe(int index, int isSet, long start, ArrowBuf buffer) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -543,6 +536,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -562,6 +568,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { DecimalVector.this.scale); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new DecimalVector(field, allocator); + } + public TransferImpl(DecimalVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java b/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java index 7af21a8ecdc..1e1db0d1c3c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/DurationVector.java @@ -43,7 +43,6 @@ */ public final class DurationVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; private final TimeUnit unit; @@ -68,18 +67,12 @@ public DurationVector(String name, FieldType fieldType, BufferAllocator allocato */ public DurationVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new DurationReaderImpl(DurationVector.this); this.unit = ((ArrowType.Duration) field.getFieldType().getType()).getUnit(); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new DurationReaderImpl(DurationVector.this); } /** @@ -369,6 +362,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -387,6 +393,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new DurationVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new DurationVector(field, allocator); + } + public TransferImpl(DurationVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java b/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java index ee5b700f505..9433719c5b8 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/ExtensionTypeVector.java @@ -131,7 +131,7 @@ public TransferPair makeTransferPair(ValueVector target) { } @Override - public FieldReader getReader() { + protected FieldReader getReaderImpl() { return underlyingVector.getReader(); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java b/java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java index f9ea37e4c37..3ce2bb77ccc 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java @@ -39,7 +39,6 @@ */ public class FixedSizeBinaryVector extends BaseFixedWidthVector { private final int byteWidth; - private final FieldReader reader; /** * Instantiate a FixedSizeBinaryVector. This doesn't allocate any memory for @@ -74,18 +73,12 @@ public FixedSizeBinaryVector(String name, FieldType fieldType, BufferAllocator a */ public FixedSizeBinaryVector(Field field, BufferAllocator allocator) { super(field, allocator, ((FixedSizeBinary) field.getFieldType().getType()).getByteWidth()); - reader = new FixedSizeBinaryReaderImpl(FixedSizeBinaryVector.this); byteWidth = ((FixedSizeBinary) field.getFieldType().getType()).getByteWidth(); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new FixedSizeBinaryReaderImpl(FixedSizeBinaryVector.this); } /** @@ -335,7 +328,7 @@ public static byte[] get(final ArrowBuf buffer, final int index, final int byteW /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -347,6 +340,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -365,6 +371,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new FixedSizeBinaryVector(ref, allocator, FixedSizeBinaryVector.this.byteWidth); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new FixedSizeBinaryVector(field, allocator); + } + public TransferImpl(FixedSizeBinaryVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java index 365a1529bb0..4b56a22f2d0 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Float4Vector.java @@ -37,7 +37,6 @@ */ public final class Float4Vector extends BaseFixedWidthVector implements FloatingPointVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a Float4Vector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public Float4Vector(String name, FieldType fieldType, BufferAllocator allocator) */ public Float4Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new Float4ReaderImpl(Float4Vector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new Float4ReaderImpl(Float4Vector.this); } /** @@ -304,7 +297,7 @@ public double getValueAsDouble(int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -316,6 +309,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -334,6 +340,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new Float4Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new Float4Vector(field, allocator); + } + public TransferImpl(Float4Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java index 948390d46f2..7e4fae7087b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/Float8Vector.java @@ -37,7 +37,6 @@ */ public final class Float8Vector extends BaseFixedWidthVector implements FloatingPointVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; /** * Instantiate a Float8Vector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public Float8Vector(String name, FieldType fieldType, BufferAllocator allocator) */ public Float8Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new Float8ReaderImpl(Float8Vector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new Float8ReaderImpl(Float8Vector.this); } /** @@ -305,7 +298,7 @@ public double getValueAsDouble(int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -317,6 +310,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -335,6 +341,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new Float8Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new Float8Vector(field, allocator); + } + public TransferImpl(Float8Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java index e591ec1e857..5c8ef440e8e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntVector.java @@ -37,7 +37,6 @@ */ public final class IntVector extends BaseFixedWidthVector implements BaseIntVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a IntVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public IntVector(String name, FieldType fieldType, BufferAllocator allocator) { */ public IntVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new IntReaderImpl(IntVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new IntReaderImpl(IntVector.this); } /** @@ -290,7 +283,7 @@ public static int get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -302,6 +295,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -335,6 +341,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new IntVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new IntVector(field, allocator); + } + public TransferImpl(IntVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java index 0dc860e6b8d..35312ba7c96 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalDayVector.java @@ -41,7 +41,6 @@ public final class IntervalDayVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 8; private static final byte MILLISECOND_OFFSET = 4; - private final FieldReader reader; /** * Instantiate a IntervalDayVector. This doesn't allocate any memory for @@ -75,17 +74,11 @@ public IntervalDayVector(String name, FieldType fieldType, BufferAllocator alloc */ public IntervalDayVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new IntervalDayReaderImpl(IntervalDayVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new IntervalDayReaderImpl(IntervalDayVector.this); } /** @@ -376,7 +369,7 @@ public void setSafe(int index, int isSet, int days, int milliseconds) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -388,6 +381,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -406,6 +412,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new IntervalDayVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new IntervalDayVector(field, allocator); + } + public TransferImpl(IntervalDayVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java index 888efbc9aa4..73bbc0a2c19 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalMonthDayNanoVector.java @@ -46,7 +46,6 @@ public final class IntervalMonthDayNanoVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 16; private static final byte DAY_OFFSET = 4; private static final byte NANOSECOND_OFFSET = 8; - private final FieldReader reader; /** @@ -81,17 +80,11 @@ public IntervalMonthDayNanoVector(String name, FieldType fieldType, BufferAlloca */ public IntervalMonthDayNanoVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new IntervalMonthDayNanoReaderImpl(IntervalMonthDayNanoVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new IntervalMonthDayNanoReaderImpl(IntervalMonthDayNanoVector.this); } /** @@ -385,7 +378,7 @@ public void setSafe(int index, int isSet, int months, int days, /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -397,6 +390,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising of this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -415,6 +421,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new IntervalMonthDayNanoVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new IntervalMonthDayNanoVector(field, allocator); + } + public TransferImpl(IntervalMonthDayNanoVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java index 7ddfe6b78b1..7fe572f3ff1 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/IntervalYearVector.java @@ -39,7 +39,6 @@ */ public final class IntervalYearVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a IntervalYearVector. This doesn't allocate any memory for @@ -73,17 +72,11 @@ public IntervalYearVector(String name, FieldType fieldType, BufferAllocator allo */ public IntervalYearVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new IntervalYearReaderImpl(IntervalYearVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new IntervalYearReaderImpl(IntervalYearVector.this); } /** @@ -325,7 +318,7 @@ public void setSafe(int index, int isSet, int value) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -337,6 +330,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -355,6 +361,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new IntervalYearVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new IntervalYearVector(field, allocator); + } + public TransferImpl(IntervalYearVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java index e9d60b38e7a..0063a61da57 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java @@ -34,7 +34,6 @@ * The size of the underlying buffer can be over 2GB. */ public final class LargeVarBinaryVector extends BaseLargeVariableWidthVector { - private final FieldReader reader; /** * Instantiate a LargeVarBinaryVector. This doesn't allocate any memory for @@ -68,17 +67,11 @@ public LargeVarBinaryVector(String name, FieldType fieldType, BufferAllocator al */ public LargeVarBinaryVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new LargeVarBinaryReaderImpl(LargeVarBinaryVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new LargeVarBinaryReaderImpl(LargeVarBinaryVector.this); } /** diff --git a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java index fd205726011..1f8d9b7d3a8 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java @@ -37,7 +37,6 @@ *

*/ public final class LargeVarCharVector extends BaseLargeVariableWidthVector { - private final FieldReader reader; /** * Instantiate a LargeVarCharVector. This doesn't allocate any memory for @@ -69,16 +68,11 @@ public LargeVarCharVector(String name, FieldType fieldType, BufferAllocator allo */ public LargeVarCharVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new LargeVarCharReaderImpl(LargeVarCharVector.this); } - /** - * Get a reader that supports reading values from this vector. - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new LargeVarCharReaderImpl(LargeVarCharVector.this); } /** diff --git a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java index 1de6dea90f8..518ee707396 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/SmallIntVector.java @@ -37,7 +37,6 @@ */ public final class SmallIntVector extends BaseFixedWidthVector implements BaseIntVector { public static final byte TYPE_WIDTH = 2; - private final FieldReader reader; /** * Instantiate a SmallIntVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public SmallIntVector(String name, FieldType fieldType, BufferAllocator allocato */ public SmallIntVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new SmallIntReaderImpl(SmallIntVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new SmallIntReaderImpl(SmallIntVector.this); } /** @@ -317,7 +310,7 @@ public static short get(final ArrowBuf buffer, final int index) { *----------------------------------------------------------------*/ /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -329,6 +322,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -362,6 +368,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new SmallIntVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new SmallIntVector(field, allocator); + } + public TransferImpl(SmallIntVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java index cf128859e4c..86738cd221e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeMicroVector.java @@ -38,7 +38,6 @@ */ public final class TimeMicroVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; /** * Instantiate a TimeMicroVector. This doesn't allocate any memory for @@ -72,17 +71,11 @@ public TimeMicroVector(String name, FieldType fieldType, BufferAllocator allocat */ public TimeMicroVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new TimeMicroReaderImpl(TimeMicroVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeMicroReaderImpl(TimeMicroVector.this); } /** @@ -290,7 +283,7 @@ public static long get(final ArrowBuf buffer, int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -302,6 +295,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -320,6 +326,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new TimeMicroVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new TimeMicroVector(field, allocator); + } + public TransferImpl(TimeMicroVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java index b96990b1060..480add91097 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeMilliVector.java @@ -40,7 +40,6 @@ */ public final class TimeMilliVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a TimeMilliVector. This doesn't allocate any memory for @@ -74,17 +73,11 @@ public TimeMilliVector(String name, FieldType fieldType, BufferAllocator allocat */ public TimeMilliVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new TimeMilliReaderImpl(TimeMilliVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeMilliReaderImpl(TimeMilliVector.this); } /** @@ -294,7 +287,7 @@ public static int get(final ArrowBuf buffer, final int index) { *----------------------------------------------------------------*/ /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -306,6 +299,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -324,6 +330,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new TimeMilliVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new TimeMilliVector(field, allocator); + } + public TransferImpl(TimeMilliVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java index bc78a026461..82609cdc446 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeNanoVector.java @@ -37,7 +37,6 @@ */ public final class TimeNanoVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; /** * Instantiate a TimeNanoVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public TimeNanoVector(String name, FieldType fieldType, BufferAllocator allocato */ public TimeNanoVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new TimeNanoReaderImpl(TimeNanoVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeNanoReaderImpl(TimeNanoVector.this); } /** @@ -290,7 +283,7 @@ public static long get(final ArrowBuf buffer, final int index) { *----------------------------------------------------------------*/ /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -302,6 +295,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -320,6 +326,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new TimeNanoVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new TimeNanoVector(field, allocator); + } + public TransferImpl(TimeNanoVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java index 29b7381be31..9b7614e55b6 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeSecVector.java @@ -37,7 +37,6 @@ */ public final class TimeSecVector extends BaseFixedWidthVector { public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; /** * Instantiate a TimeSecVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public TimeSecVector(String name, FieldType fieldType, BufferAllocator allocator */ public TimeSecVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new TimeSecReaderImpl(TimeSecVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeSecReaderImpl(TimeSecVector.this); } /** @@ -291,7 +284,7 @@ public static int get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -303,6 +296,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising of this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -321,6 +327,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new TimeSecVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new TimeSecVector(field, allocator); + } + public TransferImpl(TimeSecVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java index e083392ffe5..a37b444d1a3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java @@ -37,7 +37,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampMicroTZVector extends TimeStampVector { - private final FieldReader reader; private final String timeZone; /** @@ -63,7 +62,6 @@ public TimeStampMicroTZVector(String name, FieldType fieldType, BufferAllocator super(name, fieldType, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) fieldType.getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampMicroTZReaderImpl(TimeStampMicroTZVector.this); } /** @@ -77,17 +75,11 @@ public TimeStampMicroTZVector(Field field, BufferAllocator allocator) { super(field, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) field.getFieldType().getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampMicroTZReaderImpl(TimeStampMicroTZVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampMicroTZReaderImpl(TimeStampMicroTZVector.this); } /** @@ -229,7 +221,7 @@ public void setSafe(int index, TimeStampMicroTZHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -243,6 +235,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampMicroTZVector to = new TimeStampMicroTZVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java index 5cbef896264..88ce27a187e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java @@ -38,7 +38,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampMicroVector extends TimeStampVector { - private final FieldReader reader; /** * Instantiate a TimeStampMicroVector. This doesn't allocate any memory for @@ -61,7 +60,6 @@ public TimeStampMicroVector(String name, BufferAllocator allocator) { */ public TimeStampMicroVector(String name, FieldType fieldType, BufferAllocator allocator) { super(name, fieldType, allocator); - reader = new TimeStampMicroReaderImpl(TimeStampMicroVector.this); } /** @@ -73,17 +71,11 @@ public TimeStampMicroVector(String name, FieldType fieldType, BufferAllocator al */ public TimeStampMicroVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new TimeStampMicroReaderImpl(TimeStampMicroVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampMicroReaderImpl(TimeStampMicroVector.this); } /** @@ -209,7 +201,7 @@ public void setSafe(int index, TimeStampMicroHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -223,6 +215,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampMicroVector to = new TimeStampMicroVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java index d01a43aa1b6..775594ceea6 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java @@ -37,7 +37,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampMilliTZVector extends TimeStampVector { - private final FieldReader reader; private final String timeZone; /** @@ -63,7 +62,6 @@ public TimeStampMilliTZVector(String name, FieldType fieldType, BufferAllocator super(name, fieldType, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) fieldType.getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampMilliTZReaderImpl(TimeStampMilliTZVector.this); } /** @@ -77,17 +75,11 @@ public TimeStampMilliTZVector(Field field, BufferAllocator allocator) { super(field, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) field.getFieldType().getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampMilliTZReaderImpl(TimeStampMilliTZVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampMilliTZReaderImpl(TimeStampMilliTZVector.this); } /** @@ -228,7 +220,7 @@ public void setSafe(int index, TimeStampMilliTZHolder holder) { *----------------------------------------------------------------*/ /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -242,6 +234,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampMilliTZVector to = new TimeStampMilliTZVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java index 8f46f5606df..a42773269f8 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java @@ -38,7 +38,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampMilliVector extends TimeStampVector { - private final FieldReader reader; /** * Instantiate a TimeStampMilliVector. This doesn't allocate any memory for @@ -61,7 +60,6 @@ public TimeStampMilliVector(String name, BufferAllocator allocator) { */ public TimeStampMilliVector(String name, FieldType fieldType, BufferAllocator allocator) { super(name, fieldType, allocator); - reader = new TimeStampMilliReaderImpl(TimeStampMilliVector.this); } /** @@ -73,17 +71,11 @@ public TimeStampMilliVector(String name, FieldType fieldType, BufferAllocator al */ public TimeStampMilliVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new TimeStampMilliReaderImpl(TimeStampMilliVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampMilliReaderImpl(TimeStampMilliVector.this); } /** @@ -209,7 +201,7 @@ public void setSafe(int index, TimeStampMilliHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -223,6 +215,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampMilliVector to = new TimeStampMilliVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java index 2a51babda16..af43cf6fc9b 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java @@ -37,7 +37,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampNanoTZVector extends TimeStampVector { - private final FieldReader reader; private final String timeZone; /** @@ -63,7 +62,6 @@ public TimeStampNanoTZVector(String name, FieldType fieldType, BufferAllocator a super(name, fieldType, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) fieldType.getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampNanoTZReaderImpl(TimeStampNanoTZVector.this); } /** @@ -77,17 +75,11 @@ public TimeStampNanoTZVector(Field field, BufferAllocator allocator) { super(field, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) field.getFieldType().getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampNanoTZReaderImpl(TimeStampNanoTZVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampNanoTZReaderImpl(TimeStampNanoTZVector.this); } /** @@ -231,7 +223,7 @@ public void setSafe(int index, TimeStampNanoTZHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -245,6 +237,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampNanoTZVector to = new TimeStampNanoTZVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java index 7b87dac4377..7b02b1c87d3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java @@ -38,7 +38,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampNanoVector extends TimeStampVector { - private final FieldReader reader; /** * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for @@ -61,7 +60,6 @@ public TimeStampNanoVector(String name, BufferAllocator allocator) { */ public TimeStampNanoVector(String name, FieldType fieldType, BufferAllocator allocator) { super(name, fieldType, allocator); - reader = new TimeStampNanoReaderImpl(TimeStampNanoVector.this); } /** @@ -73,17 +71,11 @@ public TimeStampNanoVector(String name, FieldType fieldType, BufferAllocator all */ public TimeStampNanoVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new TimeStampNanoReaderImpl(TimeStampNanoVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampNanoReaderImpl(TimeStampNanoVector.this); } /** @@ -209,7 +201,7 @@ public void setSafe(int index, TimeStampNanoHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -223,6 +215,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampNanoVector to = new TimeStampNanoVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java index 47e796e9951..5837e9d8515 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java @@ -37,7 +37,6 @@ * (bit vector) is maintained to track which elements in the vector are null. */ public final class TimeStampSecTZVector extends TimeStampVector { - private final FieldReader reader; private final String timeZone; /** @@ -63,7 +62,6 @@ public TimeStampSecTZVector(String name, FieldType fieldType, BufferAllocator al super(name, fieldType, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) fieldType.getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampSecTZReaderImpl(TimeStampSecTZVector.this); } /** @@ -77,17 +75,11 @@ public TimeStampSecTZVector(Field field, BufferAllocator allocator) { super(field, allocator); ArrowType.Timestamp arrowType = (ArrowType.Timestamp) field.getFieldType().getType(); timeZone = arrowType.getTimezone(); - reader = new TimeStampSecTZReaderImpl(TimeStampSecTZVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampSecTZReaderImpl(TimeStampSecTZVector.this); } /** @@ -242,6 +234,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising of this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampSecTZVector to = new TimeStampSecTZVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java index f12e19684be..1e249140335 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java @@ -38,7 +38,6 @@ * maintained to track which elements in the vector are null. */ public final class TimeStampSecVector extends TimeStampVector { - private final FieldReader reader; /** * Instantiate a TimeStampSecVector. This doesn't allocate any memory for @@ -61,7 +60,6 @@ public TimeStampSecVector(String name, BufferAllocator allocator) { */ public TimeStampSecVector(String name, FieldType fieldType, BufferAllocator allocator) { super(name, fieldType, allocator); - reader = new TimeStampSecReaderImpl(TimeStampSecVector.this); } /** @@ -73,17 +71,11 @@ public TimeStampSecVector(String name, FieldType fieldType, BufferAllocator allo */ public TimeStampSecVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new TimeStampSecReaderImpl(TimeStampSecVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TimeStampSecReaderImpl(TimeStampSecVector.this); } /** @@ -210,7 +202,7 @@ public void setSafe(int index, TimeStampSecHolder holder) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -224,6 +216,20 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(to); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + TimeStampSecVector to = new TimeStampSecVector(field, allocator); + return new TransferImpl(to); + } + /** * Construct a TransferPair with a desired target vector of the same type. * diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java index f08b0e02f81..4c4eee1342f 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TinyIntVector.java @@ -37,7 +37,6 @@ */ public final class TinyIntVector extends BaseFixedWidthVector implements BaseIntVector { public static final byte TYPE_WIDTH = 1; - private final FieldReader reader; /** * Instantiate a TinyIntVector. This doesn't allocate any memory for @@ -71,17 +70,11 @@ public TinyIntVector(String name, FieldType fieldType, BufferAllocator allocator */ public TinyIntVector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new TinyIntReaderImpl(TinyIntVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new TinyIntReaderImpl(TinyIntVector.this); } /** @@ -318,7 +311,7 @@ public static byte get(final ArrowBuf buffer, final int index) { /** - * Construct a TransferPair comprising of this and a target vector of + * Construct a TransferPair comprising this and a target vector of * the same type. * * @param ref name of the target vector @@ -330,6 +323,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + /** * Construct a TransferPair with a desired target vector of the same type. * @@ -363,6 +369,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new TinyIntVector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new TinyIntVector(field, allocator); + } + public TransferImpl(TinyIntVector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java index bd9a732c108..777df3fb1ef 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt1Vector.java @@ -48,7 +48,6 @@ public final class UInt1Vector extends BaseFixedWidthVector implements BaseIntVe public static final byte MAX_UINT1 = (byte) 0XFF; public static final byte TYPE_WIDTH = 1; - private final FieldReader reader; public UInt1Vector(String name, BufferAllocator allocator) { this(name, FieldType.nullable(MinorType.UINT1.getType()), allocator); @@ -58,14 +57,18 @@ public UInt1Vector(String name, FieldType fieldType, BufferAllocator allocator) this(new Field(name, fieldType, null), allocator); } + /** + * Constructor for UInt1Vector. + * @param field Field type + * @param allocator Allocator type + */ public UInt1Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new UInt1ReaderImpl(UInt1Vector.this); } @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new UInt1ReaderImpl(UInt1Vector.this); } @Override @@ -309,6 +312,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + @Override public TransferPair makeTransferPair(ValueVector to) { return new TransferImpl((UInt1Vector) to); @@ -341,6 +357,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new UInt1Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new UInt1Vector(field, allocator); + } + public TransferImpl(UInt1Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java index 5c29ab6b321..e5b95be191d 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt2Vector.java @@ -44,7 +44,6 @@ public final class UInt2Vector extends BaseFixedWidthVector implements BaseIntVe public static final char MAX_UINT2 = (char) 0XFFFF; public static final byte TYPE_WIDTH = 2; - private final FieldReader reader; public UInt2Vector(String name, BufferAllocator allocator) { this(name, FieldType.nullable(MinorType.UINT2.getType()), allocator); @@ -54,14 +53,18 @@ public UInt2Vector(String name, FieldType fieldType, BufferAllocator allocator) this(new Field(name, fieldType, null), allocator); } + /** + * Constructor for UInt2Vector type. + * @param field Field type + * @param allocator Allocator type + */ public UInt2Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new UInt2ReaderImpl(UInt2Vector.this); } @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new UInt2ReaderImpl(UInt2Vector.this); } @Override @@ -286,6 +289,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + @Override public TransferPair makeTransferPair(ValueVector to) { return new TransferImpl((UInt2Vector) to); @@ -319,6 +335,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new UInt2Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new UInt2Vector(field, allocator); + } + public TransferImpl(UInt2Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java index cc954d67ddd..bda98b12005 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt4Vector.java @@ -49,7 +49,6 @@ public final class UInt4Vector extends BaseFixedWidthVector implements BaseIntVe public static final int MAX_UINT4 = 0XFFFFFFFF; public static final byte TYPE_WIDTH = 4; - private final FieldReader reader; public UInt4Vector(String name, BufferAllocator allocator) { this(name, FieldType.nullable(MinorType.UINT4.getType()), allocator); @@ -59,14 +58,18 @@ public UInt4Vector(String name, FieldType fieldType, BufferAllocator allocator) this(new Field(name, fieldType, null), allocator); } + /** + * Constructor for UInt4Vector. + * @param field Field type + * @param allocator Allocator type + */ public UInt4Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new UInt4ReaderImpl(UInt4Vector.this); } @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new UInt4ReaderImpl(UInt4Vector.this); } @Override @@ -281,6 +284,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + @Override public TransferPair makeTransferPair(ValueVector to) { return new TransferImpl((UInt4Vector) to); @@ -313,6 +329,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new UInt4Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new UInt4Vector(field, allocator); + } + public TransferImpl(UInt4Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java index 98eaf25a6e2..5e7c18902f0 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/UInt8Vector.java @@ -46,7 +46,6 @@ public final class UInt8Vector extends BaseFixedWidthVector implements BaseIntVe public static final long MAX_UINT8 = 0XFFFFFFFFFFFFFFFFL; public static final byte TYPE_WIDTH = 8; - private final FieldReader reader; public UInt8Vector(String name, BufferAllocator allocator) { this(name, FieldType.nullable(MinorType.UINT8.getType()), allocator); @@ -56,14 +55,18 @@ public UInt8Vector(String name, FieldType fieldType, BufferAllocator allocator) this(new Field(name, fieldType, null), allocator); } + /** + * Constructor for UInt8Vector. + * @param field Field type + * @param allocator Allocator type. + */ public UInt8Vector(Field field, BufferAllocator allocator) { super(field, allocator, TYPE_WIDTH); - reader = new UInt8ReaderImpl(UInt8Vector.this); } @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new UInt8ReaderImpl(UInt8Vector.this); } @Override @@ -277,6 +280,19 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator) { return new TransferImpl(ref, allocator); } + /** + * Construct a TransferPair comprising this and a target vector of + * the same type. + * + * @param field Field object used by the target vector + * @param allocator allocator for the target vector + * @return {@link TransferPair} + */ + @Override + public TransferPair getTransferPair(Field field, BufferAllocator allocator) { + return new TransferImpl(field, allocator); + } + @Override public TransferPair makeTransferPair(ValueVector to) { return new TransferImpl((UInt8Vector) to); @@ -309,6 +325,10 @@ public TransferImpl(String ref, BufferAllocator allocator) { to = new UInt8Vector(ref, field.getFieldType(), allocator); } + public TransferImpl(Field field, BufferAllocator allocator) { + to = new UInt8Vector(field, allocator); + } + public TransferImpl(UInt8Vector to) { this.to = to; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java b/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java index 798d30fe4a8..34e072aaa83 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java @@ -35,7 +35,6 @@ * to track which elements in the vector are null. */ public final class VarBinaryVector extends BaseVariableWidthVector { - private final FieldReader reader; /** * Instantiate a VarBinaryVector. This doesn't allocate any memory for @@ -69,17 +68,11 @@ public VarBinaryVector(String name, FieldType fieldType, BufferAllocator allocat */ public VarBinaryVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new VarBinaryReaderImpl(VarBinaryVector.this); } - /** - * Get a reader that supports reading values from this vector. - * - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new VarBinaryReaderImpl(VarBinaryVector.this); } /** diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java b/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java index e725e2d2839..bc5c68b29f3 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/VarCharVector.java @@ -36,7 +36,6 @@ * to track which elements in the vector are null. */ public final class VarCharVector extends BaseVariableWidthVector { - private final FieldReader reader; /** * Instantiate a VarCharVector. This doesn't allocate any memory for @@ -68,16 +67,11 @@ public VarCharVector(String name, FieldType fieldType, BufferAllocator allocator */ public VarCharVector(Field field, BufferAllocator allocator) { super(field, allocator); - reader = new VarCharReaderImpl(VarCharVector.this); } - /** - * Get a reader that supports reading values from this vector. - * @return Field Reader for this vector - */ @Override - public FieldReader getReader() { - return reader; + protected FieldReader getReaderImpl() { + return new VarCharReaderImpl(VarCharVector.this); } /** diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java index 9b7f6e03060..0f788291811 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java @@ -48,6 +48,7 @@ import org.apache.arrow.vector.compare.VectorVisitor; import org.apache.arrow.vector.complex.impl.UnionFixedSizeListReader; import org.apache.arrow.vector.complex.impl.UnionFixedSizeListWriter; +import org.apache.arrow.vector.complex.reader.FieldReader; import org.apache.arrow.vector.ipc.message.ArrowFieldNode; import org.apache.arrow.vector.types.Types.MinorType; import org.apache.arrow.vector.types.pojo.ArrowType; @@ -181,11 +182,14 @@ public List getFieldInnerVectors() { throw new UnsupportedOperationException("There are no inner vectors. Use getFieldBuffers"); } + @Override + protected FieldReader getReaderImpl() { + return new UnionFixedSizeListReader(this); + } + @Override public UnionFixedSizeListReader getReader() { - if (reader == null) { - reader = new UnionFixedSizeListReader(this); - } + reader = (UnionFixedSizeListReader) super.getReader(); return reader; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java index c08c2e496e3..6ef5f994fc6 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java @@ -695,11 +695,14 @@ public void copyValueSafe(int from, int to) { } } + @Override + protected FieldReader getReaderImpl() { + return new UnionLargeListReader(this); + } + @Override public UnionLargeListReader getReader() { - if (reader == null) { - reader = new UnionLargeListReader(this); - } + reader = (UnionLargeListReader) super.getReader(); return reader; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java index 0fa091fb0ce..52e5307e139 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java @@ -566,11 +566,14 @@ public void copyValueSafe(int from, int to) { } } + @Override + protected FieldReader getReaderImpl() { + return new UnionListReader(this); + } + @Override public UnionListReader getReader() { - if (reader == null) { - reader = new UnionListReader(this); - } + reader = (UnionListReader) super.getReader(); return reader; } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java index 28d56e342be..075a05c04b6 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.util.stream.IntStream; @@ -540,4 +541,13 @@ public void testBitVectorHashCode() { assertFalse(hashCodes[1] == hashCodes[2]); } } + + @Test + public void testGetTransferPairWithField() { + final BitVector fromVector = new BitVector(EMPTY_SCHEMA_PATH, allocator); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final BitVector toVector = (BitVector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java index 82c912cef2f..51368cf6aea 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimal256Vector.java @@ -18,6 +18,7 @@ package org.apache.arrow.vector; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -27,6 +28,7 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.types.pojo.ArrowType; +import org.apache.arrow.vector.util.TransferPair; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -337,6 +339,15 @@ public void setUsingArrowBufOfBEBytes() { } } + @Test + public void testGetTransferPairWithField() { + final Decimal256Vector fromVector = new Decimal256Vector("decimal", allocator, 10, scale); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final Decimal256Vector toVector = (Decimal256Vector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } + private void verifyWritingArrowBufWithBigEndianBytes(Decimal256Vector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java index c7e3e436e40..ba25cbe8b52 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDecimalVector.java @@ -18,6 +18,7 @@ package org.apache.arrow.vector; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -27,6 +28,7 @@ import org.apache.arrow.memory.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.types.pojo.ArrowType; +import org.apache.arrow.vector.util.TransferPair; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -345,6 +347,15 @@ public void setUsingArrowBufOfBEBytes() { } } + @Test + public void testGetTransferPairWithField() { + final DecimalVector fromVector = new DecimalVector("decimal", allocator, 10, scale); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final DecimalVector toVector = (DecimalVector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } + private void verifyWritingArrowBufWithBigEndianBytes(DecimalVector decimalVector, ArrowBuf buf, BigDecimal[] expectedValues, int length) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java index 8ae876f2011..c5d4d296cc0 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestDurationVector.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import java.time.Duration; @@ -26,6 +27,7 @@ import org.apache.arrow.vector.holders.NullableDurationHolder; import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; +import org.apache.arrow.vector.util.TransferPair; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -134,4 +136,14 @@ public void testNanosBasics() { assertEquals(1000000 , holder.value); } } + + @Test + public void testGetTransferPairWithField() { + final DurationVector fromVector = TestUtils.newVector(DurationVector.class, "nanos", + new ArrowType.Duration(TimeUnit.NANOSECOND), allocator); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final DurationVector toVector = (DurationVector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java index e8f764a21e9..c413f4e23eb 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeBinaryVector.java @@ -24,6 +24,7 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.holders.FixedSizeBinaryHolder; import org.apache.arrow.vector.holders.NullableFixedSizeBinaryHolder; +import org.apache.arrow.vector.util.TransferPair; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -276,4 +277,13 @@ public void testGetNull() { vector.setNull(0); assertNull(vector.get(0)); } + + @Test + public void testGetTransferPairWithField() { + final FixedSizeBinaryVector fromVector = new FixedSizeBinaryVector("fixedSizeBinary", allocator, typeWidth); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final FixedSizeBinaryVector toVector = (FixedSizeBinaryVector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java index 9fc15654b3f..4b2ae2eb3d4 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestIntervalYearVector.java @@ -18,11 +18,13 @@ package org.apache.arrow.vector; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; 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.apache.arrow.vector.util.TransferPair; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -63,4 +65,13 @@ public void testGetAsStringBuilder() { assertEquals(IntervalUnit.YEAR_MONTH, intervalType.getUnit()); } } + + @Test + public void testGetTransferPairWithField() { + final IntervalYearVector fromVector = new IntervalYearVector("", allocator); + final TransferPair transferPair = fromVector.getTransferPair(fromVector.getField(), allocator); + final IntervalYearVector toVector = (IntervalYearVector) transferPair.getTo(); + // Field inside a new vector created by reusing a field should be the same in memory as the original field. + assertSame(fromVector.getField(), toVector.getField()); + } }