From 96485c0ec8366d04f08f5c9a72bbee5b47503d6e Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Fri, 16 Feb 2024 21:45:19 -0800 Subject: [PATCH] Cosmetic Require that Preconditions.checkArgument is used via static import; and other changes that do not affect functionality. --- build.gradle.kts | 2 + .../enumerable/EnumerableRelFactories.java | 6 +- .../calcite/adapter/jdbc/JdbcRules.java | 7 ++- .../apache/calcite/interpreter/Bindables.java | 5 +- .../calcite/jdbc/CalciteConnectionImpl.java | 5 +- .../apache/calcite/jdbc/CalcitePrepare.java | 5 +- .../apache/calcite/jdbc/CalciteSchema.java | 5 +- .../apache/calcite/materialize/Lattice.java | 9 +-- .../calcite/materialize/LatticeNode.java | 7 ++- .../materialize/MaterializationActor.java | 5 +- .../apache/calcite/profile/ProfilerImpl.java | 11 ++-- .../apache/calcite/rel/RelCollationImpl.java | 6 +- .../calcite/rel/core/AggregateCall.java | 9 +-- .../org/apache/calcite/rel/core/Match.java | 5 +- .../org/apache/calcite/rel/core/SetOp.java | 5 +- .../apache/calcite/rel/core/TableModify.java | 11 ++-- .../org/apache/calcite/rel/hint/RelHint.java | 11 ++-- .../ReflectiveRelMetadataProvider.java | 5 +- .../calcite/rel/metadata/RelMdUniqueKeys.java | 5 +- .../calcite/rel/metadata/RelMdUtil.java | 7 ++- ...AggregateExpandDistinctAggregatesRule.java | 9 +-- .../calcite/rel/rules/CalcRelSplitter.java | 6 +- .../rel/rules/ProjectToWindowRule.java | 5 +- .../MaterializedViewAggregateRule.java | 5 +- .../org/apache/calcite/rex/RexBuilder.java | 6 +- .../apache/calcite/rex/RexFieldAccess.java | 7 +-- .../org/apache/calcite/rex/RexLiteral.java | 9 +-- .../java/org/apache/calcite/rex/RexOver.java | 6 +- .../org/apache/calcite/rex/RexSubQuery.java | 5 +- .../org/apache/calcite/rex/RexWindow.java | 5 +- .../calcite/runtime/AutomatonBuilder.java | 8 +-- .../calcite/runtime/CalciteException.java | 3 +- .../org/apache/calcite/runtime/Pattern.java | 7 ++- .../org/apache/calcite/schema/Schemas.java | 5 +- .../org/apache/calcite/sql/SqlDialect.java | 7 ++- .../calcite/sql/SqlGroupedWindowFunction.java | 8 ++- .../java/org/apache/calcite/sql/SqlJoin.java | 6 +- .../apache/calcite/sql/SqlMatchRecognize.java | 12 ++-- .../calcite/sql/SqlNullTreatmentOperator.java | 6 +- .../apache/calcite/sql/SqlTimeLiteral.java | 6 +- .../calcite/sql/SqlTimestampLiteral.java | 8 +-- .../calcite/sql/SqlWindowTableFunction.java | 5 +- .../sql/advise/SqlAdvisorValidator.java | 2 +- .../sql/ddl/SqlCreateForeignSchema.java | 5 +- .../calcite/sql/ddl/SqlCreateFunction.java | 8 +-- .../calcite/sql/ddl/SqlCreateTableLike.java | 22 ++++--- .../calcite/sql/dialect/PrestoSqlDialect.java | 5 +- .../sql/fun/SqlAnyValueAggFunction.java | 6 +- .../calcite/sql/fun/SqlAvgAggFunction.java | 4 +- .../calcite/sql/fun/SqlBitOpAggFunction.java | 8 +-- .../calcite/sql/fun/SqlCovarAggFunction.java | 4 +- .../sql/fun/SqlFirstLastValueAggFunction.java | 6 +- .../calcite/sql/fun/SqlFloorFunction.java | 6 +- .../sql/fun/SqlLeadLagAggFunction.java | 5 +- .../apache/calcite/sql/fun/SqlLibrary.java | 6 +- .../calcite/sql/fun/SqlMinMaxAggFunction.java | 6 +- .../calcite/sql/fun/SqlQuantifyOperator.java | 8 +-- .../sql/fun/SqlRegrCountAggFunction.java | 4 +- .../calcite/sql/parser/SqlParserUtil.java | 12 ++-- .../calcite/sql/pretty/SqlPrettyWriter.java | 5 +- .../apache/calcite/sql/type/BasicSqlType.java | 6 +- .../sql/type/MatchReturnTypeInference.java | 7 ++- .../apache/calcite/sql/type/ReturnTypes.java | 7 +-- .../sql/type/SqlOperandCountRanges.java | 6 +- .../sql/type/SqlReturnTypeInferenceChain.java | 5 +- .../sql/type/SqlTypeTransformCascade.java | 5 +- .../apache/calcite/sql/type/SqlTypeUtil.java | 19 +++--- .../sql/validate/AbstractNamespace.java | 24 ++++---- .../sql/validate/DelegatingNamespace.java | 2 +- .../calcite/sql/validate/DelegatingScope.java | 6 +- .../sql/validate/IdentifierNamespace.java | 46 +++++++------- .../calcite/sql/validate/ListScope.java | 4 +- .../calcite/sql/validate/SqlLambdaScope.java | 6 +- .../calcite/sql/validate/SqlQualified.java | 2 +- .../sql/validate/SqlValidatorImpl.java | 60 ++++++++++--------- .../sql/validate/SqlValidatorNamespace.java | 2 +- .../sql/validate/SqlValidatorUtil.java | 11 ++-- .../sql2rel/ReflectiveConvertletTable.java | 7 +-- .../sql2rel/SqlNodeToRexConverterImpl.java | 7 +-- .../sql2rel/StandardConvertletTable.java | 3 +- .../java/org/apache/calcite/tools/Hoist.java | 11 ++-- .../org/apache/calcite/tools/RelBuilder.java | 4 +- .../org/apache/calcite/util/DateString.java | 17 +++--- .../org/apache/calcite/util/JdbcTypeImpl.java | 10 ++-- .../calcite/util/TimeWithTimeZoneString.java | 14 ++--- .../apache/calcite/util/TimestampString.java | 2 +- .../util/TimestampWithTimeZoneString.java | 14 ++--- .../calcite/test/SqlValidatorFeatureTest.java | 19 +++--- .../calcite/adapter/druid/DruidTable.java | 7 ++- .../elasticsearch/ElasticsearchSchema.java | 5 +- .../ElasticsearchSchemaFactory.java | 5 +- .../elasticsearch/PredicateAnalyzer.java | 12 ++-- .../adapter/elasticsearch/Scrolling.java | 7 ++- .../EmbeddedElasticsearchNode.java | 10 ++-- .../adapter/geode/rel/GeodeFilter.java | 7 +-- .../calcite/adapter/geode/rel/GeodeRules.java | 5 +- .../geode/rel/GeodeEmbeddedPolicy.java | 8 +-- .../adapter/innodb/IndexCondition.java | 2 +- .../apache/calcite/linq4j/ModularInteger.java | 6 +- .../apache/calcite/adapter/pig/PigFilter.java | 6 +- .../calcite/adapter/pig/PigRelFactories.java | 5 +- .../adapter/redis/RedisSchemaFactory.java | 12 ++-- .../calcite/server/ServerDdlExecutor.java | 9 +-- .../org/apache/calcite/test/Matchers.java | 4 +- .../calcite/test/RelMetadataFixture.java | 5 +- .../calcite/test/SqlValidatorFixture.java | 6 +- .../test/catalog/MockCatalogReader.java | 20 +++++-- .../calcite/benchmarks/PreconditionTest.java | 6 +- 108 files changed, 461 insertions(+), 409 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0df08ac15c06..3ad31fedacef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -647,6 +647,8 @@ allprojects { replace("hamcrest: startsWith", "org.hamcrest.core.StringStartsWith.startsWith", "org.hamcrest.CoreMatchers.startsWith") replaceRegex("hamcrest: size", "\\.size\\(\\), (is|equalTo)\\(", ", hasSize\\(") replaceRegex("use static import: toImmutableList", "ImmutableList\\.(toImmutableList\\(\\))", "$1") + replaceRegex("use static import: checkArgument", "Preconditions\\.(checkArgument\\()", "$1") + replaceRegex("use static import: checkArgument", "Preconditions\\.(checkState\\()", "$1") custom("((() preventer", 1) { contents: String -> ParenthesisBalancer.apply(contents) } diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelFactories.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelFactories.java index 05c089018985..38adfd50a118 100644 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelFactories.java +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelFactories.java @@ -26,13 +26,13 @@ import org.apache.calcite.rex.RexUtil; import org.apache.calcite.sql.validate.SqlValidatorUtil; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + /** * Contains factory interface and default implementation for creating various * rel nodes. @@ -72,7 +72,7 @@ private static class ProjectFactoryImpl List childExprs, @Nullable List fieldNames, Set variablesSet) { - Preconditions.checkArgument(variablesSet.isEmpty(), + checkArgument(variablesSet.isEmpty(), "EnumerableProject does not allow variables"); final RelDataType rowType = RexUtil.createStructType(input.getCluster().getTypeFactory(), childExprs, diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java index 29b73a3debd4..86503ca49209 100644 --- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java +++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcRules.java @@ -71,7 +71,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.trace.CalciteTrace; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -83,6 +82,8 @@ import java.util.Set; import java.util.function.Consumer; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -98,7 +99,7 @@ private JdbcRules() { static final RelFactories.ProjectFactory PROJECT_FACTORY = (input, hints, projects, fieldNames, variablesSet) -> { - Preconditions.checkArgument(variablesSet.isEmpty(), + checkArgument(variablesSet.isEmpty(), "JdbcProject does not allow variables"); final RelOptCluster cluster = input.getCluster(); final RelDataType rowType = @@ -110,7 +111,7 @@ private JdbcRules() { static final RelFactories.FilterFactory FILTER_FACTORY = (input, condition, variablesSet) -> { - Preconditions.checkArgument(variablesSet.isEmpty(), + checkArgument(variablesSet.isEmpty(), "JdbcFilter does not allow variables"); return new JdbcFilter(input.getCluster(), input.getTraitSet(), input, condition); diff --git a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java index 9f879da917ce..cc52e7c6d8e7 100644 --- a/core/src/main/java/org/apache/calcite/interpreter/Bindables.java +++ b/core/src/main/java/org/apache/calcite/interpreter/Bindables.java @@ -76,7 +76,6 @@ import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.ImmutableIntList; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -89,6 +88,8 @@ import java.util.Set; import java.util.SortedSet; +import static com.google.common.base.Preconditions.checkArgument; + /** * Utilities pertaining to {@link BindableRel} and {@link BindableConvention}. */ @@ -219,7 +220,7 @@ public static class BindableTableScan super(cluster, traitSet, ImmutableList.of(), table); this.filters = Objects.requireNonNull(filters, "filters"); this.projects = Objects.requireNonNull(projects, "projects"); - Preconditions.checkArgument(canHandle(table)); + checkArgument(canHandle(table)); } /** Creates a BindableTableScan. */ diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java index 12fae5457208..073b42565793 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java @@ -68,7 +68,6 @@ import org.apache.calcite.util.Holder; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -88,6 +87,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; import static java.util.Objects.requireNonNull; @@ -148,7 +149,7 @@ protected CalciteConnectionImpl(Driver driver, AvaticaFactory factory, requireNonNull(rootSchema != null ? rootSchema : CalciteSchema.createRootSchema(true)); - Preconditions.checkArgument(this.rootSchema.isRoot(), "must be root schema"); + checkArgument(this.rootSchema.isRoot(), "must be root schema"); this.properties.put(InternalProperty.CASE_SENSITIVE, cfg.caseSensitive()); this.properties.put(InternalProperty.UNQUOTED_CASING, cfg.unquotedCasing()); this.properties.put(InternalProperty.QUOTED_CASING, cfg.quotedCasing()); diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java b/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java index 866cf4293086..bda806be90ea 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java @@ -47,7 +47,6 @@ import org.apache.calcite.util.ImmutableIntList; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -60,6 +59,8 @@ import java.util.List; import java.util.Map; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; import static java.util.Objects.requireNonNull; @@ -312,7 +313,7 @@ public AnalyzeViewResult(CalcitePrepareImpl prepare, this.constraint = constraint; this.columnMapping = columnMapping; this.modifiable = modifiable; - Preconditions.checkArgument(modifiable == (table != null)); + checkArgument(modifiable == (table != null)); } } diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java index 76e1ba39f1c9..418b9e1a6005 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java @@ -34,7 +34,6 @@ import org.apache.calcite.util.NameSet; import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; @@ -49,6 +48,8 @@ import java.util.NavigableSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -441,7 +442,7 @@ public final NavigableMap getTablesBasedOnNullaryFunctions() { * @return the schema snapshot. */ public CalciteSchema createSnapshot(SchemaVersion version) { - Preconditions.checkArgument(this.isRoot(), "must be root schema"); + checkArgument(this.isRoot(), "must be root schema"); return snapshot(null, version); } diff --git a/core/src/main/java/org/apache/calcite/materialize/Lattice.java b/core/src/main/java/org/apache/calcite/materialize/Lattice.java index 596b17769e3f..95ba02c35514 100644 --- a/core/src/main/java/org/apache/calcite/materialize/Lattice.java +++ b/core/src/main/java/org/apache/calcite/materialize/Lattice.java @@ -57,7 +57,6 @@ import org.apache.calcite.util.graph.TopologicalOrderIterator; import org.apache.calcite.util.mapping.IntPair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableSortedSet; @@ -86,6 +85,8 @@ import java.util.function.IntFunction; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; import static java.util.Objects.requireNonNull; @@ -130,7 +131,7 @@ private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode, // [CALCITE-429] Add statistics SPI for lattice optimization algorithm rowCountEstimate = 1000d; } - Preconditions.checkArgument(rowCountEstimate > 0d); + checkArgument(rowCountEstimate > 0d); this.rowCountEstimate = rowCountEstimate; @SuppressWarnings("argument.type.incompatible") LatticeStatisticProvider statisticProvider = @@ -798,7 +799,7 @@ public static class Builder { public Builder(LatticeSpace space, CalciteSchema schema, String sql) { this.rootSchema = requireNonNull(schema.root()); - Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); + checkArgument(rootSchema.isRoot(), "must be root schema"); CalcitePrepare.ConvertResult parsed = Schemas.convert(MaterializedViewTable.MATERIALIZATION_CONNECTION, schema, schema.path(null), sql); @@ -934,7 +935,7 @@ public Lattice build() { LatticeStatisticProvider.Factory.class, this.statisticProvider) : Lattices.CACHED_SQL; - Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); + checkArgument(rootSchema.isRoot(), "must be root schema"); final ImmutableList.Builder columnBuilder = ImmutableList.builder() .addAll(baseColumns) diff --git a/core/src/main/java/org/apache/calcite/materialize/LatticeNode.java b/core/src/main/java/org/apache/calcite/materialize/LatticeNode.java index 1e4e458e457b..6e8225db15fe 100644 --- a/core/src/main/java/org/apache/calcite/materialize/LatticeNode.java +++ b/core/src/main/java/org/apache/calcite/materialize/LatticeNode.java @@ -19,7 +19,6 @@ import org.apache.calcite.plan.RelOptTable; import org.apache.calcite.util.mapping.IntPair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.initialization.qual.Initialized; @@ -27,6 +26,8 @@ import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** Source relation of a lattice. @@ -51,8 +52,8 @@ public abstract class LatticeNode { this.startCol = mutableNode.startCol; this.endCol = mutableNode.endCol; this.alias = mutableNode.alias; - Preconditions.checkArgument(startCol >= 0); - Preconditions.checkArgument(endCol > startCol); + checkArgument(startCol >= 0); + checkArgument(endCol > startCol); final StringBuilder sb = new StringBuilder() .append(space.simpleName(table)); diff --git a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java index e61bee85978a..89a6ea2bf4d9 100644 --- a/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java +++ b/core/src/main/java/org/apache/calcite/materialize/MaterializationActor.java @@ -19,7 +19,6 @@ import org.apache.calcite.jdbc.CalciteSchema; import org.apache.calcite.rel.type.RelDataType; -import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -30,6 +29,8 @@ import java.util.Map; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Actor that manages the state of materializations in the system. */ @@ -78,7 +79,7 @@ static class Materialization { @Nullable List viewSchemaPath) { this.key = key; this.rootSchema = Objects.requireNonNull(rootSchema, "rootSchema"); - Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema"); + checkArgument(rootSchema.isRoot(), "must be root schema"); this.materializedTable = materializedTable; // may be null this.sql = sql; this.rowType = rowType; diff --git a/core/src/main/java/org/apache/calcite/profile/ProfilerImpl.java b/core/src/main/java/org/apache/calcite/profile/ProfilerImpl.java index 0c60f278f11d..b37a30680002 100644 --- a/core/src/main/java/org/apache/calcite/profile/ProfilerImpl.java +++ b/core/src/main/java/org/apache/calcite/profile/ProfilerImpl.java @@ -27,7 +27,6 @@ import org.apache.calcite.util.PartiallyOrderedSet; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; @@ -57,6 +56,8 @@ import java.util.TreeSet; import java.util.function.Predicate; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; import static org.apache.calcite.profile.ProfilerImpl.CompositeCollector.OF; @@ -96,8 +97,8 @@ public static Builder builder() { */ ProfilerImpl(int combinationsPerPass, int interestingCount, Predicate> predicate) { - Preconditions.checkArgument(combinationsPerPass > 2); - Preconditions.checkArgument(interestingCount > 2); + checkArgument(combinationsPerPass > 2); + checkArgument(interestingCount > 2); this.combinationsPerPass = combinationsPerPass; this.interestingCount = interestingCount; this.predicate = predicate; @@ -770,8 +771,8 @@ static class SurpriseQueue { SurpriseQueue(int warmUpCount, int size) { this.warmUpCount = warmUpCount; this.size = size; - Preconditions.checkArgument(warmUpCount > 3); - Preconditions.checkArgument(size > 0); + checkArgument(warmUpCount > 3); + checkArgument(size > 0); } @Override public String toString() { diff --git a/core/src/main/java/org/apache/calcite/rel/RelCollationImpl.java b/core/src/main/java/org/apache/calcite/rel/RelCollationImpl.java index 06433cd57c64..19219f741a10 100644 --- a/core/src/main/java/org/apache/calcite/rel/RelCollationImpl.java +++ b/core/src/main/java/org/apache/calcite/rel/RelCollationImpl.java @@ -26,7 +26,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.UnmodifiableIterator; @@ -35,6 +34,8 @@ import java.util.Iterator; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * Simple implementation of {@link RelCollation}. */ @@ -55,8 +56,7 @@ public class RelCollationImpl implements RelCollation { protected RelCollationImpl(ImmutableList fieldCollations) { this.fieldCollations = fieldCollations; - Preconditions.checkArgument( - Util.isDistinct(RelCollations.ordinals(fieldCollations)), + checkArgument(Util.isDistinct(RelCollations.ordinals(fieldCollations)), "fields must be distinct"); } diff --git a/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java b/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java index fa0d978962fd..aa6ea524ac5f 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java +++ b/core/src/main/java/org/apache/calcite/rel/core/AggregateCall.java @@ -32,7 +32,6 @@ import org.apache.calcite.util.mapping.Mapping; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -40,6 +39,8 @@ import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -121,10 +122,10 @@ private AggregateCall(SqlAggFunction aggFunction, boolean distinct, this.distinct = distinct; this.approximate = approximate; this.ignoreNulls = ignoreNulls; - Preconditions.checkArgument( - aggFunction.getDistinctOptionality() != Optionality.IGNORED || !distinct, + checkArgument(aggFunction.getDistinctOptionality() != Optionality.IGNORED + || !distinct, "DISTINCT has no effect for this aggregate function, so must be false"); - Preconditions.checkArgument(filterArg < 0 || aggFunction.allowsFilter()); + checkArgument(filterArg < 0 || aggFunction.allowsFilter()); } //~ Methods ---------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/core/Match.java b/core/src/main/java/org/apache/calcite/rel/core/Match.java index abdea8e97836..dbfd8c92005a 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/Match.java +++ b/core/src/main/java/org/apache/calcite/rel/core/Match.java @@ -35,7 +35,6 @@ import org.apache.calcite.sql.fun.SqlSumEmptyIsZeroAggFunction; import org.apache.calcite.util.ImmutableBitSet; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedSet; @@ -52,6 +51,8 @@ import java.util.TreeMap; import java.util.TreeSet; +import static com.google.common.base.Preconditions.checkArgument; + /** * Relational expression that represent a MATCH_RECOGNIZE node. * @@ -105,7 +106,7 @@ protected Match(RelOptCluster cluster, RelTraitSet traitSet, RelNode input, super(cluster, traitSet, input); this.rowType = Objects.requireNonNull(rowType, "rowType"); this.pattern = Objects.requireNonNull(pattern, "pattern"); - Preconditions.checkArgument(patternDefinitions.size() > 0); + checkArgument(!patternDefinitions.isEmpty()); this.strictStart = strictStart; this.strictEnd = strictEnd; this.patternDefinitions = ImmutableMap.copyOf(patternDefinitions); diff --git a/core/src/main/java/org/apache/calcite/rel/core/SetOp.java b/core/src/main/java/org/apache/calcite/rel/core/SetOp.java index 1b5d57158d6a..45a3febb3248 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/SetOp.java +++ b/core/src/main/java/org/apache/calcite/rel/core/SetOp.java @@ -30,13 +30,14 @@ import org.apache.calcite.sql.SqlKind; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * SetOp is an abstract base for relational set operators such * as UNION, MINUS (aka EXCEPT), and INTERSECT. @@ -57,7 +58,7 @@ public abstract class SetOp extends AbstractRelNode implements Hintable { protected SetOp(RelOptCluster cluster, RelTraitSet traits, List hints, List inputs, SqlKind kind, boolean all) { super(cluster, traits); - Preconditions.checkArgument(kind == SqlKind.UNION + checkArgument(kind == SqlKind.UNION || kind == SqlKind.INTERSECT || kind == SqlKind.EXCEPT); this.kind = kind; diff --git a/core/src/main/java/org/apache/calcite/rel/core/TableModify.java b/core/src/main/java/org/apache/calcite/rel/core/TableModify.java index 1d57f22a3b42..879052166a98 100644 --- a/core/src/main/java/org/apache/calcite/rel/core/TableModify.java +++ b/core/src/main/java/org/apache/calcite/rel/core/TableModify.java @@ -36,13 +36,13 @@ import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.type.SqlTypeUtil; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -126,15 +126,14 @@ protected TableModify( if (operation == Operation.UPDATE) { requireNonNull(updateColumnList, "updateColumnList"); requireNonNull(sourceExpressionList, "sourceExpressionList"); - Preconditions.checkArgument(sourceExpressionList.size() - == updateColumnList.size()); + checkArgument(sourceExpressionList.size() == updateColumnList.size()); } else { if (operation == Operation.MERGE) { requireNonNull(updateColumnList, "updateColumnList"); } else { - Preconditions.checkArgument(updateColumnList == null); + checkArgument(updateColumnList == null); } - Preconditions.checkArgument(sourceExpressionList == null); + checkArgument(sourceExpressionList == null); } RelOptSchema relOptSchema = table.getRelOptSchema(); if (relOptSchema != null) { diff --git a/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java b/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java index 65ea0a5c0c79..0312d2d138bb 100644 --- a/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java +++ b/core/src/main/java/org/apache/calcite/rel/hint/RelHint.java @@ -16,7 +16,6 @@ */ package org.apache.calcite.rel.hint; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -29,6 +28,8 @@ import java.util.Map; import java.util.Objects; +import static com.google.common.base.Preconditions.checkState; + /** * Hint attached to a relation expression. * @@ -198,7 +199,7 @@ public Builder inheritPath(Integer... inheritPath) { /** Add a hint option as string. */ public Builder hintOption(String hintOption) { Objects.requireNonNull(hintOption, "hintOption"); - Preconditions.checkState(this.kvOptions.size() == 0, + checkState(this.kvOptions.isEmpty(), "List options and key value options can not be mixed in"); this.listOptions.add(hintOption); return this; @@ -207,7 +208,7 @@ public Builder hintOption(String hintOption) { /** Add multiple string hint options. */ public Builder hintOptions(Iterable hintOptions) { Objects.requireNonNull(hintOptions, "hintOptions"); - Preconditions.checkState(this.kvOptions.size() == 0, + checkState(this.kvOptions.isEmpty(), "List options and key value options can not be mixed in"); this.listOptions = ImmutableList.copyOf(hintOptions); return this; @@ -217,7 +218,7 @@ public Builder hintOptions(Iterable hintOptions) { public Builder hintOption(String optionKey, String optionValue) { Objects.requireNonNull(optionKey, "optionKey"); Objects.requireNonNull(optionValue, "optionValue"); - Preconditions.checkState(this.listOptions.size() == 0, + checkState(this.listOptions.isEmpty(), "List options and key value options can not be mixed in"); this.kvOptions.put(optionKey, optionValue); return this; @@ -226,7 +227,7 @@ public Builder hintOption(String optionKey, String optionValue) { /** Add multiple string key-value pair hint options. */ public Builder hintOptions(Map kvOptions) { Objects.requireNonNull(kvOptions, "kvOptions"); - Preconditions.checkState(this.listOptions.size() == 0, + checkState(this.listOptions.isEmpty(), "List options and key value options can not be mixed in"); this.kvOptions = kvOptions; return this; diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java index 14c040017a93..10ed040570af 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/ReflectiveRelMetadataProvider.java @@ -25,7 +25,6 @@ import org.apache.calcite.util.ReflectiveVisitor; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; @@ -46,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.ReflectUtil.isPublic; import static org.apache.calcite.util.ReflectUtil.isStatic; @@ -90,7 +91,7 @@ protected ReflectiveRelMetadataProvider( Class metadataClass0, Multimap> handlerMap, Class> handlerClass) { - Preconditions.checkArgument(!map.isEmpty(), "ReflectiveRelMetadataProvider " + checkArgument(!map.isEmpty(), "ReflectiveRelMetadataProvider " + "methods map is empty; are your methods named wrong?"); this.map = map; this.metadataClass0 = metadataClass0; diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java index 392c431da13c..9e7d84a83851 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java @@ -43,7 +43,6 @@ import org.apache.calcite.util.ImmutableIntList; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; @@ -59,6 +58,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.rel.metadata.RelMdColumnUniqueness.PASSTHROUGH_AGGREGATIONS; import static org.apache.calcite.rel.metadata.RelMdColumnUniqueness.getConstantColumnSet; @@ -386,7 +387,7 @@ private Set filterSupersets(Set uniqueKeys) { * {@link RelMdColumnUniqueness#PASSTHROUGH_AGGREGATIONS pass-through aggregation function}. */ private Set getPassedThroughCols(ImmutableBitSet inputColumns, Aggregate rel) { - Preconditions.checkArgument(Aggregate.isSimple(rel)); + checkArgument(Aggregate.isSimple(rel)); Set conbinations = new HashSet<>(); conbinations.add(ImmutableBitSet.of()); for (Integer inputColumn : inputColumns.asSet()) { diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java index 696daa77db0d..11121db1cff9 100644 --- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java +++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdUtil.java @@ -47,7 +47,6 @@ import org.apache.calcite.util.NumberUtil; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -59,6 +58,8 @@ import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.NumberUtil.multiply; /** @@ -883,8 +884,8 @@ public static double estimateFilteredRows(RelNode child, @Nullable RexNode condi */ public static double linear(int x, int minX, int maxX, double minY, double maxY) { - Preconditions.checkArgument(minX < maxX); - Preconditions.checkArgument(minY < maxY); + checkArgument(minX < maxX); + checkArgument(minY < maxY); if (x < minX) { return minY; } diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java index 41e979c239a9..7a00db8d72cf 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java @@ -43,7 +43,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -65,6 +64,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import static java.util.Objects.requireNonNull; /** @@ -161,8 +163,7 @@ public AggregateExpandDistinctAggregatesRule( .map(aggCall -> Pair.of(aggCall.getArgList(), aggCall.filterArg)) .collect(Collectors.toCollection(LinkedHashSet::new)); - Preconditions.checkState(distinctCallArgLists.size() > 0, - "containsDistinctCall lied"); + checkState(!distinctCallArgLists.isEmpty(), "containsDistinctCall lied"); // If all of the agg expressions are distinct and have the same // arguments then we can use a more efficient form. @@ -282,7 +283,7 @@ private static RelBuilder convertSingletonDistinct(RelBuilder relBuilder, // In this case, we are assuming that there is a single distinct function. // So make sure that argLists is of size one. - Preconditions.checkArgument(argLists.size() == 1); + checkArgument(argLists.size() == 1); // For example, // SELECT deptno, COUNT(*), SUM(bonus), MIN(DISTINCT sal) diff --git a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java index b5bbe403c290..2e7699a89df6 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java @@ -43,7 +43,6 @@ import org.apache.calcite.util.graph.DirectedGraph; import org.apache.calcite.util.graph.TopologicalOrderIterator; -import com.google.common.base.Preconditions; import com.google.common.primitives.Ints; import org.checkerframework.checker.nullness.qual.Nullable; @@ -57,6 +56,8 @@ import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + /** * CalcRelSplitter operates on a * {@link org.apache.calcite.rel.core.Calc} with multiple {@link RexCall} @@ -242,8 +243,7 @@ RelNode execute() { inputExprOrdinals = projectExprOrdinals; } - Preconditions.checkArgument(doneCondition || (conditionRef == null), - "unhandled condition"); + checkArgument(doneCondition || conditionRef == null, "unhandled condition"); return rel; } diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java index f97584b36487..303a57fce664 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java @@ -45,7 +45,6 @@ import org.apache.calcite.util.graph.DirectedGraph; import org.apache.calcite.util.graph.TopologicalOrderIterator; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.immutables.value.Value; @@ -57,6 +56,8 @@ import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + /** * Planner rule that slices a * {@link org.apache.calcite.rel.core.Project} @@ -255,7 +256,7 @@ static class WindowedAggRelSplitter extends CalcRelSplitter { @Override protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { - Preconditions.checkArgument(program.getCondition() == null, + checkArgument(program.getCondition() == null, "WindowedAggregateRel cannot accept a condition"); return LogicalWindow.create(cluster, traitSet, relBuilder, input, program); diff --git a/core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java b/core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java index 225055e5129c..289c088a8f82 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewAggregateRule.java @@ -58,7 +58,6 @@ import org.apache.calcite.util.mapping.MappingType; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableList; @@ -77,6 +76,8 @@ import java.util.Map; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** Materialized view rewriting for aggregate. @@ -751,7 +752,7 @@ private static int find(RelNode rel, int ref) { BiMap tableMapping, EquivalenceClasses sourceEC, List additionalExprs) { - Preconditions.checkArgument(additionalExprs.isEmpty()); + checkArgument(additionalExprs.isEmpty()); Multimap m = ArrayListMultimap.create(); Map> equivalenceClassesMap = sourceEC.getEquivalenceClassesMap(); diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java index 69149c167949..dab524f5ee55 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java +++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java @@ -51,7 +51,6 @@ import org.apache.calcite.util.TimestampString; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableRangeSet; import com.google.common.collect.Range; @@ -76,6 +75,7 @@ import java.util.function.IntPredicate; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Verify.verifyNotNull; import static com.google.common.collect.ImmutableList.toImmutableList; @@ -351,7 +351,7 @@ public RexNode addAggCall(AggregateCall aggCall, int groupCount, boolean indicator, List aggCalls, Map aggCallMapping, final @Nullable List aggArgTypes) { - Preconditions.checkArgument(!indicator, + checkArgument(!indicator, "indicator is deprecated, use GROUPING function instead"); return addAggCall(aggCall, groupCount, aggCalls, aggCallMapping, aggArgTypes); @@ -422,7 +422,7 @@ public RexNode makeOver( makeNullLiteral(type)); } if (!allowPartial) { - Preconditions.checkArgument(rows, "DISALLOW PARTIAL over RANGE"); + checkArgument(rows, "DISALLOW PARTIAL over RANGE"); final RelDataType bigintType = typeFactory.createSqlType(SqlTypeName.BIGINT); // todo: read bound diff --git a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java index 0f09672f38dd..9b7439a203a9 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java +++ b/core/src/main/java/org/apache/calcite/rex/RexFieldAccess.java @@ -20,10 +20,10 @@ import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.sql.SqlKind; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Access to a field of a row-expression. * @@ -72,8 +72,7 @@ public class RexFieldAccess extends RexNode { private static void checkValid(RexNode expr, RelDataTypeField field) { RelDataType exprType = expr.getType(); int fieldIdx = field.getIndex(); - Preconditions.checkArgument( - fieldIdx >= 0 && fieldIdx < exprType.getFieldList().size() + checkArgument(fieldIdx >= 0 && fieldIdx < exprType.getFieldList().size() && exprType.getFieldList().get(fieldIdx).equals(field), "Field %s does not exist for expression %s", field, expr); } diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java index 4bf9073082bf..30f03669ed44 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java +++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java @@ -42,7 +42,6 @@ import org.apache.calcite.util.TimestampString; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.initialization.qual.UnknownInitialization; @@ -64,6 +63,8 @@ import java.util.Objects; import java.util.TimeZone; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; import static org.apache.calcite.rel.type.RelDataTypeImpl.NON_NULLABLE_SUFFIX; @@ -228,9 +229,9 @@ public class RexLiteral extends RexNode { this.value = value; this.type = requireNonNull(type, "type"); this.typeName = requireNonNull(typeName, "typeName"); - Preconditions.checkArgument(valueMatchesType(value, typeName, true)); - Preconditions.checkArgument((value == null) == type.isNullable()); - Preconditions.checkArgument(typeName != SqlTypeName.ANY); + checkArgument(valueMatchesType(value, typeName, true)); + checkArgument((value == null) == type.isNullable()); + checkArgument(typeName != SqlTypeName.ANY); this.digest = computeDigest(RexDigestIncludeType.OPTIONAL); } diff --git a/core/src/main/java/org/apache/calcite/rex/RexOver.java b/core/src/main/java/org/apache/calcite/rex/RexOver.java index b93d94a83736..792beae6a5ee 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexOver.java +++ b/core/src/main/java/org/apache/calcite/rex/RexOver.java @@ -22,13 +22,13 @@ import org.apache.calcite.util.ControlFlowException; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Call to an aggregate function over a window. */ @@ -70,7 +70,7 @@ public class RexOver extends RexCall { boolean distinct, boolean ignoreNulls) { super(type, op, operands); - Preconditions.checkArgument(op.isAggregator()); + checkArgument(op.isAggregator()); this.window = Objects.requireNonNull(window, "window"); this.distinct = distinct; this.ignoreNulls = ignoreNulls; diff --git a/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java b/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java index 609a4a5a0166..61d10174f8f3 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java @@ -28,7 +28,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.type.SqlTypeUtil; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -36,6 +35,8 @@ import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Scalar expression that represents an IN, EXISTS or scalar sub-query. */ @@ -146,7 +147,7 @@ public static RexSubQuery multiset(RelNode rel) { public static RexSubQuery map(RelNode rel) { final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory(); final RelDataType rowType = rel.getRowType(); - Preconditions.checkArgument(rowType.getFieldCount() == 2, + checkArgument(rowType.getFieldCount() == 2, "MAP requires exactly two fields, got %s; row type %s", rowType.getFieldCount(), rowType); final List fieldList = rowType.getFieldList(); diff --git a/core/src/main/java/org/apache/calcite/rex/RexWindow.java b/core/src/main/java/org/apache/calcite/rex/RexWindow.java index 260716918185..ecf5391163d2 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexWindow.java +++ b/core/src/main/java/org/apache/calcite/rex/RexWindow.java @@ -18,7 +18,6 @@ import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -26,6 +25,8 @@ import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Specification of the window of rows over which a {@link RexOver} windowed * aggregate is evaluated. @@ -83,7 +84,7 @@ public class RexWindow { this.isRows = isRows; this.nodeCount = computeCodeCount(); this.digest = computeDigest(); - Preconditions.checkArgument( + checkArgument( !(lowerBound.isUnbounded() && lowerBound.isPreceding() && upperBound.isUnbounded() && upperBound.isFollowing() && isRows), "use RANGE for unbounded, not ROWS"); diff --git a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java index 0d9a686c53f0..2785321b05d0 100644 --- a/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java +++ b/core/src/main/java/org/apache/calcite/runtime/AutomatonBuilder.java @@ -21,7 +21,6 @@ import org.apache.calcite.runtime.Automaton.SymbolTransition; import org.apache.calcite.runtime.Automaton.Transition; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -31,6 +30,7 @@ import java.util.Map; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.toImmutableList; /** Builds a state-transition graph for deterministic finite automaton. */ @@ -210,9 +210,9 @@ AutomatonBuilder repeat(State fromState, State toState, Pattern pattern, // fromState ---> state0 ---> state1 ---> state2 ---> state3 ---> toState // e pattern pattern pattern e // - Preconditions.checkArgument(0 <= minRepeat); - Preconditions.checkArgument(minRepeat <= maxRepeat); - Preconditions.checkArgument(1 <= maxRepeat); + checkArgument(0 <= minRepeat); + checkArgument(minRepeat <= maxRepeat); + checkArgument(1 <= maxRepeat); State prevState = fromState; for (int i = 0; i <= maxRepeat; i++) { final State s = createState(); diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteException.java b/core/src/main/java/org/apache/calcite/runtime/CalciteException.java index 73a55c5de6ab..fb491b9f0c2a 100644 --- a/core/src/main/java/org/apache/calcite/runtime/CalciteException.java +++ b/core/src/main/java/org/apache/calcite/runtime/CalciteException.java @@ -18,6 +18,7 @@ import org.apache.calcite.config.CalciteSystemProperty; +import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +56,7 @@ public class CalciteException extends RuntimeException { @SuppressWarnings({"argument.type.incompatible", "method.invocation.invalid"}) public CalciteException( String message, - Throwable cause) { + @Nullable Throwable cause) { super(message, cause); // TODO: Force the caller to pass in a Logger as a trace argument for diff --git a/core/src/main/java/org/apache/calcite/runtime/Pattern.java b/core/src/main/java/org/apache/calcite/runtime/Pattern.java index 48d430825fb2..370eb02d6de7 100644 --- a/core/src/main/java/org/apache/calcite/runtime/Pattern.java +++ b/core/src/main/java/org/apache/calcite/runtime/Pattern.java @@ -16,13 +16,14 @@ */ package org.apache.calcite.runtime; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.Objects; import java.util.Stack; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + /** Regular expression, to be compiled into an {@link Automaton}. */ public interface Pattern { default Automaton toAutomaton() { @@ -181,8 +182,8 @@ class OpPattern extends AbstractPattern { OpPattern(Op op, Pattern... patterns) { super(op); - Preconditions.checkArgument(patterns.length >= op.minArity); - Preconditions.checkArgument(op.maxArity == -1 + checkArgument(patterns.length >= op.minArity); + checkArgument(op.maxArity == -1 || patterns.length <= op.maxArity); this.patterns = ImmutableList.copyOf(patterns); } diff --git a/core/src/main/java/org/apache/calcite/schema/Schemas.java b/core/src/main/java/org/apache/calcite/schema/Schemas.java index 4795473729db..1fafb231237d 100644 --- a/core/src/main/java/org/apache/calcite/schema/Schemas.java +++ b/core/src/main/java/org/apache/calcite/schema/Schemas.java @@ -44,7 +44,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -60,6 +59,8 @@ import java.util.List; import java.util.Map; +import static com.google.common.base.Preconditions.checkState; + import static org.apache.calcite.jdbc.CalciteSchema.LatticeEntry; import static java.util.Objects.requireNonNull; @@ -567,7 +568,7 @@ public static Path path(CalciteSchema rootSchema, Iterable names) { if (!rootSchema.name.isEmpty()) { // If path starts with the name of the root schema, ignore the first step // in the path. - Preconditions.checkState(rootSchema.name.equals(iterator.next())); + checkState(rootSchema.name.equals(iterator.next())); } for (;;) { final String name = iterator.next(); diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java index 30c912dcb8df..845d351cd548 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java @@ -43,7 +43,6 @@ import org.apache.calcite.util.format.FormatModel; import org.apache.calcite.util.format.FormatModels; -import com.google.common.base.Preconditions; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; @@ -61,6 +60,8 @@ import java.util.Set; import java.util.function.Supplier; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.DateTimeStringUtils.getDateFormatter; import static java.util.Objects.requireNonNull; @@ -997,7 +998,7 @@ public void unparseTopN(SqlWriter writer, @Nullable SqlNode offset, @Nullable Sq * fetch ROWS ONLY" syntax. */ protected static void unparseFetchUsingAnsi(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) { - Preconditions.checkArgument(fetch != null || offset != null); + checkArgument(fetch != null || offset != null); if (offset != null) { writer.newlineAndIndent(); final SqlWriter.Frame offsetFrame = @@ -1023,7 +1024,7 @@ protected static void unparseFetchUsingAnsi(SqlWriter writer, @Nullable SqlNode /** Unparses offset/fetch using "LIMIT fetch OFFSET offset" syntax. */ protected static void unparseFetchUsingLimit(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) { - Preconditions.checkArgument(fetch != null || offset != null); + checkArgument(fetch != null || offset != null); unparseLimit(writer, fetch); unparseOffset(writer, offset); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java index e7b9a3a6d689..2a9192595c97 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlGroupedWindowFunction.java @@ -22,13 +22,14 @@ import org.apache.calcite.sql.type.SqlReturnTypeInference; import org.apache.calcite.sql.validate.SqlMonotonicity; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * SQL function that computes keys by which rows can be partitioned and * aggregated. @@ -66,11 +67,12 @@ public SqlGroupedWindowFunction(String name, SqlKind kind, @Nullable SqlGroupedWindowFunction groupFunction, SqlReturnTypeInference returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, - @Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory category) { + @Nullable SqlOperandTypeChecker operandTypeChecker, + SqlFunctionCategory category) { super(name, kind, returnTypeInference, operandTypeInference, operandTypeChecker, category); this.groupFunction = groupFunction; - Preconditions.checkArgument(groupFunction == null + checkArgument(groupFunction == null || groupFunction.groupFunction == null); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java index 75706adaa1f6..ab08f2d1c9cd 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java @@ -22,13 +22,13 @@ import org.apache.calcite.util.ImmutableNullableList; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.function.UnaryOperator; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -75,7 +75,7 @@ public SqlJoin(SqlParserPos pos, SqlNode left, SqlLiteral natural, this.conditionType = requireNonNull(conditionType, "conditionType"); this.condition = condition; - Preconditions.checkArgument(natural.getTypeName() == SqlTypeName.BOOLEAN); + checkArgument(natural.getTypeName() == SqlTypeName.BOOLEAN); conditionType.getValueAs(JoinConditionType.class); joinType.getValueAs(JoinType.class); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java b/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java index 970539d132f5..24de92d989e8 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlMatchRecognize.java @@ -23,13 +23,13 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.ImmutableNullableList; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * SqlNode for MATCH_RECOGNIZE clause. */ @@ -82,11 +82,11 @@ public SqlMatchRecognize(SqlParserPos pos, SqlNode tableRef, SqlNode pattern, this.strictStart = strictStart; this.strictEnd = strictEnd; this.patternDefList = Objects.requireNonNull(patternDefList, "patternDefList"); - Preconditions.checkArgument(patternDefList.size() > 0); + checkArgument(!patternDefList.isEmpty()); this.measureList = Objects.requireNonNull(measureList, "measureList"); this.after = after; this.subsetList = subsetList; - Preconditions.checkArgument(rowsPerMatch == null + checkArgument(rowsPerMatch == null || rowsPerMatch.value instanceof RowsPerMatchOption); this.rowsPerMatch = rowsPerMatch; this.partitionList = Objects.requireNonNull(partitionList, "partitionList"); @@ -137,7 +137,7 @@ public SqlMatchRecognize(SqlParserPos pos, SqlNode tableRef, SqlNode pattern, break; case OPERAND_PATTERN_DEFINES: patternDefList = Objects.requireNonNull((SqlNodeList) operand); - Preconditions.checkArgument(patternDefList.size() > 0); + checkArgument(!patternDefList.isEmpty()); break; case OPERAND_MEASURES: measureList = Objects.requireNonNull((SqlNodeList) operand); @@ -150,7 +150,7 @@ public SqlMatchRecognize(SqlParserPos pos, SqlNode tableRef, SqlNode pattern, break; case OPERAND_ROWS_PER_MATCH: rowsPerMatch = (SqlLiteral) operand; - Preconditions.checkArgument(rowsPerMatch == null + checkArgument(rowsPerMatch == null || rowsPerMatch.value instanceof RowsPerMatchOption); break; case OPERAND_PARTITION_BY: diff --git a/core/src/main/java/org/apache/calcite/sql/SqlNullTreatmentOperator.java b/core/src/main/java/org/apache/calcite/sql/SqlNullTreatmentOperator.java index 590aac2ec923..28ad44956c38 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlNullTreatmentOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlNullTreatmentOperator.java @@ -23,10 +23,10 @@ import org.apache.calcite.sql.validate.SqlValidatorScope; import org.apache.calcite.util.ImmutableNullableList; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; /** @@ -41,7 +41,7 @@ public class SqlNullTreatmentOperator extends SqlSpecialOperator { public SqlNullTreatmentOperator(SqlKind kind) { super(kind.sql, kind, 20, true, ReturnTypes.ARG0, null, OperandTypes.ANY); - Preconditions.checkArgument(kind == SqlKind.RESPECT_NULLS + checkArgument(kind == SqlKind.RESPECT_NULLS || kind == SqlKind.IGNORE_NULLS); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java index b1ff7af7fa03..953ca8611f22 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlTimeLiteral.java @@ -20,10 +20,10 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.TimeString; -import com.google.common.base.Preconditions; - import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * A SQL literal representing a TIME value, for example TIME * '14:33:44.567'. @@ -36,7 +36,7 @@ public class SqlTimeLiteral extends SqlAbstractDateTimeLiteral { SqlTimeLiteral(TimeString t, int precision, boolean hasTimeZone, SqlParserPos pos) { super(t, hasTimeZone, SqlTypeName.TIME, precision, pos); - Preconditions.checkArgument(this.precision >= 0); + checkArgument(this.precision >= 0); } //~ Methods ---------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java index ac169cad3004..d70b677279fc 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlTimestampLiteral.java @@ -20,10 +20,10 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.TimestampString; -import com.google.common.base.Preconditions; - import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * A SQL literal representing a TIMESTAMP value, for example TIMESTAMP * '1969-07-21 03:15 GMT'. @@ -36,8 +36,8 @@ public class SqlTimestampLiteral extends SqlAbstractDateTimeLiteral { SqlTimestampLiteral(TimestampString ts, int precision, SqlTypeName typeName, SqlParserPos pos) { super(ts, false, typeName, precision, pos); - Preconditions.checkArgument(this.precision >= 0); - Preconditions.checkArgument(typeName == SqlTypeName.TIMESTAMP + checkArgument(this.precision >= 0); + checkArgument(typeName == SqlTypeName.TIMESTAMP || typeName == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE); } diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java index f826fdce09b2..6decf5b11939 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlWindowTableFunction.java @@ -29,7 +29,6 @@ import org.apache.calcite.sql.validate.SqlNameMatcher; import org.apache.calcite.sql.validate.SqlValidator; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -37,6 +36,8 @@ import java.util.Collections; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; /** @@ -124,7 +125,7 @@ protected abstract static class AbstractOperandMetadata int mandatoryParamCount) { this.paramNames = ImmutableList.copyOf(paramNames); this.mandatoryParamCount = mandatoryParamCount; - Preconditions.checkArgument(mandatoryParamCount >= 0 + checkArgument(mandatoryParamCount >= 0 && mandatoryParamCount <= paramNames.size()); } diff --git a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisorValidator.java b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisorValidator.java index a4d157fd7ddf..ddcfe9a6a9b6 100644 --- a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisorValidator.java +++ b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisorValidator.java @@ -185,7 +185,7 @@ private void registerId(SqlIdentifier id, SqlValidatorScope scope) { @Override protected void validateNamespace(final SqlValidatorNamespace namespace, RelDataType targetRowType) { - // Only attempt to validate each namespace once. Otherwise if + // Only attempt to validate each namespace once. Otherwise, if // validation fails, we may end up cycling. if (activeNamespaces.add(namespace)) { super.validateNamespace(namespace, targetRowType); diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java index 38b4d85c672b..4612918174aa 100644 --- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java +++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateForeignSchema.java @@ -28,7 +28,6 @@ import org.apache.calcite.util.ImmutableNullableList; import org.apache.calcite.util.Pair; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -37,6 +36,8 @@ import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNull; /** @@ -60,7 +61,7 @@ public class SqlCreateForeignSchema extends SqlCreate { this.name = Objects.requireNonNull(name, "name"); this.type = type; this.library = library; - Preconditions.checkArgument((type == null) != (library == null), + checkArgument((type == null) != (library == null), "of type and library, exactly one must be specified"); this.optionList = optionList; // may be null } diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java index 245236f658ed..739518755461 100644 --- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateFunction.java @@ -29,12 +29,12 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import java.util.Arrays; import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Parse tree for {@code CREATE FUNCTION} statement. */ @@ -54,7 +54,7 @@ public SqlCreateFunction(SqlParserPos pos, boolean replace, this.name = Objects.requireNonNull(name, "name"); this.className = className; this.usingList = Objects.requireNonNull(usingList, "usingList"); - Preconditions.checkArgument(usingList.size() % 2 == 0); + checkArgument(usingList.size() % 2 == 0); } @Override public void unparse(SqlWriter writer, int leftPrec, @@ -67,7 +67,7 @@ public SqlCreateFunction(SqlParserPos pos, boolean replace, name.unparse(writer, 0, 0); writer.keyword("AS"); className.unparse(writer, 0, 0); - if (usingList.size() > 0) { + if (!usingList.isEmpty()) { writer.keyword("USING"); final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.SIMPLE); diff --git a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTableLike.java b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTableLike.java index c291de2fe3e9..957f87531dd4 100644 --- a/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTableLike.java +++ b/core/src/main/java/org/apache/calcite/sql/ddl/SqlCreateTableLike.java @@ -29,13 +29,13 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.util.ImmutableNullableList; -import com.google.common.base.Preconditions; - import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + /** * Parse tree for {@code CREATE TABLE LIKE} statement. */ @@ -69,24 +69,22 @@ public SqlCreateTableLike(SqlParserPos pos, boolean replace, boolean ifNotExists // validate like options if (includingOptions.contains(LikeOption.ALL.symbol(SqlParserPos.ZERO))) { - Preconditions.checkArgument( - includingOptions.size() == 1 && excludingOptions.isEmpty(), + checkArgument(includingOptions.size() == 1 && excludingOptions.isEmpty(), "ALL cannot be used with other options"); } else if (excludingOptions.contains(LikeOption.ALL.symbol(SqlParserPos.ZERO))) { - Preconditions.checkArgument( - excludingOptions.size() == 1 && includingOptions.isEmpty(), + checkArgument(excludingOptions.size() == 1 && includingOptions.isEmpty(), "ALL cannot be used with other options"); } - includingOptions.forEach(option -> { - Preconditions.checkArgument( - !excludingOptions.contains(option), - "Cannot include and exclude option %s at same time", option.toString()); - }); + includingOptions.forEach(option -> + checkArgument(!excludingOptions.contains(option), + "Cannot include and exclude option %s at same time", + option.toString())); } @Override public List getOperandList() { - return ImmutableNullableList.of(name, sourceTable, includingOptions, excludingOptions); + return ImmutableNullableList.of(name, sourceTable, includingOptions, + excludingOptions); } public Set options() { diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java index ddf2a10f6ff6..d96b8987840c 100644 --- a/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java +++ b/core/src/main/java/org/apache/calcite/sql/dialect/PrestoSqlDialect.java @@ -34,7 +34,6 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.util.RelToSqlConverterUtil; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -42,6 +41,8 @@ import java.util.ArrayList; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * A SqlDialect implementation for the Presto database. */ @@ -85,7 +86,7 @@ public PrestoSqlDialect(Context context) { /** Unparses offset/fetch using "OFFSET offset LIMIT fetch " syntax. */ private static void unparseUsingLimit(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) { - Preconditions.checkArgument(fetch != null || offset != null); + checkArgument(fetch != null || offset != null); unparseOffset(writer, offset); unparseLimit(writer, fetch); } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlAnyValueAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlAnyValueAggFunction.java index 4117a84e2e72..f83e4f129fd1 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlAnyValueAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlAnyValueAggFunction.java @@ -24,10 +24,10 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Definition of the ANY_VALUE aggregate functions, * returning any one of the values which go into it. @@ -50,7 +50,7 @@ public SqlAnyValueAggFunction(SqlKind kind) { false, false, Optionality.FORBIDDEN); - Preconditions.checkArgument(kind == SqlKind.ANY_VALUE); + checkArgument(kind == SqlKind.ANY_VALUE); } //~ Methods ---------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlAvgAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlAvgAggFunction.java index 35e01637293b..97358c8dc496 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlAvgAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlAvgAggFunction.java @@ -24,7 +24,7 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; /** * Avg is an aggregator which returns the average of the values @@ -54,7 +54,7 @@ public SqlAvgAggFunction(SqlKind kind) { false, false, Optionality.FORBIDDEN); - Preconditions.checkArgument(SqlKind.AVG_AGG_FUNCTIONS.contains(kind), + checkArgument(SqlKind.AVG_AGG_FUNCTIONS.contains(kind), "unsupported sql kind"); } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlBitOpAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlBitOpAggFunction.java index 808724d02d11..2f60a1185979 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlBitOpAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlBitOpAggFunction.java @@ -24,10 +24,10 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Definition of the BIT_AND and BIT_OR aggregate functions, * returning the bitwise AND/OR of all non-null input values, or null if none. @@ -51,7 +51,7 @@ public SqlBitOpAggFunction(SqlKind kind) { false, false, Optionality.FORBIDDEN); - Preconditions.checkArgument(kind == SqlKind.BIT_AND + checkArgument(kind == SqlKind.BIT_AND || kind == SqlKind.BIT_OR || kind == SqlKind.BIT_XOR); } @@ -68,7 +68,7 @@ public SqlBitOpAggFunction(String name, SqlKind kind) { false, false, Optionality.FORBIDDEN); - Preconditions.checkArgument(kind == SqlKind.BIT_AND + checkArgument(kind == SqlKind.BIT_AND || kind == SqlKind.BIT_OR || kind == SqlKind.BIT_XOR); } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlCovarAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlCovarAggFunction.java index 446a2901dcae..6486e47ecdec 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlCovarAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlCovarAggFunction.java @@ -24,7 +24,7 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; /** * Covar is an aggregator which returns the Covariance of the @@ -51,7 +51,7 @@ public SqlCovarAggFunction(SqlKind kind) { false, false, Optionality.FORBIDDEN); - Preconditions.checkArgument(SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(kind), + checkArgument(SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(kind), "unsupported sql kind: " + kind); } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java index 100639ca4a41..8630ccc49dfa 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlFirstLastValueAggFunction.java @@ -26,11 +26,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * FIRST_VALUE and LAST_VALUE aggregate functions * return the first or the last value in a list of values that are input to the @@ -51,8 +52,7 @@ public SqlFirstLastValueAggFunction(SqlKind kind) { false, true, Optionality.FORBIDDEN); - Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE - || kind == SqlKind.LAST_VALUE); + checkArgument(kind == SqlKind.FIRST_VALUE || kind == SqlKind.LAST_VALUE); } @Deprecated // to be removed before 2.0 diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlFloorFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlFloorFunction.java index 77321bc0fe07..784cf4d22734 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlFloorFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlFloorFunction.java @@ -37,10 +37,10 @@ import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorScope; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Definition of the "FLOOR" and "CEIL" built-in SQL functions. */ @@ -62,7 +62,7 @@ public SqlFloorFunction(SqlKind kind) { OperandTypes.DATETIME, OperandTypes.ANY)), SqlFunctionCategory.NUMERIC); - Preconditions.checkArgument(kind == SqlKind.FLOOR || kind == SqlKind.CEIL); + checkArgument(kind == SqlKind.FLOOR || kind == SqlKind.CEIL); } public SqlFloorFunction withName(String name) { diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLeadLagAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLeadLagAggFunction.java index 9a15d545454f..63b9dc14b1b2 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLeadLagAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLeadLagAggFunction.java @@ -29,7 +29,7 @@ import org.apache.calcite.sql.type.SqlTypeTransforms; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; /** * LEAD and LAG aggregate functions @@ -56,8 +56,7 @@ public SqlLeadLagAggFunction(SqlKind kind) { false, true, Optionality.FORBIDDEN); - Preconditions.checkArgument(kind == SqlKind.LEAD - || kind == SqlKind.LAG); + checkArgument(kind == SqlKind.LEAD || kind == SqlKind.LAG); } @Deprecated // to be removed before 2.0 diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibrary.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibrary.java index 3f95150608bc..164e7cbb98d5 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibrary.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibrary.java @@ -18,7 +18,6 @@ import org.apache.calcite.config.CalciteConnectionProperty; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -30,6 +29,8 @@ import java.util.Map; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -90,8 +91,7 @@ public enum SqlLibrary { SqlLibrary(String abbrev, String fun) { this.abbrev = requireNonNull(abbrev, "abbrev"); this.fun = requireNonNull(fun, "fun"); - Preconditions.checkArgument( - fun.equals(name().toLowerCase(Locale.ROOT).replace("_", ""))); + checkArgument(fun.equals(name().toLowerCase(Locale.ROOT).replace("_", ""))); } @SuppressWarnings("SwitchStatementWithTooFewBranches") diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java index 5750b2bed6e3..2196a3647c2d 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlMinMaxAggFunction.java @@ -27,13 +27,14 @@ import org.apache.calcite.sql.type.SqlOperandTypeChecker; import org.apache.calcite.util.Optionality; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * Definition of the MIN and MAX aggregate functions, * returning the returns the smallest/largest of the values which go into it. @@ -89,8 +90,7 @@ public SqlMinMaxAggFunction(String funcName, SqlKind kind, Optionality.FORBIDDEN); this.argTypes = ImmutableList.of(); this.minMaxKind = MINMAX_COMPARABLE; - Preconditions.checkArgument(kind == SqlKind.MIN - || kind == SqlKind.MAX); + checkArgument(kind == SqlKind.MIN || kind == SqlKind.MAX); } @Deprecated // to be removed before 2.0 diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java index f259627fe647..1ba3f599c4af 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlQuantifyOperator.java @@ -26,13 +26,13 @@ import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.sql.validate.SqlValidatorScope; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Definition of the SQL ALL and SOMEoperators. * @@ -61,13 +61,13 @@ public class SqlQuantifyOperator extends SqlInOperator { SqlQuantifyOperator(SqlKind kind, SqlKind comparisonKind) { super(comparisonKind.sql + " " + kind, kind); this.comparisonKind = Objects.requireNonNull(comparisonKind, "comparisonKind"); - Preconditions.checkArgument(comparisonKind == SqlKind.EQUALS + checkArgument(comparisonKind == SqlKind.EQUALS || comparisonKind == SqlKind.NOT_EQUALS || comparisonKind == SqlKind.LESS_THAN_OR_EQUAL || comparisonKind == SqlKind.LESS_THAN || comparisonKind == SqlKind.GREATER_THAN_OR_EQUAL || comparisonKind == SqlKind.GREATER_THAN); - Preconditions.checkArgument(kind == SqlKind.SOME + checkArgument(kind == SqlKind.SOME || kind == SqlKind.ALL); } diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlRegrCountAggFunction.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlRegrCountAggFunction.java index 3e74da0cc96c..28023ed83d29 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlRegrCountAggFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlRegrCountAggFunction.java @@ -19,7 +19,7 @@ import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.type.OperandTypes; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; /** * Definition of the SQL REGR_COUNT aggregation function. @@ -30,6 +30,6 @@ public class SqlRegrCountAggFunction extends SqlCountAggFunction { public SqlRegrCountAggFunction(SqlKind kind) { super("REGR_COUNT", OperandTypes.NUMERIC_NUMERIC); - Preconditions.checkArgument(SqlKind.REGR_COUNT == kind, "unsupported sql kind: " + kind); + checkArgument(SqlKind.REGR_COUNT == kind, "unsupported sql kind: " + kind); } } diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java index e4b8ef2b41af..ca3c0a708442 100644 --- a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java +++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java @@ -48,7 +48,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.trace.CalciteTrace; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -69,6 +68,8 @@ import java.util.function.Predicate; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; import static java.lang.Integer.parseInt; @@ -442,7 +443,7 @@ public static long intervalToMillis( public static long intervalToMillis( String literal, SqlIntervalQualifier intervalQualifier) { - Preconditions.checkArgument(!intervalQualifier.isYearMonth(), + checkArgument(!intervalQualifier.isYearMonth(), "interval must be day time"); int[] ret; try { @@ -480,10 +481,9 @@ public static long intervalToMonths( interval.getIntervalQualifier()); } - public static long intervalToMonths( - String literal, + public static long intervalToMonths(String literal, SqlIntervalQualifier intervalQualifier) { - Preconditions.checkArgument(intervalQualifier.isYearMonth(), + checkArgument(intervalQualifier.isYearMonth(), "interval must be year month"); int[] ret; try { @@ -818,7 +818,7 @@ public static void replaceSublist( int end, T o) { requireNonNull(list, "list"); - Preconditions.checkArgument(start < end); + checkArgument(start < end); for (int i = end - 1; i > start; --i) { list.remove(i); } diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java index ee1c52d9b866..db9b38afad28 100644 --- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java +++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java @@ -29,7 +29,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.trace.CalciteLogger; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -49,6 +48,8 @@ import java.util.Set; import java.util.function.Consumer; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -881,7 +882,7 @@ protected Frame startList( @Override public void endList(@Nullable Frame frame) { FrameImpl endedFrame = (FrameImpl) frame; - Preconditions.checkArgument(frame == this.frame, + checkArgument(frame == this.frame, "Frame does not match current frame"); if (endedFrame == null) { throw new RuntimeException("No list started"); diff --git a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java index 9428ad409ad7..847e5962869e 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java +++ b/core/src/main/java/org/apache/calcite/sql/type/BasicSqlType.java @@ -20,13 +20,13 @@ import org.apache.calcite.sql.SqlCollation; import org.apache.calcite.util.SerializableCharset; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.charset.Charset; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * BasicSqlType represents a standard atomic SQL type (excluding interval * types). @@ -140,7 +140,7 @@ BasicSqlType createWithNullability(boolean nullable) { */ BasicSqlType createWithCharsetAndCollation(Charset charset, SqlCollation collation) { - Preconditions.checkArgument(SqlTypeUtil.inCharFamily(this)); + checkArgument(SqlTypeUtil.inCharFamily(this)); return new BasicSqlType(this.typeSystem, this.typeName, this.isNullable, this.precision, this.scale, collation, SerializableCharset.forCharset(charset)); diff --git a/core/src/main/java/org/apache/calcite/sql/type/MatchReturnTypeInference.java b/core/src/main/java/org/apache/calcite/sql/type/MatchReturnTypeInference.java index ad653069c598..1426c51c3ec9 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/MatchReturnTypeInference.java +++ b/core/src/main/java/org/apache/calcite/sql/type/MatchReturnTypeInference.java @@ -19,13 +19,14 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.SqlOperatorBinding; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * Returns the first type that matches a set of given {@link SqlTypeName}s. If * no match could be found, null is returned. @@ -53,10 +54,10 @@ public MatchReturnTypeInference(int start, SqlTypeName... typeNames) { * position start (zero based). */ public MatchReturnTypeInference(int start, Iterable typeNames) { - Preconditions.checkArgument(start >= 0); + checkArgument(start >= 0); this.start = start; this.typeNames = ImmutableList.copyOf(typeNames); - Preconditions.checkArgument(!this.typeNames.isEmpty()); + checkArgument(!this.typeNames.isEmpty()); } //~ Methods ---------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java index f8696893b044..fd46977ca8b7 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java +++ b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java @@ -34,12 +34,12 @@ import org.apache.calcite.util.Glossary; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import java.util.AbstractList; import java.util.List; import java.util.function.UnaryOperator; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.sql.type.NonNullableAccessors.getCharset; import static org.apache.calcite.sql.type.NonNullableAccessors.getCollation; import static org.apache.calcite.sql.validate.SqlNonNullableAccessors.getNamespace; @@ -955,8 +955,7 @@ public static SqlCall stripSeparator(SqlCall call) { && !containsNullType && !(SqlTypeUtil.inCharOrBinaryFamilies(argType0) && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) { - Preconditions.checkArgument( - SqlTypeUtil.sameNamedType(argType0, argType1)); + checkArgument(SqlTypeUtil.sameNamedType(argType0, argType1)); } SqlCollation pickedCollation = null; if (!containsAnyType diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlOperandCountRanges.java b/core/src/main/java/org/apache/calcite/sql/type/SqlOperandCountRanges.java index f8494e95f3f8..b0d0f18ca451 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlOperandCountRanges.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlOperandCountRanges.java @@ -18,7 +18,7 @@ import org.apache.calcite.sql.SqlOperandCountRange; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; /** * Helpers for {@link SqlOperandCountRange}. @@ -48,8 +48,8 @@ private static class RangeImpl implements SqlOperandCountRange { RangeImpl(int min, int max) { this.min = min; this.max = max; - Preconditions.checkArgument(min <= max || max == -1); - Preconditions.checkArgument(min >= 0); + checkArgument(min <= max || max == -1); + checkArgument(min >= 0); } @Override public boolean isValidCount(int count) { diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlReturnTypeInferenceChain.java b/core/src/main/java/org/apache/calcite/sql/type/SqlReturnTypeInferenceChain.java index 6be969eef254..3ed9875b189b 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlReturnTypeInferenceChain.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlReturnTypeInferenceChain.java @@ -19,11 +19,12 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.SqlOperatorBinding; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Strategy to infer the type of an operator call from the type of the operands * by using a series of {@link SqlReturnTypeInference} rules in a given order. @@ -44,7 +45,7 @@ public class SqlReturnTypeInferenceChain implements SqlReturnTypeInference { * Use {@link org.apache.calcite.sql.type.ReturnTypes#chain}. */ SqlReturnTypeInferenceChain(SqlReturnTypeInference... rules) { - Preconditions.checkArgument(rules.length > 1); + checkArgument(rules.length > 1); this.rules = ImmutableList.copyOf(rules); } diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransformCascade.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransformCascade.java index b8015a282d69..f00788461245 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransformCascade.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeTransformCascade.java @@ -19,13 +19,14 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.sql.SqlOperatorBinding; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Objects; +import static com.google.common.base.Preconditions.checkArgument; + /** * Strategy to infer the type of an operator call from the type of the operands * by using one {@link SqlReturnTypeInference} rule and a combination of @@ -46,7 +47,7 @@ public class SqlTypeTransformCascade implements SqlReturnTypeInference { public SqlTypeTransformCascade( SqlReturnTypeInference rule, SqlTypeTransform... transforms) { - Preconditions.checkArgument(transforms.length > 0); + checkArgument(transforms.length > 0); this.rule = Objects.requireNonNull(rule, "rule"); this.transforms = ImmutableList.copyOf(transforms); } diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java index f8ccdb92e20a..8149b22dad5d 100644 --- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java +++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java @@ -43,7 +43,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; @@ -62,6 +61,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.rel.type.RelDataTypeImpl.NON_NULLABLE_SUFFIX; import static org.apache.calcite.sql.type.NonNullableAccessors.getCharset; import static org.apache.calcite.sql.type.NonNullableAccessors.getCollation; @@ -1192,7 +1193,7 @@ public static RelDataType createMapType( * two fields. */ public static RelDataType createMapTypeFromRecord( RelDataTypeFactory typeFactory, RelDataType type) { - Preconditions.checkArgument(type.getFieldCount() == 2, + checkArgument(type.getFieldCount() == 2, "MAP requires exactly two fields, got %s; row type %s", type.getFieldCount(), type); return createMapType(typeFactory, type.getFieldList().get(0).getType(), @@ -1309,10 +1310,8 @@ public static boolean equalAsCollectionSansNullability( RelDataTypeFactory factory, RelDataType type1, RelDataType type2) { - Preconditions.checkArgument(isCollection(type1), - "Input type1 must be collection type"); - Preconditions.checkArgument(isCollection(type2), - "Input type2 must be collection type"); + checkArgument(isCollection(type1), "Input type1 must be collection type"); + checkArgument(isCollection(type2), "Input type2 must be collection type"); return (type1 == type2) || (type1.getSqlTypeName() == type2.getSqlTypeName() @@ -1334,8 +1333,8 @@ public static boolean equalAsMapSansNullability( RelDataTypeFactory factory, RelDataType type1, RelDataType type2) { - Preconditions.checkArgument(isMap(type1), "Input type1 must be map type"); - Preconditions.checkArgument(isMap(type2), "Input type2 must be map type"); + checkArgument(isMap(type1), "Input type1 must be map type"); + checkArgument(isMap(type2), "Input type2 must be map type"); MapSqlType mType1 = (MapSqlType) type1; MapSqlType mType2 = (MapSqlType) type2; @@ -1362,8 +1361,8 @@ public static boolean equalAsStructSansNullability( RelDataType type1, RelDataType type2, @Nullable SqlNameMatcher nameMatcher) { - Preconditions.checkArgument(type1.isStruct(), "Input type1 must be struct type"); - Preconditions.checkArgument(type2.isStruct(), "Input type2 must be struct type"); + checkArgument(type1.isStruct(), "Input type1 must be struct type"); + checkArgument(type2.isStruct(), "Input type2 must be struct type"); if (type1 == type2) { return true; diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java index 40c16bee84bd..3f16078314b1 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/AbstractNamespace.java @@ -23,13 +23,15 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; -import java.util.Objects; + +import static com.google.common.base.Preconditions.checkArgument; + +import static java.util.Objects.requireNonNull; /** * Abstract implementation of {@link SqlValidatorNamespace}. @@ -83,11 +85,10 @@ abstract class AbstractNamespace implements SqlValidatorNamespace { case UNVALIDATED: try { status = SqlValidatorImpl.Status.IN_PROGRESS; - Preconditions.checkArgument(rowType == null, + checkArgument(rowType == null, "Namespace.rowType must be null before validate has been called"); RelDataType type = validateImpl(targetRowType); - Preconditions.checkArgument(type != null, - "validateImpl() returned null"); + requireNonNull(type, "validateImpl() returned null"); setType(type); } finally { status = SqlValidatorImpl.Status.VALID; @@ -107,17 +108,16 @@ abstract class AbstractNamespace implements SqlValidatorNamespace { * External users should call {@link #validate}, which uses the * {@link #status} field to protect against cycles. * - * @return record data type, never null - * * @param targetRowType Desired row type, must not be null, may be the data * type 'unknown'. + * @return record data type, never null */ protected abstract RelDataType validateImpl(RelDataType targetRowType); @Override public RelDataType getRowType() { if (rowType == null) { validator.validateNamespace(this, validator.unknownType); - Objects.requireNonNull(rowType, "validate must set rowType"); + requireNonNull(rowType, "validate must set rowType"); } return rowType; } @@ -128,7 +128,7 @@ abstract class AbstractNamespace implements SqlValidatorNamespace { @Override public RelDataType getType() { Util.discard(getRowType()); - return Objects.requireNonNull(type, "type"); + return requireNonNull(type, "type"); } @Override public void setType(RelDataType type) { @@ -179,7 +179,7 @@ public String translate(String name) { return true; } - @Override public T unwrap(Class clazz) { + @Override public T unwrap(Class clazz) { return clazz.cast(this); } @@ -219,9 +219,7 @@ protected RelDataType toStruct(RelDataType type, @Nullable SqlNode unnest) { return type; } return validator.getTypeFactory().builder() - .add( - SqlValidatorUtil.alias(Objects.requireNonNull(unnest, "unnest"), 0), - type) + .add(SqlValidatorUtil.alias(requireNonNull(unnest, "unnest"), 0), type) .build(); } } diff --git a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java index a5aee4e79e32..21f59a3dfde3 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingNamespace.java @@ -104,7 +104,7 @@ protected DelegatingNamespace(SqlValidatorNamespace namespace) { @Override public void makeNullable() { } - @Override public T unwrap(Class clazz) { + @Override public T unwrap(Class clazz) { if (clazz.isInstance(this)) { return clazz.cast(this); } else { diff --git a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java index 935e9bc14bcd..a038bbe98017 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java @@ -35,7 +35,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; @@ -50,6 +49,8 @@ import java.util.Map; import java.util.function.Supplier; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; import static java.util.Objects.requireNonNull; @@ -605,8 +606,7 @@ private static boolean hasAmbiguousField(RelDataType rowType, } private AggregatingSelectScope.Resolved resolve() { - Preconditions.checkArgument(groupAnalyzer == null, - "resolve already in progress"); + checkArgument(groupAnalyzer == null, "resolve already in progress"); SqlValidatorUtil.GroupAnalyzer groupAnalyzer = new SqlValidatorUtil.GroupAnalyzer(); this.groupAnalyzer = groupAnalyzer; try { diff --git a/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java index 8bd130f282bc..c3fab93146da 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/IdentifierNamespace.java @@ -31,13 +31,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Objects; import static org.apache.calcite.util.Static.RESOURCE; +import static java.util.Objects.requireNonNull; + /** * Namespace whose contents are defined by the type of an * {@link org.apache.calcite.sql.SqlIdentifier identifier}. @@ -77,7 +76,7 @@ public class IdentifierNamespace extends AbstractNamespace { super(validator, enclosingNode); this.id = id; this.extendList = extendList; - this.parentScope = Objects.requireNonNull(parentScope, "parentScope"); + this.parentScope = requireNonNull(parentScope, "parentScope"); } IdentifierNamespace(SqlValidatorImpl validator, SqlNode node, @@ -187,30 +186,27 @@ private SqlValidatorNamespace resolveImpl(SqlIdentifier id) { @Override public RelDataType validateImpl(RelDataType targetRowType) { resolvedNamespace = resolveImpl(id); - if (resolvedNamespace instanceof TableNamespace) { - SqlValidatorTable table = ((TableNamespace) resolvedNamespace).getTable(); - if (validator.config().identifierExpansion()) { + validator.validateNamespace(resolvedNamespace, targetRowType); + + if (validator.config().identifierExpansion()) { + SqlValidatorTable table = resolvedNamespace.getTable(); + if (table != null) { // TODO: expand qualifiers for column references also List qualifiedNames = table.getQualifiedName(); - if (qualifiedNames != null) { - // Assign positions to the components of the fully-qualified - // identifier, as best we can. We assume that qualification - // adds names to the front, e.g. FOO.BAR becomes BAZ.FOO.BAR. - List poses = - new ArrayList<>( - Collections.nCopies( - qualifiedNames.size(), id.getParserPosition())); - int offset = qualifiedNames.size() - id.names.size(); - - // Test offset in case catalog supports fewer qualifiers than catalog - // reader. - if (offset >= 0) { - for (int i = 0; i < id.names.size(); i++) { - poses.set(i + offset, id.getComponentParserPosition(i)); - } - } - id.setNames(qualifiedNames, poses); + // Assign positions to the components of the fully-qualified + // identifier, as best we can. We assume that qualification + // adds names to the front, e.g. FOO.BAR becomes BAZ.FOO.BAR. + // Test offset in case catalog supports fewer qualifiers than catalog + // reader. + ImmutableList.Builder positions = + ImmutableList.builder(); + int offset = qualifiedNames.size() - id.names.size(); + for (int i = 0; i < qualifiedNames.size(); i++) { + positions.add(offset >= 0 && i >= offset + ? id.getComponentParserPosition(i - offset) + : id.getParserPosition()); } + id.setNames(qualifiedNames, positions.build()); } } diff --git a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java index e91a476dca99..0d83ccd6bfbd 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/ListScope.java @@ -36,6 +36,8 @@ import static org.apache.calcite.util.Static.RESOURCE; +import static java.util.Objects.requireNonNull; + /** * Abstract base for a scope which is defined by a list of child namespaces and * which inherits from a parent scope. @@ -58,7 +60,7 @@ protected ListScope(SqlValidatorScope parent) { @Override public void addChild(SqlValidatorNamespace ns, String alias, boolean nullable) { - Objects.requireNonNull(alias, "alias"); + requireNonNull(alias, "alias"); children.add(new ScopeChild(children.size(), alias, ns, nullable)); } diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlLambdaScope.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlLambdaScope.java index ac7e1eac5431..02fb615c7648 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlLambdaScope.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlLambdaScope.java @@ -23,13 +23,13 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.util.Litmus; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.HashMap; import java.util.Map; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; /** @@ -69,7 +69,7 @@ public SqlLambdaScope( } @Override public @Nullable RelDataType resolveColumn(String columnName, SqlNode ctx) { - Preconditions.checkArgument(parameterTypes.containsKey(columnName), + checkArgument(parameterTypes.containsKey(columnName), "column %s not found", columnName); return parameterTypes.get(columnName); } diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlQualified.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlQualified.java index 9742f1510b59..48bb492de25e 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlQualified.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlQualified.java @@ -47,7 +47,7 @@ private SqlQualified(@Nullable SqlValidatorScope scope, int prefixLength, } @Override public String toString() { - return "{id: " + identifier.toString() + ", prefix: " + prefixLength + "}"; + return "{id: " + identifier + ", prefix: " + prefixLength + "}"; } public static SqlQualified create(@Nullable SqlValidatorScope scope, int prefixLength, diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java index 81f2140b6a41..03389814c3c7 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java @@ -117,7 +117,6 @@ import org.apache.calcite.util.Util; import org.apache.calcite.util.trace.CalciteTrace; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -154,7 +153,11 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import static org.apache.calcite.linq4j.Nullness.castNonNull; +import static org.apache.calcite.linq4j.Ord.forEach; import static org.apache.calcite.sql.SqlUtil.stripAs; import static org.apache.calcite.sql.type.NonNullableAccessors.getCharset; import static org.apache.calcite.sql.type.NonNullableAccessors.getCollation; @@ -163,6 +166,7 @@ import static org.apache.calcite.util.Static.RESOURCE; import static org.apache.calcite.util.Util.first; +import static java.util.Collections.emptyList; import static java.util.Objects.requireNonNull; /** @@ -746,7 +750,7 @@ private boolean expandStar(List selectItems, Set aliases, private static int calculatePermuteOffset(List selectItems) { for (int i = 0; i < selectItems.size(); i++) { SqlNode selectItem = selectItems.get(i); - SqlNode col = SqlUtil.stripAs(selectItem); + SqlNode col = stripAs(selectItem); if (col.getKind() == SqlKind.IDENTIFIER && selectItem.getKind() != SqlKind.AS) { return i; @@ -1914,9 +1918,7 @@ protected SqlSelect createSourceSelectForDelete(SqlDelete call) { return ns.getType(); } type = deriveTypeImpl(scope, expr); - Preconditions.checkArgument( - type != null, - "SqlValidator.deriveTypeInternal returned null"); + requireNonNull(type, "SqlValidator.deriveTypeInternal returned null"); setValidatedNodeType(expr, type); return type; } @@ -2745,7 +2747,7 @@ private void registerQuery( SqlNode enclosingNode, @Nullable String alias, boolean forceNullable) { - Preconditions.checkArgument(usingScope == null || alias != null); + checkArgument(usingScope == null || alias != null); registerQuery( parentScope, usingScope, @@ -2778,7 +2780,7 @@ private void registerQuery( boolean checkUpdate) { requireNonNull(node, "node"); requireNonNull(enclosingNode, "enclosingNode"); - Preconditions.checkArgument(usingScope == null || alias != null); + checkArgument(usingScope == null || alias != null); SqlCall call; List operands; @@ -3623,7 +3625,7 @@ protected void validateJoin(SqlJoin join, SqlValidatorScope scope) { // Validate condition. switch (conditionType) { case NONE: - Preconditions.checkArgument(join.getCondition() == null); + checkArgument(join.getCondition() == null); break; case ON: final SqlNode condition = expand(getCondition(join), joinScope); @@ -3636,7 +3638,7 @@ protected void validateJoin(SqlJoin join, SqlValidatorScope scope) { (List) getCondition(join); // Parser ensures that using clause is not empty. - Preconditions.checkArgument(!list.isEmpty(), "Empty USING clause"); + checkArgument(!list.isEmpty(), "Empty USING clause"); for (SqlIdentifier id : list) { validateCommonJoinColumn(id, left, right, scope, natural); } @@ -3741,7 +3743,7 @@ private void validateCommonJoinColumn(SqlIdentifier id, SqlNode left, } private RelDataType checkAndDeriveDataType(SqlIdentifier id, SqlNode node) { - Preconditions.checkArgument(id.names.size() == 1); + checkArgument(id.names.size() == 1); String name = id.names.get(0); SqlNameMatcher nameMatcher = getCatalogReader().nameMatcher(); RelDataType rowType = getNamespaceOrThrow(node).getRowType(); @@ -3755,7 +3757,7 @@ private RelDataType checkAndDeriveDataType(SqlIdentifier id, SqlNode node) { * NATURAL join, in the left or right input to the join. */ private RelDataType validateCommonInputJoinColumn(SqlIdentifier id, SqlNode leftOrRight, SqlValidatorScope scope, boolean natural) { - Preconditions.checkArgument(id.names.size() == 1); + checkArgument(id.names.size() == 1); final String name = id.names.get(0); final SqlValidatorNamespace namespace = getNamespaceOrThrow(leftOrRight); final RelDataType rowType = namespace.getRowType(); @@ -3790,7 +3792,8 @@ private RelDataType validateCommonInputJoinColumn(SqlIdentifier id, protected void validateSelect( SqlSelect select, RelDataType targetRowType) { - assert targetRowType != null; + requireNonNull(targetRowType, "targetRowType"); + // Namespace is either a select namespace or a wrapper around one. final SelectNamespace ns = getNamespaceOrThrow(select).unwrap(SelectNamespace.class); @@ -3844,12 +3847,13 @@ protected void validateSelect( RESOURCE.fromAliasDuplicate(child.name)); } - if (select.getFrom() == null) { + final SqlNode from = select.getFrom(); + if (from == null) { if (this.config.conformance().isFromRequired()) { throw newValidationError(select, RESOURCE.selectMissingFrom()); } } else { - validateFrom(select.getFrom(), fromType, fromScope); + validateFrom(from, fromType, fromScope); } validateWhereClause(select); @@ -3871,7 +3875,7 @@ protected void validateSelect( // "SELECT empno AS x FROM emp ORDER BY x" validateOrderList(select); - if (shouldCheckForRollUp(select.getFrom())) { + if (shouldCheckForRollUp(from)) { checkRollUpInSelectList(select); checkRollUp(null, select, select.getWhere(), getWhereScope(select)); checkRollUp(null, select, select.getHaving(), getHavingScope(select)); @@ -4624,7 +4628,7 @@ protected void validateWhereOrOn( private static boolean isReturnBooleanType(RelDataType relDataType) { if (relDataType instanceof RelRecordType) { RelRecordType recordType = (RelRecordType) relDataType; - Preconditions.checkState(recordType.getFieldList().size() == 1, + checkState(recordType.getFieldList().size() == 1, "sub-query as condition must return only one column"); RelDataTypeField recordField = recordType.getFieldList().get(0); return SqlTypeUtil.inBooleanFamily(recordField.getType()); @@ -5795,12 +5799,13 @@ public void setOriginal(SqlNode expr, SqlNode original) { } }); - final RelDataType rowType = typeBuilder.build(); - if (matchRecognize.getMeasureList().size() == 0) { - ns.setType(getNamespaceOrThrow(matchRecognize.getTableRef()).getRowType()); + final RelDataType rowType; + if (matchRecognize.getMeasureList().isEmpty()) { + rowType = getNamespaceOrThrow(matchRecognize.getTableRef()).getRowType(); } else { - ns.setType(rowType); + rowType = typeBuilder.build(); } + ns.setType(rowType); } private PairList validateMeasure(SqlMatchRecognize mr, @@ -6043,7 +6048,7 @@ public void validateUnpivot(SqlUnpivot unpivot) { // Gather the name and type of each measure. final PairList measureNameTypes = PairList.of(); - Ord.forEach(unpivot.measureList, (measure, i) -> { + forEach(unpivot.measureList, (measure, i) -> { final String measureName = ((SqlIdentifier) measure).getSimple(); final List types = new ArrayList<>(); final List nodes = new ArrayList<>(); @@ -6080,7 +6085,7 @@ public void validateUnpivot(SqlUnpivot unpivot) { // ('CLERK', 'ANALYST'), namely VARCHAR(7). The derived type of 'deptno' is // the type of values (10, 20), namely INTEGER. final PairList axisNameTypes = PairList.of(); - Ord.forEach(unpivot.axisList, (axis, i) -> { + forEach(unpivot.axisList, (axis, i) -> { final String axisName = ((SqlIdentifier) axis).getSimple(); final List types = new ArrayList<>(); unpivot.forEachNameValues((aliasList, valueList) -> @@ -6183,7 +6188,7 @@ private SqlNode navigationInDefine(SqlNode node, String alpha) { final SqlAggFunction op = (SqlAggFunction) aggCall.getOperator(); switch (op.requiresGroupOrder()) { case MANDATORY: - if (orderList == null || orderList.size() == 0) { + if (orderList == null || orderList.isEmpty()) { throw newValidationError(aggCall, RESOURCE.aggregateMissingWithinGroupClause(op.getName())); } @@ -6197,7 +6202,7 @@ private SqlNode navigationInDefine(SqlNode node, String alpha) { } break; case FORBIDDEN: - if (orderList != null && orderList.size() != 0) { + if (orderList != null && !orderList.isEmpty()) { throw newValidationError(aggCall, RESOURCE.withinGroupClauseIllegalInAggregate(op.getName())); } @@ -6350,7 +6355,7 @@ public SqlNode extendedExpandGroupBy(SqlNode expr, @Override public List<@Nullable List> getFieldOrigins(SqlNode sqlQuery) { if (sqlQuery instanceof SqlExplain) { - return Collections.emptyList(); + return emptyList(); } final RelDataType rowType = getValidatedNodeType(sqlQuery); final int fieldCount = rowType.getFieldCount(); @@ -6575,7 +6580,7 @@ private static class PatternVarVisitor implements SqlVisitor { } @Override public Void visit(SqlIdentifier id) { - Preconditions.checkArgument(id.isSimple()); + checkArgument(id.isSimple()); scope.addPatternVar(id.getSimple()); return null; } @@ -7031,7 +7036,8 @@ static class ExtendedExpander extends Expander { // SQL ordinals are 1-based, but Sort's are 0-based int ordinal = intValue - 1; - return SqlUtil.stripAs(SqlNonNullableAccessors.getSelectList(select).get(ordinal)); + return stripAs(SqlNonNullableAccessors.getSelectList(select) + .get(ordinal)); } break; default: diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java index 3de29d403e54..ddcaceefb49d 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorNamespace.java @@ -184,7 +184,7 @@ default boolean fieldExists(String name) { * @return This namespace cast to desired type * @throws ClassCastException if no such interface is available */ - T unwrap(Class clazz); + T unwrap(Class clazz); /** * Returns whether this namespace implements a given interface, or wraps a diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java index 6d1119c9a46a..3c4565bb2f2e 100644 --- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java +++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorUtil.java @@ -63,7 +63,6 @@ import org.apache.calcite.util.Util; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -84,6 +83,8 @@ import java.util.Set; import java.util.TreeSet; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.linq4j.Nullness.castNonNullList; import static org.apache.calcite.sql.type.NonNullableAccessors.getCharset; import static org.apache.calcite.sql.type.NonNullableAccessors.getCollation; @@ -329,7 +330,7 @@ public static SqlNode addAlias( * "expr$ordinal"; never null */ public static String alias(SqlNode node, int ordinal) { - Preconditions.checkArgument(ordinal >= 0); + checkArgument(ordinal >= 0); return requireNonNull(alias_(node, ordinal), "alias"); } @@ -1540,11 +1541,11 @@ public static class FlatAggregate { @Nullable SqlCall distinctCall, @Nullable SqlCall orderCall) { this.aggregateCall = Objects.requireNonNull(aggregateCall, "aggregateCall"); - Preconditions.checkArgument(filterCall == null + checkArgument(filterCall == null || filterCall.getKind() == SqlKind.FILTER); - Preconditions.checkArgument(distinctCall == null + checkArgument(distinctCall == null || distinctCall.getKind() == SqlKind.WITHIN_DISTINCT); - Preconditions.checkArgument(orderCall == null + checkArgument(orderCall == null || orderCall.getKind() == SqlKind.WITHIN_GROUP); this.filterCall = filterCall; this.filter = filterCall == null ? null : filterCall.operand(1); diff --git a/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java b/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java index 47be8816dd7b..1b7077d53a7f 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/ReflectiveConvertletTable.java @@ -22,8 +22,6 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.parser.SqlParserPos; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.initialization.qual.UnderInitialization; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.RequiresNonNull; @@ -33,6 +31,8 @@ import java.util.HashMap; import java.util.Map; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.ReflectUtil.isPublic; import static java.util.Objects.requireNonNull; @@ -208,8 +208,7 @@ protected void addAlias( final SqlOperator alias, final SqlOperator target) { map.put( alias, (SqlRexConvertlet) (cx, call) -> { - Preconditions.checkArgument(call.getOperator() == alias, - "call to wrong operator"); + checkArgument(call.getOperator() == alias, "call to wrong operator"); final SqlCall newCall = target.createCall(SqlParserPos.ZERO, call.getOperandList()); cx.getValidator().setValidatedNodeType(newCall, diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java index afdfe92fe98f..313fda132c00 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlNodeToRexConverterImpl.java @@ -34,10 +34,10 @@ import org.apache.calcite.util.TimestampString; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import java.math.BigDecimal; +import static com.google.common.base.Preconditions.checkArgument; + /** * Standard implementation of {@link SqlNodeToRexConverter}. */ @@ -108,8 +108,7 @@ public class SqlNodeToRexConverterImpl implements SqlNodeToRexConverter { return rexBuilder.makeLiteral(literal.getValueAs(Boolean.class)); case BINARY: final BitString bitString = literal.getValueAs(BitString.class); - Preconditions.checkArgument((bitString.getBitCount() % 8) == 0, - "incomplete octet"); + checkArgument((bitString.getBitCount() % 8) == 0, "incomplete octet"); // An even number of hexits (e.g. X'ABCD') makes whole number // of bytes. diff --git a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java index ccd946c437f8..9211f9778c99 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java @@ -82,7 +82,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.initialization.qual.UnknownInitialization; @@ -1840,7 +1839,7 @@ private static class SubstrConvertlet implements SqlRexConvertlet { SubstrConvertlet(SqlLibrary library) { this.library = library; - Preconditions.checkArgument(library == SqlLibrary.ORACLE + checkArgument(library == SqlLibrary.ORACLE || library == SqlLibrary.MYSQL || library == SqlLibrary.BIG_QUERY || library == SqlLibrary.POSTGRESQL); diff --git a/core/src/main/java/org/apache/calcite/tools/Hoist.java b/core/src/main/java/org/apache/calcite/tools/Hoist.java index f2ac5dba04a4..3fceb10b5f4a 100644 --- a/core/src/main/java/org/apache/calcite/tools/Hoist.java +++ b/core/src/main/java/org/apache/calcite/tools/Hoist.java @@ -25,7 +25,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.util.SqlShuttle; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -38,6 +37,8 @@ import java.util.Objects; import java.util.function.Function; +import static com.google.common.base.Preconditions.checkArgument; + /** * Utility that extracts constants from a SQL query. * @@ -154,10 +155,10 @@ private Variable(String originalSql, int ordinal, SqlNode node) { SqlParserUtil.lineColToIndex(originalSql, pos.getEndLineNum(), pos.getEndColumnNum()) + 1; - Preconditions.checkArgument(ordinal >= 0); - Preconditions.checkArgument(start >= 0); - Preconditions.checkArgument(start <= end); - Preconditions.checkArgument(end <= originalSql.length()); + checkArgument(ordinal >= 0); + checkArgument(start >= 0); + checkArgument(start <= end); + checkArgument(end <= originalSql.length()); } /** Returns SQL text of the region of the statement covered by this diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java index 757e81265f45..8d8d48bd078a 100644 --- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java +++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java @@ -118,7 +118,6 @@ import org.apache.calcite.util.mapping.Mapping; import org.apache.calcite.util.mapping.Mappings; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -155,6 +154,7 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.toImmutableList; import static org.apache.calcite.linq4j.Nullness.castNonNull; @@ -2270,7 +2270,7 @@ public RelBuilder uncollect(List itemAliases, boolean withOrdinality) { */ public RelBuilder rename(List fieldNames) { final List oldFieldNames = peek().getRowType().getFieldNames(); - Preconditions.checkArgument(fieldNames.size() <= oldFieldNames.size(), + checkArgument(fieldNames.size() <= oldFieldNames.size(), "More names than fields"); final List newFieldNames = new ArrayList<>(oldFieldNames); for (int i = 0; i < fieldNames.size(); i++) { diff --git a/core/src/main/java/org/apache/calcite/util/DateString.java b/core/src/main/java/org/apache/calcite/util/DateString.java index 2dc19b5def4f..5ae741400aed 100644 --- a/core/src/main/java/org/apache/calcite/util/DateString.java +++ b/core/src/main/java/org/apache/calcite/util/DateString.java @@ -21,13 +21,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Preconditions; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Calendar; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkArgument; + /** * Date literal. * @@ -48,13 +49,13 @@ private DateString(String v, @SuppressWarnings("unused") boolean ignore) { @SuppressWarnings("method.invocation.invalid") public DateString(String v) { this(v, false); - Preconditions.checkArgument(PATTERN.matcher(v).matches(), + checkArgument(PATTERN.matcher(v).matches(), "Invalid date format:", v); - Preconditions.checkArgument(getYear() >= 1 && getYear() <= 9999, + checkArgument(getYear() >= 1 && getYear() <= 9999, "Year out of range:", getYear()); - Preconditions.checkArgument(getMonth() >= 1 && getMonth() <= 12, + checkArgument(getMonth() >= 1 && getMonth() <= 12, "Month out of range:", getMonth()); - Preconditions.checkArgument(getDay() >= 1 && getDay() <= 31, + checkArgument(getDay() >= 1 && getDay() <= 31, "Day out of range:", getDay()); } @@ -65,11 +66,11 @@ public DateString(int year, int month, int day) { /** Validates a year-month-date and converts to a string. */ private static String ymd(int year, int month, int day) { - Preconditions.checkArgument(year >= 1 && year <= 9999, + checkArgument(year >= 1 && year <= 9999, "Year out of range:", year); - Preconditions.checkArgument(month >= 1 && month <= 12, + checkArgument(month >= 1 && month <= 12, "Month out of range:", month); - Preconditions.checkArgument(day >= 1 && day <= 31, + checkArgument(day >= 1 && day <= 31, "Day out of range:", day); final StringBuilder b = new StringBuilder(); DateTimeStringUtils.ymd(b, year, month, day); diff --git a/core/src/main/java/org/apache/calcite/util/JdbcTypeImpl.java b/core/src/main/java/org/apache/calcite/util/JdbcTypeImpl.java index 6cff5d61ba05..aa8d4853de30 100644 --- a/core/src/main/java/org/apache/calcite/util/JdbcTypeImpl.java +++ b/core/src/main/java/org/apache/calcite/util/JdbcTypeImpl.java @@ -16,14 +16,14 @@ */ package org.apache.calcite.util; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; +import static com.google.common.base.Preconditions.checkArgument; + import static java.util.Objects.requireNonNull; /** @@ -52,7 +52,7 @@ enum JdbcTypeImpl implements JdbcType { @Override public Boolean get(int column, ResultSet resultSet) throws SQLException { boolean v = resultSet.getBoolean(column); - Preconditions.checkArgument(v || !resultSet.wasNull()); + checkArgument(v || !resultSet.wasNull()); return v; } }, @@ -69,7 +69,7 @@ enum JdbcTypeImpl implements JdbcType { @Override public Double get(int column, ResultSet resultSet) throws SQLException { double v = resultSet.getDouble(column); - Preconditions.checkArgument(v != 0 || !resultSet.wasNull()); + checkArgument(v != 0 || !resultSet.wasNull()); return v; } }, @@ -86,7 +86,7 @@ enum JdbcTypeImpl implements JdbcType { @Override public Integer get(int column, ResultSet resultSet) throws SQLException { int v = resultSet.getInt(column); - Preconditions.checkArgument(v != 0 || !resultSet.wasNull()); + checkArgument(v != 0 || !resultSet.wasNull()); return v; } }, diff --git a/core/src/main/java/org/apache/calcite/util/TimeWithTimeZoneString.java b/core/src/main/java/org/apache/calcite/util/TimeWithTimeZoneString.java index a533e2493d7d..a57e949cdc82 100644 --- a/core/src/main/java/org/apache/calcite/util/TimeWithTimeZoneString.java +++ b/core/src/main/java/org/apache/calcite/util/TimeWithTimeZoneString.java @@ -18,8 +18,6 @@ import org.apache.calcite.avatica.util.DateTimeUtils; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.text.SimpleDateFormat; @@ -27,6 +25,8 @@ import java.util.Locale; import java.util.TimeZone; +import static com.google.common.base.Preconditions.checkArgument; + import static java.lang.Math.floorMod; /** @@ -52,7 +52,7 @@ public TimeWithTimeZoneString(TimeString localTime, TimeZone timeZone) { public TimeWithTimeZoneString(String v) { this.localTime = new TimeString(v.substring(0, 8)); String timeZoneString = v.substring(9); - Preconditions.checkArgument(DateTimeStringUtils.isValidTimeZone(timeZoneString)); + checkArgument(DateTimeStringUtils.isValidTimeZone(timeZoneString)); this.timeZone = TimeZone.getTimeZone(timeZoneString); this.v = v; } @@ -70,7 +70,7 @@ public TimeWithTimeZoneString(int h, int m, int s, String timeZone) { * {@code new TimeWithTimeZoneString(1970, 1, 1, 2, 3, 4, "UTC").withMillis(56)} * yields {@code TIME WITH LOCAL TIME ZONE '1970-01-01 02:03:04.056 UTC'}. */ public TimeWithTimeZoneString withMillis(int millis) { - Preconditions.checkArgument(millis >= 0 && millis < 1000); + checkArgument(millis >= 0 && millis < 1000); return withFraction(DateTimeStringUtils.pad(3, millis)); } @@ -81,7 +81,7 @@ public TimeWithTimeZoneString withMillis(int millis) { * {@code new TimeWithTimeZoneString(1970, 1, 1, 2, 3, 4, "UTC").withNanos(56789)} * yields {@code TIME WITH LOCAL TIME ZONE '1970-01-01 02:03:04.000056789 UTC'}. */ public TimeWithTimeZoneString withNanos(int nanos) { - Preconditions.checkArgument(nanos >= 0 && nanos < 1000000000); + checkArgument(nanos >= 0 && nanos < 1000000000); return withFraction(DateTimeStringUtils.pad(9, nanos)); } @@ -165,7 +165,7 @@ public TimeWithTimeZoneString withTimeZone(TimeZone timeZone) { } public TimeWithTimeZoneString round(int precision) { - Preconditions.checkArgument(precision >= 0); + checkArgument(precision >= 0); return new TimeWithTimeZoneString( localTime.round(precision), timeZone); } @@ -179,7 +179,7 @@ public static TimeWithTimeZoneString fromMillisOfDay(int i) { /** Converts this TimeWithTimeZoneString to a string, truncated or padded with * zeros to a given precision. */ public String toString(int precision) { - Preconditions.checkArgument(precision >= 0); + checkArgument(precision >= 0); return localTime.toString(precision) + " " + timeZone.getID(); } diff --git a/core/src/main/java/org/apache/calcite/util/TimestampString.java b/core/src/main/java/org/apache/calcite/util/TimestampString.java index fccd59b93672..45d7eb9cc1aa 100644 --- a/core/src/main/java/org/apache/calcite/util/TimestampString.java +++ b/core/src/main/java/org/apache/calcite/util/TimestampString.java @@ -111,7 +111,7 @@ public TimestampString withFraction(String fraction) { while (fraction.endsWith("0")) { fraction = fraction.substring(0, fraction.length() - 1); } - if (fraction.length() > 0) { + if (!fraction.isEmpty()) { v = v + "." + fraction; } return new TimestampString(v); diff --git a/core/src/main/java/org/apache/calcite/util/TimestampWithTimeZoneString.java b/core/src/main/java/org/apache/calcite/util/TimestampWithTimeZoneString.java index 752fa12f25c7..8e31656a65f7 100644 --- a/core/src/main/java/org/apache/calcite/util/TimestampWithTimeZoneString.java +++ b/core/src/main/java/org/apache/calcite/util/TimestampWithTimeZoneString.java @@ -18,8 +18,6 @@ import org.apache.calcite.avatica.util.DateTimeUtils; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.text.SimpleDateFormat; @@ -27,6 +25,8 @@ import java.util.Locale; import java.util.TimeZone; +import static com.google.common.base.Preconditions.checkArgument; + import static java.lang.Math.floorMod; /** @@ -53,7 +53,7 @@ public TimestampWithTimeZoneString(TimestampString localDateTime, TimeZone timeZ public TimestampWithTimeZoneString(String v) { this.localDateTime = new TimestampString(v.substring(0, v.indexOf(' ', 11))); String timeZoneString = v.substring(v.indexOf(' ', 11) + 1); - Preconditions.checkArgument(DateTimeStringUtils.isValidTimeZone(timeZoneString)); + checkArgument(DateTimeStringUtils.isValidTimeZone(timeZoneString)); this.timeZone = TimeZone.getTimeZone(timeZoneString); this.v = v; } @@ -73,7 +73,7 @@ public TimestampWithTimeZoneString(int year, int month, int day, int h, int m, i * {@code new TimestampWithTimeZoneString(1970, 1, 1, 2, 3, 4, "GMT").withMillis(56)} * yields {@code TIMESTAMP WITH LOCAL TIME ZONE '1970-01-01 02:03:04.056 GMT'}. */ public TimestampWithTimeZoneString withMillis(int millis) { - Preconditions.checkArgument(millis >= 0 && millis < 1000); + checkArgument(millis >= 0 && millis < 1000); return withFraction(DateTimeStringUtils.pad(3, millis)); } @@ -84,7 +84,7 @@ public TimestampWithTimeZoneString withMillis(int millis) { * {@code new TimestampWithTimeZoneString(1970, 1, 1, 2, 3, 4, "GMT").withNanos(56789)} * yields {@code TIMESTAMP WITH LOCAL TIME ZONE '1970-01-01 02:03:04.000056789 GMT'}. */ public TimestampWithTimeZoneString withNanos(int nanos) { - Preconditions.checkArgument(nanos >= 0 && nanos < 1000000000); + checkArgument(nanos >= 0 && nanos < 1000000000); return withFraction(DateTimeStringUtils.pad(9, nanos)); } @@ -161,7 +161,7 @@ public TimestampWithTimeZoneString withTimeZone(TimeZone timeZone) { } public TimestampWithTimeZoneString round(int precision) { - Preconditions.checkArgument(precision >= 0); + checkArgument(precision >= 0); return new TimestampWithTimeZoneString( localDateTime.round(precision), timeZone); } @@ -177,7 +177,7 @@ public static TimestampWithTimeZoneString fromMillisSinceEpoch(long millis) { /** Converts this TimestampWithTimeZoneString to a string, truncated or padded with * zeros to a given precision. */ public String toString(int precision) { - Preconditions.checkArgument(precision >= 0); + checkArgument(precision >= 0); return localDateTime.toString(precision) + " " + timeZone.getID(); } diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorFeatureTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorFeatureTest.java index 56a7d39fcd6c..24cdf1935d1b 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorFeatureTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorFeatureTest.java @@ -25,10 +25,13 @@ import org.apache.calcite.sql.validate.SqlValidatorCatalogReader; import org.apache.calcite.sql.validate.SqlValidatorImpl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.jupiter.api.Test; import static org.apache.calcite.util.Static.RESOURCE; +import static java.util.Objects.requireNonNull; + /** * SqlValidatorFeatureTest verifies that features can be independently enabled * or disabled. @@ -36,7 +39,7 @@ class SqlValidatorFeatureTest extends SqlValidatorTestCase { private static final String FEATURE_DISABLED = "feature_disabled"; - private Feature disabledFeature; + private @Nullable Feature disabledFeature; @Override public SqlValidatorFixture fixture() { return super.fixture() @@ -117,22 +120,20 @@ protected FeatureValidator( protected void validateFeature( Feature feature, - SqlParserPos context) { + SqlParserPos pos) { + requireNonNull(pos, "pos"); if (feature.equals(disabledFeature)) { CalciteException ex = new CalciteException( FEATURE_DISABLED, null); - if (context == null) { - throw ex; - } throw new CalciteContextException( "location", ex, - context.getLineNum(), - context.getColumnNum(), - context.getEndLineNum(), - context.getEndColumnNum()); + pos.getLineNum(), + pos.getColumnNum(), + pos.getEndLineNum(), + pos.getEndColumnNum()); } } } diff --git a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java index 58d844ce114f..f04c9be34b73 100644 --- a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java +++ b/druid/src/main/java/org/apache/calcite/adapter/druid/DruidTable.java @@ -37,7 +37,6 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.type.SqlTypeName; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -53,6 +52,8 @@ import java.util.Objects; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + /** * Table mapped onto a Druid table. */ @@ -235,8 +236,8 @@ public boolean isComplexMetric(String alias) { @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { final RelDataType rowType = protoRowType.apply(typeFactory); final List fieldNames = rowType.getFieldNames(); - Preconditions.checkArgument(fieldNames.contains(timestampFieldName)); - Preconditions.checkArgument(fieldNames.containsAll(metricFieldNames)); + checkArgument(fieldNames.contains(timestampFieldName)); + checkArgument(fieldNames.containsAll(metricFieldNames)); return rowType; } diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java index 02a6bf20fb32..c0f34e4ec878 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchema.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -43,6 +42,8 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import static com.google.common.base.Preconditions.checkArgument; + /** * Each table in the schema is an ELASTICSEARCH index. */ @@ -76,7 +77,7 @@ public ElasticsearchSchema(RestClient client, ObjectMapper mapper, String index) super(); this.client = Objects.requireNonNull(client, "client"); this.mapper = Objects.requireNonNull(mapper, "mapper"); - Preconditions.checkArgument(fetchSize > 0, + checkArgument(fetchSize > 0, "invalid fetch size. Expected %s > 0", fetchSize); this.fetchSize = fetchSize; diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java index d1cc87f721fb..052ddfb0b8e0 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java @@ -30,7 +30,6 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -56,6 +55,8 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; +import static com.google.common.base.Preconditions.checkArgument; + /** * Factory that creates an {@link ElasticsearchSchema}. * @@ -195,7 +196,7 @@ private static RestClient connect(List hosts, String pathPrefix, boolean disableSSLVerification) { Objects.requireNonNull(hosts, "hosts or coordinates"); - Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified"); + checkArgument(!hosts.isEmpty(), "no ES hosts specified"); // Two lists are considered equal when all of their corresponding elements are equal // making a list of RestClient params a suitable cache key. List cacheKey = ImmutableList.of(hosts, pathPrefix, username, password); diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/PredicateAnalyzer.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/PredicateAnalyzer.java index 95d829f4d562..9b9796857ca0 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/PredicateAnalyzer.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/PredicateAnalyzer.java @@ -32,7 +32,6 @@ import org.apache.calcite.util.NlsString; import org.apache.calcite.util.Sarg; -import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.Range; @@ -45,6 +44,9 @@ import java.util.Objects; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import static org.apache.calcite.adapter.elasticsearch.QueryBuilders.boolQuery; import static org.apache.calcite.adapter.elasticsearch.QueryBuilders.existsQuery; import static org.apache.calcite.adapter.elasticsearch.QueryBuilders.rangeQuery; @@ -283,7 +285,7 @@ static boolean isSearchWithComplementedPoints(RexCall search) { private static String convertQueryString(List fields, Expression query) { int index = 0; - Preconditions.checkArgument(query instanceof LiteralExpression, + checkArgument(query instanceof LiteralExpression, "Query string must be a string literal"); String queryString = ((LiteralExpression) query).stringValue(); @SuppressWarnings("ModifiedButNotUsed") @@ -303,7 +305,7 @@ private static String convertQueryString(List fields, Expression que } private QueryExpression prefix(RexCall call) { - Preconditions.checkArgument(call.getKind() == SqlKind.NOT, + checkArgument(call.getKind() == SqlKind.NOT, "Expected %s got %s", SqlKind.NOT, call.getKind()); if (call.getOperands().size() != 1) { @@ -316,7 +318,7 @@ private QueryExpression prefix(RexCall call) { } private QueryExpression postfix(RexCall call) { - Preconditions.checkArgument(call.getKind() == SqlKind.IS_NULL + checkArgument(call.getKind() == SqlKind.IS_NULL || call.getKind() == SqlKind.IS_NOT_NULL); if (call.getOperands().size() != 1) { String message = String.format(Locale.ROOT, "Unsupported operator: [%s]", call); @@ -349,7 +351,7 @@ private QueryExpression binary(RexCall call) { checkForIncompatibleDateTimeOperands(call); - Preconditions.checkState(call.getOperands().size() == 2); + checkState(call.getOperands().size() == 2); final Expression a = call.getOperands().get(0).accept(this); final Expression b = call.getOperands().get(1).accept(this); diff --git a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/Scrolling.java b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/Scrolling.java index a75c061df854..d44d32e50782 100644 --- a/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/Scrolling.java +++ b/elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/Scrolling.java @@ -17,7 +17,6 @@ package org.apache.calcite.adapter.elasticsearch; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.base.Preconditions; import com.google.common.collect.AbstractSequentialIterator; import com.google.common.collect.Iterators; @@ -26,6 +25,8 @@ import java.util.Objects; import java.util.function.Consumer; +import static com.google.common.base.Preconditions.checkArgument; + /** * "Iterator" which retrieves results lazily and in batches. Uses * Elastic Scrolling API @@ -41,7 +42,7 @@ class Scrolling { Scrolling(ElasticsearchTransport transport) { this.transport = Objects.requireNonNull(transport, "transport"); final int fetchSize = transport.fetchSize; - Preconditions.checkArgument(fetchSize > 0, + checkArgument(fetchSize > 0, "invalid fetch size. Expected %s > 0", fetchSize); this.fetchSize = fetchSize; } @@ -148,7 +149,7 @@ private SequentialIterator(final ElasticsearchJson.Result first, final ElasticsearchTransport transport, final long limit) { super(first); this.transport = transport; - Preconditions.checkArgument(limit >= 0, + checkArgument(limit >= 0, "limit: %s >= 0", limit); this.limit = limit; } diff --git a/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/EmbeddedElasticsearchNode.java b/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/EmbeddedElasticsearchNode.java index e79e9f33dcce..f17d56a75e82 100644 --- a/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/EmbeddedElasticsearchNode.java +++ b/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/EmbeddedElasticsearchNode.java @@ -18,8 +18,6 @@ import org.apache.calcite.util.TestUtil; -import com.google.common.base.Preconditions; - import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; @@ -40,6 +38,8 @@ import java.util.Collection; import java.util.Objects; +import static com.google.common.base.Preconditions.checkState; + import static java.util.Collections.emptyMap; /** @@ -107,7 +107,7 @@ public static synchronized EmbeddedElasticsearchNode create() { /** Starts the current node. */ public void start() { - Preconditions.checkState(!isStarted, "already started"); + checkState(!isStarted, "already started"); try { node.start(); this.isStarted = true; @@ -122,7 +122,7 @@ public void start() { * @return hostname/port for HTTP connection */ public TransportAddress httpAddress() { - Preconditions.checkState(isStarted, "node is not started"); + checkState(isStarted, "node is not started"); NodesInfoResponse response = client().admin().cluster().prepareNodesInfo() .execute().actionGet(); @@ -143,7 +143,7 @@ public TransportAddress httpAddress() { * @return current elastic search client */ public Client client() { - Preconditions.checkState(isStarted, "node is not started"); + checkState(isStarted, "node is not started"); return node.client(); } diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java index 0a401fdfc06f..cf549b587099 100644 --- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java +++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeFilter.java @@ -37,8 +37,6 @@ import org.apache.calcite.util.TimestampString; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; @@ -49,6 +47,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.sql.type.SqlTypeName.CHAR; /** @@ -219,8 +219,7 @@ private boolean useInSetQueryClause(List disjunctions) { /** Creates OQL {@code IN SET} predicate string. */ private String translateInSet(List disjunctions) { - Preconditions.checkArgument( - !disjunctions.isEmpty(), "empty disjunctions"); + checkArgument(!disjunctions.isEmpty(), "empty disjunctions"); RexNode firstNode = disjunctions.get(0); RexCall firstCall = (RexCall) firstNode; diff --git a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java index b407d3680883..cff828e73697 100644 --- a/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java +++ b/geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeRules.java @@ -40,7 +40,6 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.calcite.sql.validate.SqlValidatorUtil; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.immutables.value.Value; @@ -48,6 +47,8 @@ import java.util.ArrayList; import java.util.List; +import static com.google.common.base.Preconditions.checkArgument; + /** * Rules and relational operators for {@link GeodeRel#CONVENTION} * calling convention. @@ -153,7 +154,7 @@ protected GeodeProjectRule(Config config) { @Override public RelNode convert(RelNode rel) { final LogicalProject project = (LogicalProject) rel; - Preconditions.checkArgument(project.getVariablesSet().isEmpty(), + checkArgument(project.getVariablesSet().isEmpty(), "GeodeProject does now allow variables"); final RelTraitSet traitSet = project.getTraitSet().replace(getOutConvention()); diff --git a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java index 0191d2e9e605..5e1d893a7d2c 100644 --- a/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java +++ b/geode/src/test/java/org/apache/calcite/adapter/geode/rel/GeodeEmbeddedPolicy.java @@ -21,8 +21,6 @@ import org.apache.geode.distributed.AbstractLauncher; import org.apache.geode.distributed.ServerLauncher; -import com.google.common.base.Preconditions; - import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -35,6 +33,8 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import static com.google.common.base.Preconditions.checkState; + /** * Manages embedded Geode instance using native {@link ServerLauncher}. */ @@ -44,7 +44,7 @@ public class GeodeEmbeddedPolicy implements BeforeAllCallback, AfterAllCallback private GeodeEmbeddedPolicy(final ServerLauncher launcher) { Objects.requireNonNull(launcher, "launcher"); - Preconditions.checkState(!launcher.isRunning(), "Launcher process is already running"); + checkState(!launcher.isRunning(), "Launcher process is already running"); this.launcher = launcher; } @@ -92,7 +92,7 @@ Cache cache() { private void requireStatus(AbstractLauncher.Status expected) { final AbstractLauncher.Status current = launcher.status().getStatus(); - Preconditions.checkState(current == expected, + checkState(current == expected, "Expected state %s but got %s", expected, current); } diff --git a/innodb/src/main/java/org/apache/calcite/adapter/innodb/IndexCondition.java b/innodb/src/main/java/org/apache/calcite/adapter/innodb/IndexCondition.java index d650318a860d..7797dcda5882 100644 --- a/innodb/src/main/java/org/apache/calcite/adapter/innodb/IndexCondition.java +++ b/innodb/src/main/java/org/apache/calcite/adapter/innodb/IndexCondition.java @@ -166,7 +166,7 @@ public RelCollation getImplicitCollation() { */ private static RelCollation deduceImplicitCollation(List fieldNames, List indexColumnNames) { - checkState(fieldNames != null, "field names cannot be null"); + requireNonNull(fieldNames, "field names must not be null"); List keyCollations = new ArrayList<>(indexColumnNames.size()); for (String keyColumnName : indexColumnNames) { int fieldIndex = fieldNames.indexOf(keyColumnName); diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java b/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java index 12cc470c468d..638b1f5f913c 100644 --- a/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java +++ b/linq4j/src/main/java/org/apache/calcite/linq4j/ModularInteger.java @@ -16,10 +16,10 @@ */ package org.apache.calcite.linq4j; -import com.google.common.base.Preconditions; - import org.checkerframework.checker.nullness.qual.Nullable; +import static com.google.common.base.Preconditions.checkArgument; + /** * Represents an integer in modular arithmetic. * Its {@code value} is between 0 and {@code m - 1} for some modulus {@code m}. @@ -32,7 +32,7 @@ class ModularInteger { /** Creates a ModularInteger. */ ModularInteger(int value, int modulus) { - Preconditions.checkArgument(value >= 0 && value < modulus); + checkArgument(value >= 0 && value < modulus); this.value = value; this.modulus = modulus; } diff --git a/pig/src/main/java/org/apache/calcite/adapter/pig/PigFilter.java b/pig/src/main/java/org/apache/calcite/adapter/pig/PigFilter.java index 7726bcf58984..9c720aeb8442 100644 --- a/pig/src/main/java/org/apache/calcite/adapter/pig/PigFilter.java +++ b/pig/src/main/java/org/apache/calcite/adapter/pig/PigFilter.java @@ -27,11 +27,11 @@ import org.apache.calcite.rex.RexLiteral; import org.apache.calcite.rex.RexNode; -import com.google.common.base.Preconditions; - import java.util.ArrayList; import java.util.List; +import static com.google.common.base.Preconditions.checkState; + import static org.apache.calcite.sql.SqlKind.INPUT_REF; import static org.apache.calcite.sql.SqlKind.LITERAL; @@ -70,7 +70,7 @@ public PigFilter(RelOptCluster cluster, RelTraitSet traitSet, RelNode input, Rex * */ private String getPigFilterStatement(Implementor implementor) { - Preconditions.checkState(containsOnlyConjunctions(condition)); + checkState(containsOnlyConjunctions(condition)); String relationAlias = implementor.getPigRelationAlias(this); List filterConditionsConjunction = new ArrayList<>(); for (RexNode node : RelOptUtil.conjunctions(condition)) { diff --git a/pig/src/main/java/org/apache/calcite/adapter/pig/PigRelFactories.java b/pig/src/main/java/org/apache/calcite/adapter/pig/PigRelFactories.java index 991925d17cf2..b855efda4f14 100644 --- a/pig/src/main/java/org/apache/calcite/adapter/pig/PigRelFactories.java +++ b/pig/src/main/java/org/apache/calcite/adapter/pig/PigRelFactories.java @@ -31,12 +31,13 @@ import org.apache.calcite.util.ImmutableBitSet; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + /** Implementations of factories in {@link RelFactories} * for the Pig adapter. */ public class PigRelFactories { @@ -78,7 +79,7 @@ public static class PigFilterFactory implements RelFactories.FilterFactory { @Override public RelNode createFilter(RelNode input, RexNode condition, Set variablesSet) { - Preconditions.checkArgument(variablesSet.isEmpty(), + checkArgument(variablesSet.isEmpty(), "PigFilter does not allow variables"); final RelTraitSet traitSet = input.getTraitSet().replace(PigRel.CONVENTION); diff --git a/redis/src/main/java/org/apache/calcite/adapter/redis/RedisSchemaFactory.java b/redis/src/main/java/org/apache/calcite/adapter/redis/RedisSchemaFactory.java index bfc36ec2bb5c..6829714bb0b1 100644 --- a/redis/src/main/java/org/apache/calcite/adapter/redis/RedisSchemaFactory.java +++ b/redis/src/main/java/org/apache/calcite/adapter/redis/RedisSchemaFactory.java @@ -20,11 +20,11 @@ import org.apache.calcite.schema.SchemaFactory; import org.apache.calcite.schema.SchemaPlus; -import com.google.common.base.Preconditions; - import java.util.List; import java.util.Map; +import static com.google.common.base.Preconditions.checkArgument; + /** * Factory that creates a {@link RedisSchema}. * @@ -39,13 +39,13 @@ public RedisSchemaFactory() { @Override public Schema create(SchemaPlus schema, String name, Map operand) { - Preconditions.checkArgument(operand.get("tables") != null, + checkArgument(operand.get("tables") != null, "tables must be specified"); - Preconditions.checkArgument(operand.get("host") != null, + checkArgument(operand.get("host") != null, "host must be specified"); - Preconditions.checkArgument(operand.get("port") != null, + checkArgument(operand.get("port") != null, "port must be specified"); - Preconditions.checkArgument(operand.get("database") != null, + checkArgument(operand.get("database") != null, "database must be specified"); @SuppressWarnings("unchecked") List> tables = diff --git a/server/src/main/java/org/apache/calcite/server/ServerDdlExecutor.java b/server/src/main/java/org/apache/calcite/server/ServerDdlExecutor.java index a0808c9f6389..a2a326ca6b76 100644 --- a/server/src/main/java/org/apache/calcite/server/ServerDdlExecutor.java +++ b/server/src/main/java/org/apache/calcite/server/ServerDdlExecutor.java @@ -88,7 +88,6 @@ import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.checkerframework.checker.nullness.qual.Nullable; @@ -105,6 +104,8 @@ import java.util.Objects; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.util.Static.RESOURCE; /** Executes DDL commands. @@ -260,7 +261,7 @@ public void execute(SqlCreateForeignSchema create, final Schema subSchema; final String libraryName; if (create.type != null) { - Preconditions.checkArgument(create.library == null); + checkArgument(create.library == null); final String typeName = (String) value(create.type); final JsonSchema.Type type = Util.enumVal(JsonSchema.Type.class, @@ -282,7 +283,7 @@ public void execute(SqlCreateForeignSchema create, Arrays.toString(JsonSchema.Type.values()))); } } else { - Preconditions.checkArgument(create.library != null); + checkArgument(create.library != null); libraryName = (String) value(create.library); } final SchemaFactory schemaFactory = @@ -716,7 +717,7 @@ private ColumnDef(SqlNode expr, RelDataType type, this.expr = expr; this.type = type; this.strategy = Objects.requireNonNull(strategy, "strategy"); - Preconditions.checkArgument( + checkArgument( strategy == ColumnStrategy.NULLABLE || strategy == ColumnStrategy.NOT_NULLABLE || expr != null); diff --git a/testkit/src/main/java/org/apache/calcite/test/Matchers.java b/testkit/src/main/java/org/apache/calcite/test/Matchers.java index 4a7b44815574..0013437031a8 100644 --- a/testkit/src/main/java/org/apache/calcite/test/Matchers.java +++ b/testkit/src/main/java/org/apache/calcite/test/Matchers.java @@ -24,7 +24,6 @@ import org.apache.calcite.util.TestUtil; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.RangeSet; @@ -49,6 +48,7 @@ import java.util.regex.Pattern; import java.util.stream.StreamSupport; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.toImmutableList; import static org.hamcrest.CoreMatchers.equalTo; @@ -413,7 +413,7 @@ public static class IsWithin extends BaseMatcher { private final double epsilon; public IsWithin(T expectedValue, double epsilon) { - Preconditions.checkArgument(epsilon >= 0D); + checkArgument(epsilon >= 0D); this.expectedValue = expectedValue; this.epsilon = epsilon; } diff --git a/testkit/src/main/java/org/apache/calcite/test/RelMetadataFixture.java b/testkit/src/main/java/org/apache/calcite/test/RelMetadataFixture.java index 63f478429d4b..31a636b6c8b9 100644 --- a/testkit/src/main/java/org/apache/calcite/test/RelMetadataFixture.java +++ b/testkit/src/main/java/org/apache/calcite/test/RelMetadataFixture.java @@ -40,7 +40,6 @@ import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.util.ImmutableBitSet; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; @@ -58,6 +57,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; +import static com.google.common.base.Preconditions.checkArgument; + import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; @@ -196,7 +197,7 @@ public RelNode toRel() { metadataConfig.applyMetadata(rel.getCluster()); if (convertAsCalc) { Project project = (Project) rel; - Preconditions.checkArgument(project.getVariablesSet().isEmpty(), + checkArgument(project.getVariablesSet().isEmpty(), "Calc does not allow variables"); RexProgram program = RexProgram.create(project.getInput().getRowType(), diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlValidatorFixture.java b/testkit/src/main/java/org/apache/calcite/test/SqlValidatorFixture.java index 059db989be5d..71558b5cc3f3 100644 --- a/testkit/src/main/java/org/apache/calcite/test/SqlValidatorFixture.java +++ b/testkit/src/main/java/org/apache/calcite/test/SqlValidatorFixture.java @@ -46,14 +46,14 @@ import org.apache.calcite.util.TestUtil; import org.apache.calcite.util.Util; -import com.google.common.base.Preconditions; - import org.hamcrest.Matcher; import java.nio.charset.Charset; import java.util.List; import java.util.function.UnaryOperator; +import static com.google.common.base.Preconditions.checkArgument; + import static org.apache.calcite.sql.SqlUtil.stripAs; import static org.hamcrest.CoreMatchers.is; @@ -182,7 +182,7 @@ public SqlValidatorFixture withLenientOperatorLookup(boolean lenient) { } public SqlValidatorFixture withWhole(boolean whole) { - Preconditions.checkArgument(sap.cursor < 0); + checkArgument(sap.cursor < 0); final StringAndPos sap = StringAndPos.of("^" + this.sap.sql + "^"); return new SqlValidatorFixture(tester, factory, sap, expression, whole); } diff --git a/testkit/src/main/java/org/apache/calcite/test/catalog/MockCatalogReader.java b/testkit/src/main/java/org/apache/calcite/test/catalog/MockCatalogReader.java index 8f7e8f5ca94d..8b489f2bb0ee 100644 --- a/testkit/src/main/java/org/apache/calcite/test/catalog/MockCatalogReader.java +++ b/testkit/src/main/java/org/apache/calcite/test/catalog/MockCatalogReader.java @@ -105,6 +105,8 @@ import java.util.Map; import java.util.Set; +import static java.util.Objects.requireNonNull; + /** * Mock implementation of {@link SqlValidatorCatalogReader} which returns tables * "EMP", "DEPT", "BONUS", "SALGRADE" (same as Oracle's SCOTT schema). @@ -316,7 +318,7 @@ public static class MockTable extends Prepare.AbstractPreparingTable protected final Double maxRowCount; protected final Set monotonicColumnSet = new HashSet<>(); protected StructKind kind = StructKind.FULLY_QUALIFIED; - protected final ColumnResolver resolver; + protected final @Nullable ColumnResolver resolver; private final boolean temporal; protected final InitializerExpressionFactory initializerFactory; protected final Set rolledUpColumns = new HashSet<>(); @@ -328,7 +330,7 @@ public static class MockTable extends Prepare.AbstractPreparingTable public MockTable(MockCatalogReader catalogReader, String catalogName, String schemaName, String name, boolean stream, boolean temporal, - double rowCount, ColumnResolver resolver, + double rowCount, @Nullable ColumnResolver resolver, InitializerExpressionFactory initializerFactory) { this(catalogReader, ImmutableList.of(catalogName, schemaName, name), stream, temporal, rowCount, resolver, initializerFactory, @@ -350,7 +352,7 @@ public void registerRolledUpColumn(String columnName) { private MockTable(MockCatalogReader catalogReader, List names, boolean stream, boolean temporal, double rowCount, - ColumnResolver resolver, + @Nullable ColumnResolver resolver, InitializerExpressionFactory initializerFactory, List wraps, Double maxRowCount) { this.catalogReader = catalogReader; @@ -666,11 +668,13 @@ private class ModifiableTableWithCustomColumnResolving ModifiableTableWithCustomColumnResolving(String tableName) { super(tableName); + requireNonNull(resolver, "resolver"); } @Override public List>> resolveColumn( RelDataType rowType, RelDataTypeFactory typeFactory, List names) { + requireNonNull(resolver, "resolver"); return resolver.resolveColumn(rowType, typeFactory, names); } } @@ -700,7 +704,8 @@ private MockModifiableViewRelOptTable(MockModifiableViewTable modifiableViewTabl MockCatalogReader catalogReader, boolean stream, double rowCount, List> columnList, List keyList, RelDataType rowType, List collationList, List names, - Set monotonicColumnSet, StructKind kind, ColumnResolver resolver, + Set monotonicColumnSet, StructKind kind, + @Nullable ColumnResolver resolver, InitializerExpressionFactory initializerFactory) { super(catalogReader, stream, false, rowCount, columnList, keyList, rowType, collationList, names, @@ -911,9 +916,13 @@ private class ModifiableView extends AbstractModifiableView */ private class ModifiableViewWithCustomColumnResolving extends ModifiableView implements CustomColumnResolvingTable, Wrapper { + ModifiableViewWithCustomColumnResolving() { + requireNonNull(resolver, "resolver"); + } @Override public List>> resolveColumn( RelDataType rowType, RelDataTypeFactory typeFactory, List names) { + requireNonNull(resolver, "resolver"); return resolver.resolveColumn(rowType, typeFactory, names); } @@ -968,7 +977,8 @@ protected abstract RexNode getConstraint(RexBuilder rexBuilder, } /** - * Mock implementation of {@link AbstractQueryableTable} with dynamic record type. + * Mock implementation of {@link AbstractQueryableTable} with dynamic record + * type. */ public static class MockDynamicTable extends AbstractQueryableTable implements TranslatableTable { diff --git a/ubenchmark/src/jmh/java/org/apache/calcite/benchmarks/PreconditionTest.java b/ubenchmark/src/jmh/java/org/apache/calcite/benchmarks/PreconditionTest.java index 8f8ca1970137..e4975dd2c8e2 100644 --- a/ubenchmark/src/jmh/java/org/apache/calcite/benchmarks/PreconditionTest.java +++ b/ubenchmark/src/jmh/java/org/apache/calcite/benchmarks/PreconditionTest.java @@ -16,8 +16,6 @@ */ package org.apache.calcite.benchmarks; -import com.google.common.base.Preconditions; - import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Mode; @@ -29,6 +27,8 @@ import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; +import static com.google.common.base.Preconditions.checkState; + /** * Checks if silent precondition has noticeable overhead. */ @@ -40,7 +40,7 @@ public class PreconditionTest { @Benchmark public void testPrecondition() { - Preconditions.checkState(fire, "Hello %s", param); + checkState(fire, "Hello %s", param); } public static void main(String[] args) throws RunnerException {