Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6552] Enable CheckerFramework in 'server' module #3939

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ jobs:
with:
job-id: checkerframework-jdk11
remote-build-cache-proxy-enabled: false
arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes
arguments: --scan --no-parallel --no-daemon -PenableCheckerframework :linq4j:classes :core:classes :server:classes

linux-checkerframework-guava29:
linux-checkerframework-oldest-guava:
name: 'CheckerFramework (JDK 11), oldest Guava'
runs-on: ubuntu-latest
env:
Expand All @@ -398,7 +398,7 @@ jobs:
with:
job-id: checkerframework-jdk11
remote-build-cache-proxy-enabled: false
arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableCheckerframework :linq4j:classes :core:classes
arguments: --scan --no-parallel --no-daemon -Pguava.version=${{ env.GUAVA }} -PenableCheckerframework :linq4j:classes :core:classes :server:classes

linux-slow:
# Run slow tests when the commit is on main or it is requested explicitly by adding an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@
import org.apache.arrow.vector.ipc.ArrowFileReader;
import org.apache.arrow.vector.ipc.message.ArrowRecordBatch;

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

import java.io.IOException;

import static java.util.Objects.requireNonNull;

/**
* Enumerator that reads from a filtered collection of Arrow value-vectors.
*/
class ArrowFilterEnumerator extends AbstractArrowEnumerator {
private final BufferAllocator allocator;
private final Filter filter;
private ArrowBuf buf;
private SelectionVector selectionVector;
private @Nullable ArrowBuf buf;
private @Nullable SelectionVector selectionVector;
private int selectionVectorIndex;

ArrowFilterEnumerator(ArrowFileReader arrowFileReader, ImmutableIntList fields, Filter filter) {
Expand Down Expand Up @@ -71,7 +75,7 @@ class ArrowFilterEnumerator extends AbstractArrowEnumerator {
selectionVectorIndex = 0;
this.valueVectors.clear();
loadNextArrowBatch();
assert selectionVector != null;
requireNonNull(selectionVector, "selectionVector");
if (selectionVectorIndex >= selectionVector.getRecordCount()) {
// the "filtered" batch is empty, but there may be more batches to fetch
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
import java.util.ArrayList;
import java.util.List;

import static java.lang.Double.parseDouble;
import static java.lang.Float.parseFloat;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -183,13 +187,13 @@ private static RelDataType deduceRowType(Schema schema,
private static TreeNode makeLiteralNode(String literal, String type) {
switch (type) {
case "integer":
return TreeBuilder.makeLiteral(Integer.parseInt(literal));
return TreeBuilder.makeLiteral(parseInt(literal));
case "long":
return TreeBuilder.makeLiteral(Long.parseLong(literal));
return TreeBuilder.makeLiteral(parseLong(literal));
case "float":
return TreeBuilder.makeLiteral(Float.parseFloat(literal));
return TreeBuilder.makeLiteral(parseFloat(literal));
case "double":
return TreeBuilder.makeLiteral(Double.parseDouble(literal));
return TreeBuilder.makeLiteral(parseDouble(literal));
case "string":
return TreeBuilder.makeStringLiteral(literal.substring(1, literal.length() - 1));
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.Map;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertEquals;

import static java.util.Objects.requireNonNull;

/**
* Tests for the Apache Arrow adapter.
*/
Expand All @@ -57,9 +58,11 @@ class ArrowAdapterTest {
private static File arrowDataDirectory;

@BeforeAll
static void initializeArrowState(@TempDir Path sharedTempDir) throws IOException, SQLException {
static void initializeArrowState(@TempDir Path sharedTempDir)
throws IOException, SQLException {
URL modelUrl =
Objects.requireNonNull(ArrowAdapterTest.class.getResource("/arrow-model.json"), "url");
requireNonNull(
ArrowAdapterTest.class.getResource("/arrow-model.json"), "url");
Path sourceModelFilePath = Sources.of(modelUrl).file().toPath();
Path modelFileTarget = sharedTempDir.resolve("arrow-model.json");
Files.copy(sourceModelFilePath, modelFileTarget);
Expand Down
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,14 @@ allprojects {
replace("hamcrest: sameInstance", "org.hamcrest.core.IsSame.sameInstance", "org.hamcrest.CoreMatchers.sameInstance")
replace("hamcrest: startsWith", "org.hamcrest.core.StringStartsWith.startsWith", "org.hamcrest.CoreMatchers.startsWith")
replaceRegex("hamcrest: size", "\\.size\\(\\), (is|equalTo)\\(", ", hasSize\\(")
replaceRegex("use static import: parseBoolean", "Boolean\\.(parseBoolean\\()", "$1")
replaceRegex("use static import: parseByte", "Byte\\.(parseByte\\()", "$1")
replaceRegex("use static import: parseDouble", "Double\\.(parseDouble\\()", "$1")
replaceRegex("use static import: parseFloat", "Float\\.(parseFloat\\()", "$1")
replaceRegex("use static import: parseInt", "Integer\\.(parseInt\\()", "$1")
replaceRegex("use static import: parseLong", "Long\\.(parseLong\\()", "$1")
replaceRegex("use static import: parseLong", "Short\\.(parseShort\\()", "$1")
replaceRegex("use static import: requireNonNull", "Objects\\.(requireNonNull\\()", "$1")
replaceRegex("use static import: toImmutableList", "ImmutableList\\.(toImmutableList\\(\\))", "$1")
replaceRegex("use static import: checkArgument", "Preconditions\\.(checkArgument\\()", "$1")
replaceRegex("use static import: checkArgument", "Preconditions\\.(checkState\\()", "$1")
Expand Down Expand Up @@ -778,6 +786,9 @@ allprojects {
if (project.path == ":core") {
extraJavacArgs.add("-AskipDefs=^org\\.apache\\.calcite\\.sql\\.parser\\.impl\\.")
}
if (project.path == ":server") {
extraJavacArgs.add("-AskipDefs=^org\\.apache\\.calcite\\.sql\\.parser\\.ddl\\.")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.Objects;
import java.util.stream.IntStream;

import static java.util.Objects.requireNonNull;

/** Enumerator that reads from a Cassandra column family. */
class CassandraEnumerator implements Enumerator<Object> {
private final Iterator<Row> iterator;
Expand Down Expand Up @@ -86,7 +88,7 @@ class CassandraEnumerator implements Enumerator<Object> {
* @param index Index of the field within the Row object
*/
private @Nullable Object currentRowField(int index) {
assert current != null;
requireNonNull(current, "current");
final Object o =
current.get(index,
CodecRegistry.DEFAULT.codecFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import static org.apache.calcite.util.DateTimeStringUtils.ISO_DATETIME_FRACTIONAL_SECOND_FORMAT;
import static org.apache.calcite.util.DateTimeStringUtils.getDateFormatter;

import static java.util.Objects.requireNonNull;

/**
* Implementation of a {@link org.apache.calcite.rel.core.Filter}
* relational expression in Cassandra.
Expand Down Expand Up @@ -297,7 +298,7 @@ private String translateOp2(String op, String name, RexLiteral right) {
String valueString = value.toString();
if (value instanceof String) {
RelDataTypeField field =
Objects.requireNonNull(rowType.getField(name, true, false));
requireNonNull(rowType.getField(name, true, false));
SqlTypeName typeName = field.getType().getSqlTypeName();
if (typeName != SqlTypeName.CHAR) {
valueString = "'" + valueString + "'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.List;
import java.util.Map;

import static java.util.Objects.requireNonNull;

/**
* Implementation of {@link org.apache.calcite.rel.core.Project}
* relational expression in Cassandra.
Expand All @@ -56,7 +58,8 @@ public CassandraProject(RelOptCluster cluster, RelTraitSet traitSet,

@Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq) {
return super.computeSelfCost(planner, mq).multiplyBy(0.1);
final RelOptCost cost = super.computeSelfCost(planner, mq);
return requireNonNull(cost, "cost").multiplyBy(0.1);
}

@Override public void implement(Implementor implementor) {
Expand All @@ -66,9 +69,9 @@ public CassandraProject(RelOptCluster cluster, RelTraitSet traitSet,
CassandraRules.cassandraFieldNames(getInput().getRowType()));
final Map<String, String> fields = new LinkedHashMap<>();
for (Pair<RexNode, String> pair : getNamedProjects()) {
assert pair.left != null;
final RexNode node = pair.left;
final String name = pair.right;
final String originalName = pair.left.accept(translator);
final String originalName = node.accept(translator);
fields.put(originalName, name);
}
implementor.add(fields, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.Objects.requireNonNull;

/**
* Schema mapped onto a Cassandra column family.
*/
Expand Down Expand Up @@ -297,7 +298,7 @@ private void addMaterializedViews() {
+ "WHERE keyspace_name='" + keyspace + "' AND view_name='"
+ view.getName().asInternal() + "'";

Row whereClauseRow = Objects.requireNonNull(session.execute(whereQuery).one());
Row whereClauseRow = requireNonNull(session.execute(whereQuery).one());

queryBuilder.append(" WHERE ")
.append(whereClauseRow.getString(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static java.lang.Integer.parseInt;

/**
* Factory that creates a {@link CassandraSchema}.
*/
Expand Down Expand Up @@ -107,7 +109,7 @@ private static int getPort(Map<String, Object> map) {
if (map.containsKey("port")) {
Object portObj = map.get("port");
if (portObj instanceof String) {
return Integer.parseInt((String) portObj);
return parseInt((String) portObj);
} else {
return (int) portObj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static java.util.Objects.requireNonNull;

/**
* Relational expression representing a scan of a table in a Cassandra data source.
Expand Down Expand Up @@ -105,7 +106,7 @@ protected CassandraToEnumerableConverter(
list.append("selectFields", constantArrayList(selectList, Pair.class));
final Expression table =
list.append("table",
Objects.requireNonNull(
requireNonNull(
cassandraImplementor.table.getExpression(
CassandraTable.CassandraQueryable.class)));
final Expression predicates =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.time.Duration;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

import static java.util.Objects.requireNonNull;

/**
* JUnit5 extension to start and stop embedded Cassandra server.
*
Expand Down Expand Up @@ -83,9 +85,9 @@ class CassandraExtension implements ParameterResolver, ExecutionCondition {
}

static ImmutableMap<String, String> getDataset(String resourcePath) {
URL u = CassandraExtension.class.getResource(resourcePath);
return ImmutableMap.of("model",
Sources.of(Objects.requireNonNull(CassandraExtension.class.getResource(resourcePath)))
.file().getAbsolutePath());
Sources.of(requireNonNull(u, "u")).file().getAbsolutePath());
}

/** Registers a Cassandra resource in root context, so it can be shared with
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -1745,10 +1745,10 @@ SqlNode SqlInsert() :
(
LOOKAHEAD(2)
p = ParenthesizedCompoundIdentifierList() {
if (p.right.size() > 0) {
if (!p.right.isEmpty()) {
tableRef = extend(tableRef, p.right);
}
if (p.left.size() > 0) {
if (!p.left.isEmpty()) {
columnList = p.left;
} else {
columnList = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ static List<Expression> fromInternal(Class<?>[] targetTypes,
}
} else {
int j = 0;
for (int i = 0; i < expressions.size(); i++) {
for (Expression expression : expressions) {
Class<?> type;
if (!targetTypes[j].isArray()) {
type = targetTypes[j];
j++;
} else {
type = targetTypes[j].getComponentType();
}
list.add(fromInternal(expressions.get(i), type));
list.add(fromInternal(expression, type));
}
}
return list;
Expand Down Expand Up @@ -453,7 +453,7 @@ public static Expression convert(Expression operand, Type fromType,
"to" + SqlFunctions.initcap(toPrimitive.getPrimitiveName()),
operand);
default:
// Generate "Short.parseShort(x)".
// Generate "parseShort(x)".
return Expressions.call(
toPrimitive.getBoxClass(),
"parse" + SqlFunctions.initcap(toPrimitive.getPrimitiveName()),
Expand Down Expand Up @@ -993,7 +993,7 @@ private static class SessionizationEnumerator implements Enumerator<@Nullable Ob
}

@Override public boolean moveNext() {
return initialized ? list.size() > 0 : inputEnumerator.moveNext();
return initialized ? !list.isEmpty() : inputEnumerator.moveNext();
}

@Override public void reset() {
Expand Down Expand Up @@ -1133,7 +1133,7 @@ private static class HopEnumerator implements Enumerator<@Nullable Object[]> {
}

@Override public @Nullable Object[] current() {
if (list.size() > 0) {
if (!list.isEmpty()) {
return takeOne();
} else {
@Nullable Object[] current = inputEnumerator.current();
Expand All @@ -1155,7 +1155,7 @@ private static class HopEnumerator implements Enumerator<@Nullable Object[]> {
}

@Override public boolean moveNext() {
return list.size() > 0 || inputEnumerator.moveNext();
return !list.isEmpty() || inputEnumerator.moveNext();
}

@Override public void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ public static EnumerableAsofJoin create(
return planner.getCostFactory().makeCost(rowCount, 0, 0);
}

/** Generate the function that compares two rows from the right collection on their
* timestamp field.
/** Generates the function that compares two rows from the right collection on
* their timestamp field.
*
* @param rightCollectionType Type of data in right collection.
* @param kind Comparison kind.
* @param timestampFieldIndex Index of the field that is the timestamp field.
*/
private Expression generateTimestampComparator(
private static Expression generateTimestampComparator(
PhysType rightCollectionType, SqlKind kind, int timestampFieldIndex) {
RelFieldCollation.Direction direction;
switch (kind) {
Expand All @@ -159,7 +159,7 @@ private Expression generateTimestampComparator(
return rightCollectionType.generateComparator(collation);
}

/** Extract from a comparison 'call' the index of the field from
/** Extracts from a comparison 'call' the index of the field from
* the inner collection that is used in the comparison. */
private int getTimestampFieldIndex(RexCall call) {
int timestampFieldIndex;
Expand Down
Loading
Loading