Skip to content

Commit 4b3b45d

Browse files
committed
WIP: core nullability
1 parent 696d8f1 commit 4b3b45d

File tree

120 files changed

+628
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+628
-355
lines changed

core/src/main/java/org/apache/calcite/adapter/clone/ColumnLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public int size() {
196196
// We have discovered a the first unique key in the table.
197197
sort[0] = pair.i;
198198
final Comparable[] values =
199-
valueSet.values.toArray(new Comparable[list.size()]);
199+
valueSet.values.toArray(new Comparable[0]);
200200
final Kev[] kevs = new Kev[list.size()];
201201
for (int i = 0; i < kevs.length; i++) {
202202
kevs[i] = new Kev(i, values[i]);

core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import com.google.common.collect.Multimap;
4949
import com.google.common.collect.Ordering;
5050

51+
import org.checkerframework.checker.nullness.qual.Nullable;
52+
5153
import java.sql.Connection;
5254
import java.sql.DatabaseMetaData;
5355
import java.sql.ResultSet;
@@ -481,15 +483,15 @@ protected Map<String, RelProtoDataType> getTypes() {
481483
return ImmutableMap.of();
482484
}
483485

484-
@Override public RelProtoDataType getType(String name) {
486+
@Override public @Nullable RelProtoDataType getType(String name) {
485487
return getTypes().get(name);
486488
}
487489

488490
@Override public Set<String> getTypeNames() {
489491
return getTypes().keySet();
490492
}
491493

492-
public Schema getSubSchema(String name) {
494+
public @Nullable Schema getSubSchema(String name) {
493495
// JDBC does not support sub-schemas.
494496
return null;
495497
}

core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static Function1<ResultSet, Function0<Object[]>> factory(
117117
try {
118118
return new ObjectArrayRowBuilder(
119119
resultSet,
120-
Pair.left(list).toArray(new ColumnMetaData.Rep[list.size()]),
120+
Pair.left(list).toArray(new ColumnMetaData.Rep[0]),
121121
Ints.toArray(Pair.right(list)));
122122
} catch (SQLException e) {
123123
throw new RuntimeException(e);

core/src/main/java/org/apache/calcite/interpreter/BindableConvention.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.calcite.plan.RelTraitSet;
2525
import org.apache.calcite.rel.RelNode;
2626

27+
import org.checkerframework.checker.nullness.qual.Nullable;
28+
2729
/**
2830
* Calling convention that returns results as an
2931
* {@link org.apache.calcite.linq4j.Enumerable} of object arrays.
@@ -52,7 +54,7 @@ public String getName() {
5254
return "BINDABLE";
5355
}
5456

55-
@Override public RelNode enforce(RelNode input, RelTraitSet required) {
57+
@Override public @Nullable RelNode enforce(RelNode input, RelTraitSet required) {
5658
return null;
5759
}
5860

core/src/main/java/org/apache/calcite/interpreter/Context.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919
import org.apache.calcite.DataContext;
2020

21+
import org.checkerframework.checker.nullness.qual.Nullable;
22+
2123
/**
2224
* Context for executing a scalar expression in an interpreter.
2325
*/
2426
public class Context {
2527
public final DataContext root;
2628

2729
/** Values of incoming columns from all inputs. */
28-
public Object[] values;
30+
public Object @Nullable [] values;
2931

3032
Context(DataContext root) {
3133
this.root = root;

core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.google.common.collect.ImmutableSortedMap;
3434
import com.google.common.collect.ImmutableSortedSet;
3535

36+
import org.checkerframework.checker.nullness.qual.Nullable;
37+
3638
import java.util.Collection;
3739
import java.util.List;
3840
import java.util.Set;
@@ -50,11 +52,11 @@ class CachingCalciteSchema extends CalciteSchema {
5052
private boolean cache = true;
5153

5254
/** Creates a CachingCalciteSchema. */
53-
CachingCalciteSchema(CalciteSchema parent, Schema schema, String name) {
55+
CachingCalciteSchema(@Nullable CalciteSchema parent, Schema schema, String name) {
5456
this(parent, schema, name, null, null, null, null, null, null, null, null);
5557
}
5658

57-
private CachingCalciteSchema(CalciteSchema parent, Schema schema,
59+
private CachingCalciteSchema(@Nullable CalciteSchema parent, Schema schema,
5860
String name, NameMap<CalciteSchema> subSchemaMap,
5961
NameMap<TableEntry> tableMap, NameMap<LatticeEntry> latticeMap, NameMap<TypeEntry> typeMap,
6062
NameMultimap<FunctionEntry> functionMap, NameSet functionNames,

core/src/main/java/org/apache/calcite/jdbc/CalcitePrepare.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import com.google.common.base.Preconditions;
5151
import com.google.common.collect.ImmutableList;
5252

53+
import org.checkerframework.checker.nullness.qual.Nullable;
54+
5355
import java.lang.reflect.InvocationTargetException;
5456
import java.lang.reflect.Method;
5557
import java.lang.reflect.Type;
@@ -58,6 +60,8 @@
5860
import java.util.List;
5961
import java.util.Map;
6062

63+
import static org.apache.calcite.linq4j.Nullness.assertNonNull;
64+
6165
/**
6266
* API for a service that prepares statements for execution.
6367
*/
@@ -172,7 +176,7 @@ private static SparkHandler createHandler() {
172176
final Class<?> clazz =
173177
Class.forName("org.apache.calcite.adapter.spark.SparkHandlerImpl");
174178
Method method = clazz.getMethod("instance");
175-
return (CalcitePrepare.SparkHandler) method.invoke(null);
179+
return (CalcitePrepare.SparkHandler) assertNonNull(method.invoke(null));
176180
} catch (ClassNotFoundException e) {
177181
return new TrivialSparkHandler();
178182
} catch (IllegalAccessException
@@ -341,7 +345,7 @@ public CalciteSignature(String sql,
341345
List<RelCollation> collationList,
342346
long maxRowCount,
343347
Bindable<T> bindable,
344-
Meta.StatementType statementType) {
348+
Meta.@Nullable StatementType statementType) {
345349
super(columns, sql, parameterList, internalParameters, cursorFactory,
346350
statementType);
347351
this.rowType = rowType;
@@ -372,11 +376,11 @@ public List<RelCollation> getCollationList() {
372376
*
373377
* @param <T> element type */
374378
class Query<T> {
375-
public final String sql;
376-
public final Queryable<T> queryable;
377-
public final RelNode rel;
379+
public final @Nullable String sql;
380+
public final @Nullable Queryable<T> queryable;
381+
public final @Nullable RelNode rel;
378382

379-
private Query(String sql, Queryable<T> queryable, RelNode rel) {
383+
private Query(@Nullable String sql, @Nullable Queryable<T> queryable, @Nullable RelNode rel) {
380384
this.sql = sql;
381385
this.queryable = queryable;
382386
this.rel = rel;

core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import com.google.common.collect.ImmutableSortedSet;
4242
import com.google.common.collect.Lists;
4343

44+
import org.checkerframework.checker.nullness.qual.Nullable;
45+
4446
import java.util.ArrayList;
4547
import java.util.Collection;
4648
import java.util.List;
@@ -58,7 +60,7 @@
5860
*/
5961
public abstract class CalciteSchema {
6062

61-
private final CalciteSchema parent;
63+
private final @Nullable CalciteSchema parent;
6264
public final Schema schema;
6365
public final String name;
6466
/** Tables explicitly defined in this schema. Does not include tables in
@@ -70,14 +72,18 @@ public abstract class CalciteSchema {
7072
protected final NameSet functionNames;
7173
protected final NameMap<FunctionEntry> nullaryFunctionMap;
7274
protected final NameMap<CalciteSchema> subSchemaMap;
73-
private List<? extends List<String>> path;
74-
75-
protected CalciteSchema(CalciteSchema parent, Schema schema,
76-
String name, NameMap<CalciteSchema> subSchemaMap,
77-
NameMap<TableEntry> tableMap, NameMap<LatticeEntry> latticeMap, NameMap<TypeEntry> typeMap,
78-
NameMultimap<FunctionEntry> functionMap, NameSet functionNames,
79-
NameMap<FunctionEntry> nullaryFunctionMap,
80-
List<? extends List<String>> path) {
75+
private @Nullable List<? extends List<String>> path;
76+
77+
protected CalciteSchema(@Nullable CalciteSchema parent, Schema schema,
78+
String name,
79+
@Nullable NameMap<CalciteSchema> subSchemaMap,
80+
@Nullable NameMap<TableEntry> tableMap,
81+
@Nullable NameMap<LatticeEntry> latticeMap,
82+
@Nullable NameMap<TypeEntry> typeMap,
83+
@Nullable NameMultimap<FunctionEntry> functionMap,
84+
@Nullable NameSet functionNames,
85+
@Nullable NameMap<FunctionEntry> nullaryFunctionMap,
86+
@Nullable List<? extends List<String>> path) {
8187
this.parent = parent;
8288
this.schema = schema;
8389
this.name = name;
@@ -662,7 +668,7 @@ public NavigableSet<String> getTableNames() {
662668
return CalciteSchema.this.getTableNames();
663669
}
664670

665-
@Override public RelProtoDataType getType(String name) {
671+
@Override public @Nullable RelProtoDataType getType(String name) {
666672
final TypeEntry entry = CalciteSchema.this.getType(name, true);
667673
return entry == null ? null : entry.getType();
668674
}
@@ -679,7 +685,7 @@ public NavigableSet<String> getFunctionNames() {
679685
return CalciteSchema.this.getFunctionNames();
680686
}
681687

682-
public SchemaPlus getSubSchema(String name) {
688+
public @Nullable SchemaPlus getSubSchema(String name) {
683689
final CalciteSchema subSchema =
684690
CalciteSchema.this.getSubSchema(name, true);
685691
return subSchema == null ? null : subSchema.plus();

core/src/main/java/org/apache/calcite/jdbc/JavaCollation.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.apache.calcite.sql.SqlCollation;
2020

21+
import org.checkerframework.checker.initialization.qual.UnderInitialization;
22+
import org.checkerframework.checker.nullness.qual.Nullable;
23+
2124
import java.nio.charset.Charset;
2225
import java.text.Collator;
2326
import java.util.Locale;
@@ -55,11 +58,13 @@ private static String getStrengthString(int strengthValue) {
5558
}
5659
}
5760

58-
@Override protected String generateCollationName(Charset charset) {
61+
@Override protected String generateCollationName(
62+
@UnderInitialization(SqlCollation.class) JavaCollation this,
63+
Charset charset) {
5964
return super.generateCollationName(charset) + "$JAVA_COLLATOR";
6065
}
6166

62-
@Override public Collator getCollator() {
67+
@Override public @Nullable Collator getCollator() {
6368
return collator;
6469
}
6570
}

core/src/main/java/org/apache/calcite/package-info.java

+7
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@
1818
/**
1919
* Main package for Calcite, the dynamic data management platform.
2020
*/
21+
@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.FIELD)
22+
@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.PARAMETER)
23+
@DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.RETURN)
2124
package org.apache.calcite;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.checkerframework.framework.qual.DefaultQualifier;
28+
import org.checkerframework.framework.qual.TypeUseLocation;

core/src/main/java/org/apache/calcite/plan/Convention.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.apache.calcite.rel.RelNode;
2020
import org.apache.calcite.rel.core.RelFactories;
2121

22+
import org.checkerframework.checker.nullness.qual.Nullable;
23+
2224
/**
2325
* Calling convention trait.
2426
*/
@@ -48,7 +50,7 @@ public interface Convention extends RelTrait {
4850
* or {@code null} if trait enforcement is not allowed or the
4951
* required traitSet can't be satisfied.
5052
*/
51-
default RelNode enforce(RelNode input, RelTraitSet required) {
53+
default @Nullable RelNode enforce(RelNode input, RelTraitSet required) {
5254
throw new RuntimeException(getClass().getName()
5355
+ "#enforce() is not implemented.");
5456
}

core/src/main/java/org/apache/calcite/plan/RelOptPlanner.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.calcite.util.CancelFlag;
2525
import org.apache.calcite.util.trace.CalciteTrace;
2626

27+
import org.checkerframework.checker.nullness.qual.Nullable;
2728
import org.slf4j.Logger;
2829

2930
import java.util.List;
@@ -249,7 +250,7 @@ RelNode register(
249250
* @param equivRel Relational expression it is equivalent to (may be null)
250251
* @return Registered relational expression
251252
*/
252-
RelNode ensureRegistered(RelNode rel, RelNode equivRel);
253+
RelNode ensureRegistered(RelNode rel, @Nullable RelNode equivRel);
253254

254255
/**
255256
* Determines whether a relational expression has been registered.

core/src/main/java/org/apache/calcite/plan/RelOptRule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public boolean matches(RelOptRuleCall call) {
550550
* @return Convention of the result of firing this rule, null if
551551
* not known
552552
*/
553-
public Convention getOutConvention() {
553+
public @Nullable Convention getOutConvention() {
554554
return null;
555555
}
556556

@@ -561,7 +561,7 @@ public Convention getOutConvention() {
561561
* @return Trait which will be modified as a result of firing this rule,
562562
* or null if the rule is not a converter rule
563563
*/
564-
public RelTrait getOutTrait() {
564+
public @Nullable RelTrait getOutTrait() {
565565
return null;
566566
}
567567

core/src/main/java/org/apache/calcite/plan/RelOptRuleCall.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.collect.ImmutableList;
2727
import com.google.common.collect.ImmutableMap;
2828

29+
import org.checkerframework.checker.nullness.qual.Nullable;
2930
import org.slf4j.Logger;
3031

3132
import java.util.HashMap;
@@ -54,7 +55,7 @@ public abstract class RelOptRuleCall {
5455
public final RelOptRule rule;
5556
public final RelNode[] rels;
5657
private final RelOptPlanner planner;
57-
private final List<RelNode> parents;
58+
private final @Nullable List<RelNode> parents;
5859

5960
//~ Constructors -----------------------------------------------------------
6061

@@ -77,7 +78,7 @@ protected RelOptRuleCall(
7778
RelOptRuleOperand operand,
7879
RelNode[] rels,
7980
Map<RelNode, List<RelNode>> nodeInputs,
80-
List<RelNode> parents) {
81+
@Nullable List<RelNode> parents) {
8182
this.id = nextId++;
8283
this.planner = planner;
8384
this.operand0 = operand;
@@ -171,7 +172,7 @@ public <T extends RelNode> T rel(int ordinal) {
171172
* @param rel Relational expression
172173
* @return Children of relational expression
173174
*/
174-
public List<RelNode> getChildRels(RelNode rel) {
175+
public @Nullable List<RelNode> getChildRels(RelNode rel) {
175176
return nodeInputs.get(rel);
176177
}
177178

@@ -221,7 +222,7 @@ public RelMetadataQuery getMetadataQuery() {
221222
/**
222223
* Returns a list of parents of the first relational expression.
223224
*/
224-
public List<RelNode> getParents() {
225+
public @Nullable List<RelNode> getParents() {
225226
return parents;
226227
}
227228

0 commit comments

Comments
 (0)