Skip to content

Commit

Permalink
test(java): add Checker Framework
Browse files Browse the repository at this point in the history
Fixes apache#624.
  • Loading branch information
lidavidm committed Feb 8, 2024
1 parent 0b103c8 commit b8f843d
Show file tree
Hide file tree
Showing 43 changed files with 745 additions and 318 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ repos:
entry: bash -c 'cd go/adbc && golangci-lint run --fix --timeout 5m'
types_or: [go]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
rev: v2.12.0
hooks:
- id: pretty-format-golang
- id: pretty-format-java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.adapter.jdbc;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Calendar;

import org.apache.arrow.vector.types.pojo.ArrowType;

public class JdbcToArrowUtils {
public static ArrowType getArrowTypeFromJdbcType(JdbcFieldInfo fieldInfo, @Nullable Calendar calendar);
}
24 changes: 24 additions & 0 deletions java/.checker-framework/org.apache.arrow.util.AutoCloseables.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.util;

import org.checkerframework.checker.nullness.qual.Nullable;

public final class AutoCloseables {
public static void close(@Nullable AutoCloseable... autoCloseables) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.vector.types.pojo;

import org.checkerframework.checker.nullness.qual.Nullable;

import org.apache.arrow.vector.types.TimeUnit;

public abstract class ArrowType {
public abstract static class PrimitiveType extends ArrowType {
}

public static class Timestamp extends PrimitiveType {
public Timestamp(TimeUnit unit, @Nullable String timezone);
}
}
29 changes: 29 additions & 0 deletions java/.checker-framework/org.junit.jupiter.api.Assumptions.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.junit.jupiter.api;

import org.checkerframework.dataflow.qual.AssertMethod;
import org.opentest4j.TestAbortedException;

public class Assumptions {
@AssertMethod(value = TestAbortedException.class)
public static void assumeTrue(boolean assumption, String message) throws TestAbortedException;

@AssertMethod(isAssertFalse = true, value = TestAbortedException.class)
public static void assumeFalse(boolean assumption, String message) throws TestAbortedException;
}
6 changes: 6 additions & 0 deletions java/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<artifactId>arrow-vector</artifactId>
</dependency>

<!-- Static analysis and linting -->
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.assertj</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.arrow.vector.VectorSchemaRoot;
import org.apache.arrow.vector.ipc.ArrowReader;
import org.apache.arrow.vector.types.pojo.Schema;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A connection to a {@link AdbcDatabase}.
Expand Down Expand Up @@ -79,7 +80,7 @@ default ArrowReader readPartition(ByteBuffer descriptor) throws AdbcException {
*
* @param infoCodes The metadata items to fetch.
*/
ArrowReader getInfo(int[] infoCodes) throws AdbcException;
ArrowReader getInfo(int @Nullable [] infoCodes) throws AdbcException;

/**
* Get metadata about the driver/database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public interface AdbcDriver {

/** ADBC API revision 1.0.0. */
long ADBC_VERSION_1_0_0 = 1_000_000;

/** ADBC API revision 1.1.0. */
long ADBC_VERSION_1_1_0 = 1_001_000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.Collections;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* An error in the database or ADBC driver.
Expand All @@ -34,20 +35,24 @@
*/
public class AdbcException extends Exception {
private final AdbcStatusCode status;
private final String sqlState;
private final @Nullable String sqlState;
private final int vendorCode;
private Collection<ErrorDetail> details;

public AdbcException(
String message, Throwable cause, AdbcStatusCode status, String sqlState, int vendorCode) {
@Nullable String message,
@Nullable Throwable cause,
AdbcStatusCode status,
@Nullable String sqlState,
int vendorCode) {
this(message, cause, status, sqlState, vendorCode, Collections.emptyList());
}

public AdbcException(
String message,
Throwable cause,
@Nullable String message,
@Nullable Throwable cause,
AdbcStatusCode status,
String sqlState,
@Nullable String sqlState,
int vendorCode,
Collection<ErrorDetail> details) {
super(message, cause);
Expand Down Expand Up @@ -83,7 +88,7 @@ public AdbcStatusCode getStatus() {
}

/** A SQLSTATE error code, if provided, as defined by the SQL:2003 standard. */
public String getSqlState() {
public @Nullable String getSqlState() {
return sqlState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.arrow.adbc.core;

import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Additional details (not necessarily human-readable) contained in an {@link AdbcException}. */
public class ErrorDetail {
Expand All @@ -37,7 +38,7 @@ public Object getValue() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.ByteBuffer;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;

/** An opaque descriptor for a part of a potentially distributed or partitioned result set. */
public final class PartitionDescriptor {
Expand All @@ -32,7 +33,7 @@ public ByteBuffer getDescriptor() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,64 @@ private StandardSchemas() {

public static final List<Field> COLUMN_SCHEMA =
Arrays.asList(
new Field("column_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field("ordinal_position", FieldType.nullable(INT32), null),
new Field("remarks", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_data_type", FieldType.nullable(INT16), null),
new Field("xdbc_type_name", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_column_size", FieldType.nullable(INT32), null),
new Field("xdbc_decimal_digits", FieldType.nullable(INT16), null),
new Field("xdbc_num_prec_radix", FieldType.nullable(INT16), null),
new Field("xdbc_nullable", FieldType.nullable(INT16), null),
new Field("xdbc_column_def", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_sql_data_type", FieldType.nullable(INT16), null),
new Field("xdbc_datetime_sub", FieldType.nullable(INT16), null),
new Field("xdbc_char_octet_length", FieldType.nullable(INT32), null),
new Field("xdbc_is_nullable", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_scope_catalog", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_scope_schema", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_scope_table", FieldType.nullable(ArrowType.Utf8.INSTANCE), null),
new Field("xdbc_is_autoincrement", FieldType.nullable(ArrowType.Bool.INSTANCE), null),
new Field("xdbc_is_generatedcolumn", FieldType.nullable(ArrowType.Bool.INSTANCE), null));
new Field(
"column_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field("ordinal_position", FieldType.nullable(INT32), Collections.emptyList()),
new Field(
"remarks", FieldType.nullable(ArrowType.Utf8.INSTANCE), Collections.emptyList()),
new Field("xdbc_data_type", FieldType.nullable(INT16), Collections.emptyList()),
new Field(
"xdbc_type_name",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field("xdbc_column_size", FieldType.nullable(INT32), Collections.emptyList()),
new Field("xdbc_decimal_digits", FieldType.nullable(INT16), Collections.emptyList()),
new Field("xdbc_num_prec_radix", FieldType.nullable(INT16), Collections.emptyList()),
new Field("xdbc_nullable", FieldType.nullable(INT16), Collections.emptyList()),
new Field(
"xdbc_column_def",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field("xdbc_sql_data_type", FieldType.nullable(INT16), Collections.emptyList()),
new Field("xdbc_datetime_sub", FieldType.nullable(INT16), Collections.emptyList()),
new Field("xdbc_char_octet_length", FieldType.nullable(INT32), Collections.emptyList()),
new Field(
"xdbc_is_nullable",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"xdbc_scope_catalog",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"xdbc_scope_schema",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"xdbc_scope_table",
FieldType.nullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"xdbc_is_autoincrement",
FieldType.nullable(ArrowType.Bool.INSTANCE),
Collections.emptyList()),
new Field(
"xdbc_is_generatedcolumn",
FieldType.nullable(ArrowType.Bool.INSTANCE),
Collections.emptyList()));

public static final List<Field> TABLE_SCHEMA =
Arrays.asList(
new Field("table_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field("table_type", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field(
"table_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"table_type",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"table_columns",
FieldType.nullable(ArrowType.List.INSTANCE),
Expand All @@ -136,7 +170,10 @@ private StandardSchemas() {

public static final List<Field> DB_SCHEMA_SCHEMA =
Arrays.asList(
new Field("db_schema_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field(
"db_schema_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"db_schema_tables",
FieldType.nullable(ArrowType.List.INSTANCE),
Expand All @@ -150,7 +187,10 @@ private StandardSchemas() {
public static final Schema GET_OBJECTS_SCHEMA =
new Schema(
Arrays.asList(
new Field("catalog_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field(
"catalog_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"catalog_db_schemas",
FieldType.nullable(ArrowType.List.INSTANCE),
Expand Down Expand Up @@ -180,7 +220,10 @@ private StandardSchemas() {

public static final List<Field> STATISTICS_DB_SCHEMA_SCHEMA =
Arrays.asList(
new Field("db_schema_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field(
"db_schema_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"db_schema_statistics",
FieldType.notNullable(ArrowType.List.INSTANCE),
Expand All @@ -195,7 +238,10 @@ private StandardSchemas() {
public static final Schema GET_STATISTICS_SCHEMA =
new Schema(
Arrays.asList(
new Field("catalog_name", FieldType.notNullable(ArrowType.Utf8.INSTANCE), null),
new Field(
"catalog_name",
FieldType.notNullable(ArrowType.Utf8.INSTANCE),
Collections.emptyList()),
new Field(
"catalog_db_schemas",
FieldType.notNullable(ArrowType.List.INSTANCE),
Expand Down
Loading

0 comments on commit b8f843d

Please sign in to comment.