Skip to content

Commit

Permalink
Checker framework fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jduo committed Feb 17, 2024
1 parent c90881d commit 47caa0e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,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.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 FlightStream currentStream;
private Schema schema;
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.arrow.flight.sql.impl.FlightSql;
import org.apache.arrow.flight.sql.util.TableRef;
import org.apache.arrow.util.AutoCloseables;
import org.checkerframework.checker.nullness.qual.Nullable;

/** A wrapper around FlightSqlClient which automatically adds CallOptions to each RPC call. */
public class FlightSqlClientWithCallOptions implements AutoCloseable {
Expand Down Expand Up @@ -163,7 +164,7 @@ public FlightInfo getTables(
String catalog,
String dbSchemaFilterPattern,
String tableFilterPattern,
List<String> tableTypes,
@Nullable List<String> tableTypes,
boolean includeSchema,
CallOption... options) {
return client.getTables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ final class GetInfoMetadataReader extends BaseFlightReader {

private final BufferAllocator allocator;
private final Collection<Integer> requestedCodes;
private UInt4Vector infoCodes;
private DenseUnionVector infoValues;
private VarCharVector stringValues;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.Schema;
import org.apache.arrow.vector.util.Text;
import org.checkerframework.checker.nullness.qual.Nullable;

final class GetObjectsMetadataReaders {

Expand Down Expand Up @@ -121,7 +122,7 @@ static ArrowReader CreateGetObjectsReader(
tableTypes,
columnNamePattern);
default:
return null;
throw new IllegalArgumentException();
}
}

Expand Down Expand Up @@ -202,7 +203,7 @@ protected VectorSchemaRoot getAggregateRoot() {
}

private static class GetCatalogsMetadataReader extends GetObjectMetadataReader {
private final Pattern catalogPattern;
private final @Nullable Pattern catalogPattern;

protected GetCatalogsMetadataReader(
BufferAllocator allocator,
Expand Down Expand Up @@ -322,28 +323,35 @@ private static List<FlightEndpoint> doRequest(

private static class GetTablesMetadataReader extends GetObjectMetadataReader {
private static class ColumnDefinition {
Field field;
FlightSqlColumnMetadata metadata;
int ordinal;
final Field field;
final FlightSqlColumnMetadata metadata;
final int ordinal;

private ColumnDefinition(Field field, int ordinal) {
this.field = field;
this.metadata = new FlightSqlColumnMetadata(field.getMetadata());
this.ordinal = ordinal;
}

static ColumnDefinition from(Field field, int ordinal) {
ColumnDefinition columnDefinition = new ColumnDefinition();
columnDefinition.field = field;
columnDefinition.metadata = new FlightSqlColumnMetadata(field.getMetadata());
columnDefinition.ordinal = ordinal;
return columnDefinition;
return new ColumnDefinition(field, ordinal);
}
}

private static class TableDefinition {
String tableType;
final String tableType;

final List<ColumnDefinition> columnDefinitions;

List<ColumnDefinition> columnDefinitions;
TableDefinition(String tableType, List<ColumnDefinition> columnDefinitions) {
this.tableType = tableType;
this.columnDefinitions = columnDefinitions;
}
}

private final String catalogPattern;
private final String dbSchemaPattern;
private final Pattern compiledColumnNamePattern;
private final @Nullable Pattern compiledColumnNamePattern;
private final boolean shouldGetColumns;
private final Map<String, Map<String, Map<String, TableDefinition>>> tablePathToColumnsMap =
new LinkedHashMap<>();
Expand Down Expand Up @@ -396,7 +404,7 @@ protected void processRootFromStream(VectorSchemaRoot root) {
VarCharVector schemaVector = (VarCharVector) root.getVector(1);
VarCharVector tableVector = (VarCharVector) root.getVector(2);
VarCharVector tableTypeVector = (VarCharVector) root.getVector(3);
VarBinaryVector tableSchemaVector =
@Nullable VarBinaryVector tableSchemaVector =
shouldGetColumns ? (VarBinaryVector) root.getVector(4) : null;

for (int i = 0; i < root.getRowCount(); ++i) {
Expand Down Expand Up @@ -442,9 +450,7 @@ protected void processRootFromStream(VectorSchemaRoot root) {
if (schemaEntryValue == null) {
schemaEntryValue = new LinkedHashMap<>();
}
TableDefinition tableDefinition = new TableDefinition();
tableDefinition.columnDefinitions = columns;
tableDefinition.tableType = tableType;
TableDefinition tableDefinition = new TableDefinition(tableType, columns);
schemaEntryValue.put(table, tableDefinition);
return schemaEntryValue;
});
Expand Down Expand Up @@ -483,7 +489,14 @@ protected void finish() throws AdbcException, IOException {
schemaListWriter.startList();
for (Object schemaStructObj : sourceSchemaStructList.getObject(i)) {
final Map<String, Object> schemaStructAsMap = (Map<String, Object>) schemaStructObj;
String schemaName = schemaStructAsMap.get("db_schema_name").toString();
if (schemaStructAsMap == null) {
throw new IllegalStateException(String.format("Error in catalog %s: Null schema encountered when schemas were requested.", catalog));
}
Object schemaNameObj = schemaStructAsMap.get("db_schema_name");
if (schemaNameObj == null) {
throw new IllegalStateException(String.format("Error in catalog %s: Schema with no name encountered.", catalog));
}
String schemaName = schemaNameObj.toString();

// Set up the schema list writer to write at the current position.
schemaListWriter.setPosition(i);
Expand Down Expand Up @@ -664,7 +677,7 @@ private static List<FlightEndpoint> doRequest(
}
}

static Integer getDecimalDigits(final ArrowType fieldType) {
static @Nullable Integer getDecimalDigits(final ArrowType fieldType) {
// We aren't setting DECIMAL_DIGITS for Float/Double as their precision and scale are variable.
if (fieldType instanceof ArrowType.Decimal) {
final ArrowType.Decimal thisDecimal = (ArrowType.Decimal) fieldType;
Expand Down Expand Up @@ -704,7 +717,7 @@ static Integer getDecimalDigits(final ArrowType fieldType) {
return null;
}

static Integer getColumnSize(final ArrowType fieldType) {
static @Nullable Integer getColumnSize(final ArrowType fieldType) {
// We aren't setting COLUMN_SIZE for ROWID SQL Types, as there's no such Arrow type.
// We aren't setting COLUMN_SIZE nor DECIMAL_DIGITS for Float/Double as their precision and
// scale are variable.
Expand Down

0 comments on commit 47caa0e

Please sign in to comment.