Skip to content

Commit

Permalink
Merge branch 'main' into main-SqlLibraryOperators
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaibudiu authored Sep 9, 2024
2 parents 3ef2028 + 67405c3 commit dc0f97c
Show file tree
Hide file tree
Showing 623 changed files with 6,024 additions and 4,627 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.hydromatic.quidem.CommandHandler;
import net.hydromatic.quidem.Quidem;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

Expand Down Expand Up @@ -167,13 +168,11 @@ public static void main(String[] args) throws Exception {
static class ExplainValidatedCommand extends AbstractCommand {
private final ImmutableList<String> lines;
private final ImmutableList<String> content;
private final Set<String> productSet;

ExplainValidatedCommand(List<String> lines, List<String> content,
Set<String> productSet) {
Set<String> unusedProductSet) {
this.lines = ImmutableList.copyOf(lines);
this.content = ImmutableList.copyOf(content);
this.productSet = ImmutableSet.copyOf(productSet);
}

@Override public void execute(Context x, boolean execute) throws Exception {
Expand Down Expand Up @@ -214,7 +213,7 @@ static class ExplainValidatedCommand extends AbstractCommand {
/** Command handler that adds a "!explain-validated-on dialect..." command
* (see {@link ExplainValidatedCommand}). */
private static class BabelCommandHandler implements CommandHandler {
@Override public Command parseCommand(List<String> lines,
@Override public @Nullable Command parseCommand(List<String> lines,
List<String> content, String line) {
final String prefix = "explain-validated-on";
if (line.startsWith(prefix)) {
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 @@ -92,7 +93,8 @@ public CassandraFilter(

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

@Override public CassandraFilter copy(RelTraitSet traitSet, RelNode input,
Expand Down Expand Up @@ -297,7 +299,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 @@ -33,6 +33,8 @@
import java.util.ArrayList;
import java.util.List;

import static java.util.Objects.requireNonNull;

/**
* Implementation of {@link org.apache.calcite.rel.core.Sort}
* relational expression in Cassandra.
Expand All @@ -48,7 +50,7 @@ public CassandraSort(RelOptCluster cluster, RelTraitSet traitSet,

@Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq) {
RelOptCost cost = super.computeSelfCost(planner, mq);
RelOptCost cost = requireNonNull(super.computeSelfCost(planner, mq));
if (!collation.getFieldCollations().isEmpty()) {
return cost.multiplyBy(0.05);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
public class CassandraTable extends AbstractQueryableTable
implements TranslatableTable {
final RelProtoDataType protoRowType;
List<String> partitionKeys;
List<String> clusteringKeys;
List<RelFieldCollation> clusteringOrder;
final List<String> partitionKeys;
final List<String> clusteringKeys;
final List<RelFieldCollation> clusteringOrder;
private final Optional<String> keyspace;
private final String columnFamily;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptCost;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterImpl;
Expand All @@ -46,7 +47,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 All @@ -68,7 +70,8 @@ protected CassandraToEnumerableConverter(

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

@Override public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
Expand Down Expand Up @@ -103,10 +106,12 @@ protected CassandraToEnumerableConverter(
}
final Expression selectFields =
list.append("selectFields", constantArrayList(selectList, Pair.class));
final RelOptTable cassandraTable =
requireNonNull(cassandraImplementor.table);
final Expression table =
list.append("table",
Objects.requireNonNull(
cassandraImplementor.table.getExpression(
requireNonNull(
cassandraTable.getExpression(
CassandraTable.CassandraQueryable.class)));
final Expression predicates =
list.append("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
Loading

0 comments on commit dc0f97c

Please sign in to comment.