Skip to content

Commit

Permalink
core: assertNonNull -> requireNonNull
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Oct 12, 2020
1 parent db9e969 commit 7d80985
Show file tree
Hide file tree
Showing 38 changed files with 170 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
import javax.sql.DataSource;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static java.util.Objects.requireNonNull;

/**
* Implementation of {@link Schema} that is backed by a JDBC data source.
Expand Down Expand Up @@ -106,8 +105,8 @@ public JdbcSchema(DataSource dataSource, SqlDialect dialect,
private JdbcSchema(DataSource dataSource, SqlDialect dialect,
JdbcConvention convention, @Nullable String catalog, @Nullable String schema,
@Nullable ImmutableMap<String, JdbcTable> tableMap) {
this.dataSource = Objects.requireNonNull(dataSource);
this.dialect = Objects.requireNonNull(dialect);
this.dataSource = requireNonNull(dataSource, "dataSource");
this.dialect = requireNonNull(dialect, "dialect");
this.convention = convention;
this.catalog = catalog;
this.schema = schema;
Expand Down Expand Up @@ -381,7 +380,7 @@ RelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName,
new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
while (resultSet.next()) {
final String columnName = assertNonNull(resultSet.getString(4), "columnName");
final String columnName = requireNonNull(resultSet.getString(4), "columnName");
final int dataType = resultSet.getInt(5);
final String typeString = resultSet.getString(6);
final int precision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ private CachingCalciteSchema(@Nullable CalciteSchema parent, Schema schema,
return null;
}

@Override protected CalciteSchema snapshot(@Nullable CalciteSchema parent, SchemaVersion version) {
@Override protected CalciteSchema snapshot(@Nullable CalciteSchema parent,
SchemaVersion version) {
CalciteSchema snapshot = new CachingCalciteSchema(parent,
schema.snapshot(version), name, null, tableMap, latticeMap, typeMap,
functionMap, functionNames, nullaryFunctionMap, getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
import java.util.List;
import java.util.Map;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* API for a service that prepares statements for execution.
*/
Expand Down Expand Up @@ -177,7 +178,9 @@ private static SparkHandler createHandler() {
final Class<?> clazz =
Class.forName("org.apache.calcite.adapter.spark.SparkHandlerImpl");
Method method = clazz.getMethod("instance");
return (CalcitePrepare.SparkHandler) assertNonNull(method.invoke(null));
return (CalcitePrepare.SparkHandler) requireNonNull(
method.invoke(null),
() -> "non-null SparkHandler expected from " + method);
} catch (ClassNotFoundException e) {
return new TrivialSparkHandler();
} catch (IllegalAccessException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ private SimpleCalciteSchema(@Nullable CalciteSchema parent,
return null;
}

@Override protected CalciteSchema snapshot(@Nullable CalciteSchema parent, SchemaVersion version) {
@Override protected CalciteSchema snapshot(@Nullable CalciteSchema parent,
SchemaVersion version) {
CalciteSchema snapshot = new SimpleCalciteSchema(parent,
schema.snapshot(version), name, null, tableMap, latticeMap, typeMap,
functionMap, functionNames, nullaryFunctionMap, getPath());
Expand Down
27 changes: 14 additions & 13 deletions core/src/main/java/org/apache/calcite/materialize/Lattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@
import java.util.function.IntFunction;
import java.util.stream.Collectors;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* Structure that allows materialized views based upon a star schema to be
* recognized and recommended.
Expand All @@ -113,13 +114,13 @@ private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode,
ImmutableSortedSet<Measure> defaultMeasures, ImmutableList<Tile> tiles,
ImmutableListMultimap<Integer, Boolean> columnUses) {
this.rootSchema = rootSchema;
this.rootNode = Objects.requireNonNull(rootNode);
this.columns = Objects.requireNonNull(columns);
this.rootNode = requireNonNull(rootNode);
this.columns = requireNonNull(columns);
this.auto = auto;
this.algorithm = algorithm;
this.algorithmMaxMillis = algorithmMaxMillis;
this.defaultMeasures = defaultMeasures.asList(); // unique and sorted
this.tiles = Objects.requireNonNull(tiles);
this.tiles = requireNonNull(tiles);
this.columnUses = columnUses;

assert isValid(Litmus.THROW);
Expand All @@ -133,7 +134,7 @@ private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode,
this.rowCountEstimate = rowCountEstimate;
@SuppressWarnings("argument.type.incompatible")
LatticeStatisticProvider statisticProvider =
Objects.requireNonNull(statisticProviderFactory.apply(this));
requireNonNull(statisticProviderFactory.apply(this));
this.statisticProvider = statisticProvider;
}

Expand Down Expand Up @@ -387,7 +388,7 @@ public StarTable createStarTable() {
final List<Table> tables = new ArrayList<>();
for (LatticeNode node : rootNode.descendants) {
tables.add(
assertNonNull(
requireNonNull(
node.table.t.unwrap(Table.class),
() -> "can't get table for " + node.table.t));
}
Expand Down Expand Up @@ -562,7 +563,7 @@ public static class Measure implements Comparable<Measure> {

public Measure(SqlAggFunction agg, boolean distinct, @Nullable String name,
Iterable<Column> args) {
this.agg = Objects.requireNonNull(agg);
this.agg = requireNonNull(agg);
this.distinct = distinct;
this.name = name;
this.args = ImmutableList.copyOf(args);
Expand Down Expand Up @@ -658,7 +659,7 @@ public abstract static class Column implements Comparable<Column> {

private Column(int ordinal, String alias) {
this.ordinal = ordinal;
this.alias = Objects.requireNonNull(alias);
this.alias = requireNonNull(alias);
}

/** Converts a list of columns to a bit set of their ordinals. */
Expand Down Expand Up @@ -703,8 +704,8 @@ public static class BaseColumn extends Column {

private BaseColumn(int ordinal, String table, String column, String alias) {
super(ordinal, alias);
this.table = Objects.requireNonNull(table);
this.column = Objects.requireNonNull(column);
this.table = requireNonNull(table);
this.column = requireNonNull(column);
}

@Override public String toString() {
Expand Down Expand Up @@ -799,7 +800,7 @@ public static class Builder {
new LinkedHashMap<>();

public Builder(LatticeSpace space, CalciteSchema schema, String sql) {
this.rootSchema = Objects.requireNonNull(schema.root());
this.rootSchema = requireNonNull(schema.root());
Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema");
CalcitePrepare.ConvertResult parsed =
Schemas.convert(MaterializedViewTable.MATERIALIZATION_CONNECTION,
Expand Down Expand Up @@ -1149,8 +1150,8 @@ public static class Tile {

public Tile(ImmutableList<Measure> measures,
ImmutableList<Column> dimensions) {
this.measures = Objects.requireNonNull(measures);
this.dimensions = Objects.requireNonNull(dimensions);
this.measures = requireNonNull(measures);
this.dimensions = requireNonNull(dimensions);
assert Ordering.natural().isStrictlyOrdered(dimensions);
assert Ordering.natural().isStrictlyOrdered(measures);
bitSet = Column.toBitSet(dimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Objects;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static java.util.Objects.requireNonNull;

/** Source relation of a lattice.
*
Expand All @@ -48,7 +47,7 @@ public abstract class LatticeNode {
* <p>The {@code parent} and {@code mutableNode} arguments are used only
* during construction. */
LatticeNode(LatticeSpace space, @Nullable LatticeNode parent, MutableNode mutableNode) {
this.table = Objects.requireNonNull(mutableNode.table);
this.table = requireNonNull(mutableNode.table);
this.startCol = mutableNode.startCol;
this.endCol = mutableNode.endCol;
this.alias = mutableNode.alias;
Expand All @@ -60,7 +59,7 @@ public abstract class LatticeNode {
if (parent != null) {
sb.append(':');
int i = 0;
for (IntPair p : assertNonNull(mutableNode.step, "mutableNode.step").keys) {
for (IntPair p : requireNonNull(mutableNode.step, "mutableNode.step").keys) {
if (i++ > 0) {
sb.append(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

import com.google.common.collect.ImmutableList;

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

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* A <code>RelSet</code> is an equivalence-set of expressions; that is, a set of
* expressions which have identical semantics. We are generally interested in
Expand Down Expand Up @@ -247,7 +248,7 @@ void addConverters(RelSubset subset, boolean required,
enforcer = new AbstractConverter(
cluster, from, null, to.getTraitSet());
} else {
Convention convention = assertNonNull(
Convention convention = requireNonNull(
subset.getConvention(),
() -> "convention is null for " + subset);
enforcer = convention.enforce(from, to.getTraitSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* Subset of an equivalence class where all relational expressions have the
* same physical properties.
Expand Down Expand Up @@ -447,7 +448,7 @@ void propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq,
// removes parent cached metadata since its input was changed
mq.clearCache(parent);
final RelSubset parentSubset =
assertNonNull(planner.getSubset(parent), "subset not found for " + parent);
requireNonNull(planner.getSubset(parent), "subset not found for " + parent);

// parent subset will clear its cache in propagateCostImprovements0 method itself
for (RelSubset subset : parentSubset.set.subsets) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.Stack;
import java.util.function.Predicate;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static java.util.Objects.requireNonNull;

/**
* A rule driver that apply rules in a Top-Down manner.
Expand Down Expand Up @@ -165,7 +165,7 @@ private void clearProcessed(RelSet set) {
Collection<RelNode> parentRels = subset.getParentRels();
for (RelNode parentRel : parentRels) {
RelSet parentRelSet =
assertNonNull(planner.getSet(parentRel), () -> "no set found for " + parentRel);
requireNonNull(planner.getSet(parentRel), () -> "no set found for " + parentRel);
clearProcessed(parentRelSet);
}
if (subset == planner.root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.util.Pair;

import java.util.ArrayDeque;
import java.util.Deque;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* VolcanoPlanner optimizes queries by transforming expressions selectively
* according to a dynamic programming algorithm.
Expand Down Expand Up @@ -763,7 +764,7 @@ public void setNoneConventionHasInfiniteCost(boolean infinite) {
*/
@API(since = "1.26", status = API.Status.EXPERIMENTAL)
public RelSubset getSubsetNonNull(RelNode rel) {
return assertNonNull(getSubset(rel), () -> "Subset is not found for " + rel);
return requireNonNull(getSubset(rel), () -> "Subset is not found for " + rel);
}

public @Nullable RelSubset getSubset(RelNode rel, RelTraitSet traits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;

/**
* <code>VolcanoRuleCall</code> implements the {@link RelOptRuleCall} interface
* for VolcanoPlanner.
Expand Down Expand Up @@ -313,7 +314,7 @@ private void matchRecurse(int solve) {
final RelSubset subset = volcanoPlanner.getSubsetNonNull(previous);
successors = subset.getParentRels();
} else {
parentOperand = assertNonNull(
parentOperand = requireNonNull(
operand.getParent(),
() -> "operand.getParent() for " + operand);
final RelNode parentRel = rels[parentOperand.ordinalInRule];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import static org.apache.calcite.linq4j.Nullness.assertNonNull;
import static java.util.Objects.requireNonNull;

/**
* Base class for every relational expression ({@link RelNode}).
Expand Down Expand Up @@ -453,7 +453,7 @@ private class InnerRelDigest implements RelDigest {
@Override public String toString() {
RelDigestWriter rdw = new RelDigestWriter();
explain(rdw);
return assertNonNull(rdw.digest);
return requireNonNull(rdw.digest, "digest");
}
}

Expand Down
Loading

0 comments on commit 7d80985

Please sign in to comment.