Skip to content

Commit

Permalink
Checkerframework
Browse files Browse the repository at this point in the history
  • Loading branch information
jduo committed Feb 17, 2024
1 parent 711978e commit 94e3a1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
import org.apache.arrow.vector.ipc.ArrowReader;
import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;
import org.apache.arrow.vector.types.pojo.Schema;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Base class for ArrowReaders based on consuming data from FlightEndpoints. */
public abstract class BaseFlightReader extends ArrowReader {

private final List<FlightEndpoint> flightEndpoints;
private final Supplier<List<FlightEndpoint>> rpcCall;
private int nextEndpointIndex = 0;
private @MonotonicNonNull FlightStream currentStream = null;
private @MonotonicNonNull Schema schema = null;
private @Nullable FlightStream currentStream = null;
private @Nullable Schema schema = null;
private long bytesRead = 0;
protected final FlightSqlClientWithCallOptions client;
protected final LoadingCache<Location, FlightSqlClientWithCallOptions> clientCache;
Expand All @@ -65,7 +65,7 @@ protected BaseFlightReader(

@Override
public boolean loadNextBatch() throws IOException {
Preconditions.checkNotNull(currentStream);
Preconditions.checkState(currentStream != null);
if (!currentStream.next()) {
if (nextEndpointIndex >= flightEndpoints.size()) {
return false;
Expand Down Expand Up @@ -94,7 +94,7 @@ public boolean loadNextBatch() throws IOException {

@Override
protected Schema readSchema() throws IOException {
Preconditions.checkNotNull(currentStream);
Preconditions.checkState(schema != null);
return schema;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.complex.DenseUnionVector;
import org.apache.arrow.vector.types.pojo.Schema;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Helper class to track state needed to build up the info structure. */
Expand All @@ -51,12 +50,12 @@ final class GetInfoMetadataReader extends BaseFlightReader {

private final BufferAllocator allocator;
private final Collection<Integer> requestedCodes;
private @MonotonicNonNull UInt4Vector infoCodes = null;
private @MonotonicNonNull DenseUnionVector infoValues = null;
private @MonotonicNonNull VarCharVector stringValues = null;
private @Nullable UInt4Vector infoCodes = null;
private @Nullable DenseUnionVector infoValues = null;
private @Nullable VarCharVector stringValues = null;
private boolean hasInMemoryDataBeenWritten = false;
private boolean hasInMemoryData;
private boolean hasSupportedCodes;
private final boolean hasInMemoryData;
private final boolean hasSupportedCodes;
private boolean hasRequestBeenIssued = false;

@FunctionalInterface
Expand All @@ -75,14 +74,14 @@ void accept(
SUPPORTED_CODES.put(
FlightSql.SqlInfo.FLIGHT_SQL_SERVER_NAME.getNumber(),
(b, sqlInfo, srcIndex, dstIndex) -> {
Preconditions.checkNotNull(b.infoCodes);
Preconditions.checkState(b.infoCodes != null);
b.infoCodes.setSafe(dstIndex, AdbcInfoCode.VENDOR_NAME.getValue());
b.setStringValue(dstIndex, sqlInfo.getVarCharVector(STRING_VALUE_TYPE_ID).get(srcIndex));
});
SUPPORTED_CODES.put(
FlightSql.SqlInfo.FLIGHT_SQL_SERVER_VERSION.getNumber(),
(b, sqlInfo, srcIndex, dstIndex) -> {
Preconditions.checkNotNull(b.infoCodes);
Preconditions.checkState(b.infoCodes != null);
b.infoCodes.setSafe(dstIndex, AdbcInfoCode.VENDOR_VERSION.getValue());
b.setStringValue(dstIndex, sqlInfo.getVarCharVector(STRING_VALUE_TYPE_ID).get(srcIndex));
});
Expand Down Expand Up @@ -120,16 +119,18 @@ static GetInfoMetadataReader CreateGetInfoMetadataReader(
this.hasInMemoryData =
requestedCodes.contains(AdbcInfoCode.DRIVER_NAME.getValue())
|| requestedCodes.contains(AdbcInfoCode.DRIVER_VERSION.getValue());
boolean hasRequestedCode = false;
for (Integer requestedCode : requestedCodes) {
if (SUPPORTED_CODES.containsKey(requestedCode)) {
hasSupportedCodes = true;
hasRequestedCode = true;
break;
}
}
hasSupportedCodes = hasRequestedCode;
}

void setStringValue(int index, byte[] value) {
Preconditions.checkNotNull(infoValues, stringValues);
Preconditions.checkState(infoValues != null && stringValues != null);
infoValues.setValueCount(index + 1);
infoValues.setTypeId(index, STRING_VALUE_TYPE_ID);
stringValues.setSafe(index, value);
Expand Down

0 comments on commit 94e3a1c

Please sign in to comment.