Skip to content

Commit

Permalink
apacheGH-15187: add new lambda to return implementation of the reader
Browse files Browse the repository at this point in the history
  • Loading branch information
rtadepalli committed Jun 16, 2023
1 parent fe52705 commit fa74584
Show file tree
Hide file tree
Showing 41 changed files with 142 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.apache.arrow.vector;

import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.Iterator;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -153,11 +153,11 @@ long computeCombinedBufferSize(int valueCount, int typeWidth) {
*
* @return Returns the implementation class type of the vector's reader.
*/
protected abstract Class<? extends FieldReader> getReaderImplClass();
protected abstract Supplier<FieldReader> getReaderImpl();

/**
* Default implementation to create a reader for the vector. Depends on the individual vector
* class' implementation of {@link #getReaderImplClass} to initialize the reader appropriately.
* class' implementation of {@link #getReaderImpl} to initialize the reader appropriately.
*
* @return Concrete instance of FieldReader by using lazy initialization.
*/
Expand All @@ -169,13 +169,7 @@ public FieldReader getReader() {
}
synchronized (this) {
if (fieldReader == null) {
try {
fieldReader = getReaderImplClass().getDeclaredConstructor(getClass()).newInstance(this);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
InvocationTargetException e) {
logger.error("Unable to instantiate FieldReader for {} because of: ", getClass().getSimpleName(), e);
throw new RuntimeException(e);
}
fieldReader = getReaderImpl().get();
}

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

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.BigIntReaderImpl;
Expand Down Expand Up @@ -73,8 +75,8 @@ public BigIntVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return BigIntReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new BigIntReaderImpl(BigIntVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.apache.arrow.memory.util.LargeMemoryUtil.capAtMaxInt;
import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.util.ArrowBufPointer;
Expand Down Expand Up @@ -81,8 +83,8 @@ public BitVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return BitReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new BitReaderImpl(BitVector.this);
}

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

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.DateDayReaderImpl;
Expand Down Expand Up @@ -74,8 +76,8 @@ public DateDayVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return DateDayReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new DateDayReaderImpl(DateDayVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.time.LocalDateTime;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -76,8 +77,8 @@ public DateMilliVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return DateMilliReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new DateMilliReaderImpl(DateMilliVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.math.BigDecimal;
import java.nio.ByteOrder;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -89,8 +90,8 @@ public Decimal256Vector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return Decimal256ReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new Decimal256ReaderImpl(Decimal256Vector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.math.BigDecimal;
import java.nio.ByteOrder;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -88,8 +89,8 @@ public DecimalVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return DecimalReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new DecimalReaderImpl(DecimalVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.time.Duration;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -71,8 +72,8 @@ public DurationVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return DurationReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new DurationReaderImpl(DurationVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -131,7 +132,7 @@ public TransferPair makeTransferPair(ValueVector target) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
protected Supplier<FieldReader> getReaderImpl() {
throw new UnsupportedOperationException("Readers for extension types depend on the underlying vector, " +
"asking for a concrete implementation class of the reader type is invalid.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.util.Preconditions;
Expand Down Expand Up @@ -77,8 +79,8 @@ public FixedSizeBinaryVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return FixedSizeBinaryReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new FixedSizeBinaryReaderImpl(FixedSizeBinaryVector.this);
}

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

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.Float4ReaderImpl;
Expand Down Expand Up @@ -73,8 +75,8 @@ public Float4Vector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return Float4ReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new Float4ReaderImpl(Float4Vector.this);
}

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

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.Float8ReaderImpl;
Expand Down Expand Up @@ -73,8 +75,8 @@ public Float8Vector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return Float8ReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new Float8ReaderImpl(Float8Vector.this);
}

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

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.IntReaderImpl;
Expand Down Expand Up @@ -73,8 +75,8 @@ public IntVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return IntReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new IntReaderImpl(IntVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
public final class IntervalDayVector extends BaseFixedWidthVector {
public static final byte TYPE_WIDTH = 8;
private static final byte MILLISECOND_OFFSET = 4;
private Supplier<FieldReader> reader;

/**
* Instantiate a IntervalDayVector. This doesn't allocate any memory for
Expand Down Expand Up @@ -76,19 +75,11 @@ public IntervalDayVector(String name, FieldType fieldType, BufferAllocator alloc
*/
public IntervalDayVector(Field field, BufferAllocator allocator) {
super(field, allocator, TYPE_WIDTH);
reader = () -> {
final FieldReader fieldReader;
synchronized (this) {
fieldReader = new IntervalDayReaderImpl(IntervalDayVector.this);
reader = () -> fieldReader;
}
return fieldReader;
};
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return IntervalDayReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new IntervalDayReaderImpl(IntervalDayVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 Supplier<FieldReader> reader;


/**
Expand Down Expand Up @@ -85,8 +84,8 @@ public IntervalMonthDayNanoVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return IntervalMonthDayNanoReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new IntervalMonthDayNanoReaderImpl(IntervalMonthDayNanoVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import java.time.Period;
import java.util.function.Supplier;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.BufferAllocator;
Expand Down Expand Up @@ -75,8 +76,8 @@ public IntervalYearVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return IntervalYearReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new IntervalYearReaderImpl(IntervalYearVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.arrow.vector;

import java.util.function.Supplier;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.LargeVarBinaryReaderImpl;
import org.apache.arrow.vector.complex.reader.FieldReader;
Expand Down Expand Up @@ -70,8 +72,8 @@ public LargeVarBinaryVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return LargeVarBinaryReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new LargeVarBinaryReaderImpl(LargeVarBinaryVector.this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.arrow.vector;

import java.util.function.Supplier;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.LargeVarCharReaderImpl;
import org.apache.arrow.vector.complex.reader.FieldReader;
Expand Down Expand Up @@ -71,8 +73,8 @@ public LargeVarCharVector(Field field, BufferAllocator allocator) {
}

@Override
protected Class<? extends FieldReader> getReaderImplClass() {
return LargeVarCharReaderImpl.class;
protected Supplier<FieldReader> getReaderImpl() {
return () -> new LargeVarCharReaderImpl(LargeVarCharVector.this);
}

/**
Expand Down

0 comments on commit fa74584

Please sign in to comment.