Skip to content

Commit db28e84

Browse files
committed
[SQL] Remove all uses of assert, since it is not enforced at runtime
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 6cf0d5e commit db28e84

170 files changed

Lines changed: 672 additions & 541 deletions

File tree

Some content is hidden

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

sql-to-dbsp-compiler/SQL-compiler/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@
204204
<artifactId>commons-compiler</artifactId>
205205
<version>${janino.version}</version>
206206
</dependency>
207+
<dependency>
208+
<groupId>org.jetbrains</groupId>
209+
<artifactId>annotations</artifactId>
210+
<version>26.0.2</version>
211+
</dependency>
207212
<dependency>
208213
<groupId>com.jayway.jsonpath</groupId>
209214
<artifactId>json-path</artifactId>

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/CompilerMain.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
import org.dbsp.sqlCompiler.compiler.errors.CompilationError;
4141
import org.dbsp.sqlCompiler.compiler.errors.CompilerMessages;
4242
import org.dbsp.sqlCompiler.compiler.errors.SourcePositionRange;
43+
import org.dbsp.sqlCompiler.compiler.frontend.calciteCompiler.SqlToRelCompiler;
4344
import org.dbsp.util.IIndentStream;
4445
import org.dbsp.util.IndentStream;
46+
import org.dbsp.util.Logger;
4547
import org.dbsp.util.Utilities;
4648

4749
import javax.annotation.Nullable;
@@ -167,7 +169,7 @@ CompilerMessages run() throws SQLException {
167169
DBSPCircuit circuit = compiler.getFinalCircuit(false);
168170
if (compiler.hasErrors())
169171
return compiler.messages;
170-
assert circuit != null;
172+
Utilities.enforce(circuit != null);
171173
if (this.options.ioOptions.emitJsonSchema != null) {
172174
try {
173175
PrintStream outputStream = new PrintStream(
@@ -251,7 +253,7 @@ CompilerMessages run() throws SQLException {
251253
String outputPath = new File(outputFile).getAbsolutePath();
252254
if (options.ioOptions.multiCrates()) {
253255
// Generate globals/src/stubs.rs
254-
assert multiWriter != null;
256+
Utilities.enforce(multiWriter != null);
255257
String globals = multiWriter.getGlobalsName();
256258
stubs = Paths.get(outputPath).resolve(globals).resolve("src").resolve(DBSPCompiler.STUBS_FILE_NAME);
257259
} else {

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/DBSPCircuit.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public int getOutputCount() {
141141
public DBSPType getSingleOutputType() {
142142
List<DBSPSinkOperator> sinks = Linq.where(
143143
Linq.list(this.sinkOperators.values()), o -> !o.metadata.system);
144-
assert sinks.size() == 1: "Expected a single output, got " + sinks.size();
144+
Utilities.enforce(sinks.size() == 1, "Expected a single output, got " + sinks.size());
145145
return sinks.get(0).getType();
146146
}
147147

@@ -165,8 +165,8 @@ public void addOperator(DBSPOperator operator) {
165165
.append("Adding ")
166166
.appendSupplier(operator::toString)
167167
.newline();
168-
assert !this.operators.contains(operator):
169-
"Operator " + operator + " already inserted";
168+
Utilities.enforce(!this.operators.contains(operator),
169+
"Operator " + operator + " already inserted");
170170
this.operators.add(operator);
171171
DBSPSourceTableOperator source = operator.as(DBSPSourceTableOperator.class);
172172
if (source != null)

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/annotation/Annotation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public void asJson(JsonStream stream) {
2626

2727
@SuppressWarnings("unused")
2828
public static Annotation fromJson(JsonNode node) throws ClassNotFoundException {
29-
assert node.isObject();
29+
Utilities.enforce(node.isObject());
3030
ObjectNode object = (ObjectNode) node;
3131
JsonNode cls = object.get("class");
32-
assert cls != null : "Node does not have 'class' field: " + Utilities.toDepth(node, 1);
32+
Utilities.enforce(cls != null,
33+
"Node does not have 'class' field: " + Utilities.toDepth(node, 1));
3334
try {
3435
Class<?> clazz = Class.forName("org.dbsp.sqlCompiler.circuit.annotation." + cls.asText());
3536
Method method = clazz.getMethod("fromJson", JsonNode.class);

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPAntiJoinOperator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.dbsp.sqlCompiler.compiler.visitors.outer.CircuitVisitor;
1010
import org.dbsp.sqlCompiler.ir.expression.DBSPExpression;
1111
import org.dbsp.sqlCompiler.ir.type.DBSPType;
12+
import org.dbsp.util.Utilities;
1213

1314
import javax.annotation.Nullable;
1415
import java.util.List;
@@ -21,10 +22,13 @@ public DBSPAntiJoinOperator(CalciteRelNode node, OutputPort left, OutputPort rig
2122
// Inputs must be indexed
2223
left.getOutputIndexedZSetType();
2324
right.getOutputIndexedZSetType();
24-
assert left.getOutputIndexedZSetType().keyType.sameType(right.getOutputIndexedZSetType().keyType) :
25+
Utilities.enforce(left.getOutputIndexedZSetType()
26+
.keyType
27+
.sameType(right.getOutputIndexedZSetType()
28+
.keyType),
2529
"Anti join key types to not match\n" +
2630
left.getOutputIndexedZSetType().keyType + " and\n" +
27-
right.getOutputIndexedZSetType().keyType;
31+
right.getOutputIndexedZSetType().keyType);
2832
}
2933

3034
@Override

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPApply2Operator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.dbsp.sqlCompiler.ir.expression.DBSPClosureExpression;
1111
import org.dbsp.sqlCompiler.ir.expression.DBSPExpression;
1212
import org.dbsp.sqlCompiler.ir.type.DBSPType;
13+
import org.dbsp.util.Utilities;
1314

1415
import javax.annotation.Nullable;
1516
import java.util.List;
@@ -23,13 +24,14 @@ public final class DBSPApply2Operator extends DBSPBinaryOperator {
2324
public DBSPApply2Operator(CalciteRelNode node, DBSPClosureExpression function,
2425
OutputPort left, OutputPort right) {
2526
super(node, "apply2", function, function.getResultType(), false, left, right, false);
26-
assert function.parameters.length == 2: "Expected 2 parameters for function " + function;
27+
Utilities.enforce(function.parameters.length == 2,
28+
"Expected 2 parameters for function " + function);
2729
DBSPType param0Type = function.parameters[0].getType().deref();
28-
assert left.outputType().sameType(param0Type):
29-
"Parameter type " + param0Type + " does not match input type " + left.outputType();
30+
Utilities.enforce(left.outputType().sameType(param0Type),
31+
"Parameter type " + param0Type + " does not match input type " + left.outputType());
3032
DBSPType param1Type = function.parameters[1].getType().deref();
31-
assert right.outputType().sameType(param1Type):
32-
"Parameter type " + param1Type + " does not match input type " + right.outputType();
33+
Utilities.enforce(right.outputType().sameType(param1Type),
34+
"Parameter type " + param1Type + " does not match input type " + right.outputType());
3335
DBSPApplyOperator.noZsets(left.outputType());
3436
DBSPApplyOperator.noZsets(right.outputType());
3537
DBSPApplyOperator.noZsets(this.outputType());
@@ -45,7 +47,7 @@ public DBSPSimpleOperator withFunction(@Nullable DBSPExpression expression, DBSP
4547

4648
@Override
4749
public DBSPSimpleOperator withInputs(List<OutputPort> newInputs, boolean force) {
48-
assert newInputs.size() == 2: "Expected 2 inputs " + newInputs;
50+
Utilities.enforce(newInputs.size() == 2, "Expected 2 inputs " + newInputs);
4951
if (force || this.inputsDiffer(newInputs)) {
5052
return new DBSPApply2Operator(
5153
this.getRelNode(), this.getClosureFunction(),

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPApplyOperator.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.dbsp.sqlCompiler.ir.type.DBSPType;
1313
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeIndexedZSet;
1414
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeZSet;
15+
import org.dbsp.util.Utilities;
1516

1617
import javax.annotation.Nullable;
1718
import java.util.List;
@@ -29,21 +30,21 @@
2930
* In the type system such inputs would show up as ZSets or IndexedZSets. */
3031
public final class DBSPApplyOperator extends DBSPUnaryOperator {
3132
public static void noZsets(DBSPType type) {
32-
assert !type.is(DBSPTypeZSet.class);
33-
assert !type.is(DBSPTypeIndexedZSet.class);
33+
Utilities.enforce(!type.is(DBSPTypeZSet.class));
34+
Utilities.enforce(!type.is(DBSPTypeIndexedZSet.class));
3435
}
3536

3637
public DBSPApplyOperator(CalciteRelNode node, DBSPClosureExpression function,
3738
DBSPType outputType, OutputPort input, @Nullable String comment) {
3839
super(node, "apply", function, outputType, false, input, comment, false);
39-
assert function.parameters.length == 1: "Expected 1 parameter for function " + function;
40+
Utilities.enforce(function.parameters.length == 1, "Expected 1 parameter for function " + function);
4041
DBSPType paramType = function.parameters[0].getType().deref();
41-
assert input.outputType().sameType(paramType) :
42-
"Parameter type " + paramType + " does not match input type " + input.outputType();
42+
Utilities.enforce(input.outputType().sameType(paramType),
43+
"Parameter type " + paramType + " does not match input type " + input.outputType());
4344
noZsets(input.outputType());
4445
noZsets(this.outputType());
45-
assert function.getResultType().sameType(outputType) :
46-
"Function return type " + function.getResultType() + " does not match output type " + outputType;
46+
Utilities.enforce(function.getResultType().sameType(outputType),
47+
"Function return type " + function.getResultType() + " does not match output type " + outputType);
4748
}
4849

4950
public DBSPApplyOperator(CalciteRelNode node, DBSPClosureExpression function,
@@ -61,7 +62,7 @@ public DBSPSimpleOperator withFunction(@Nullable DBSPExpression expression, DBSP
6162

6263
@Override
6364
public DBSPSimpleOperator withInputs(List<OutputPort> newInputs, boolean force) {
64-
assert newInputs.size() == 1: "Expected 1 input " + newInputs;
65+
Utilities.enforce(newInputs.size() == 1, "Expected 1 input " + newInputs);
6566
if (force || this.inputsDiffer(newInputs)) {
6667
return new DBSPApplyOperator(
6768
this.getRelNode(), this.getClosureFunction(),

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPAsofJoinOperator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public DBSPAsofJoinOperator(CalciteRelNode node, DBSPTypeZSet outputType,
6262
// Note that the third argument of the function may not match in type the right join input:
6363
// if the join is left join, the argument is always nullable, even if the input is not.
6464
DBSPType[] argumentTypes = function.getType().to(DBSPTypeFunction.class).parameterTypes;
65-
assert argumentTypes.length == 3;
66-
assert leftTimestampIndex >= 0 &&
67-
leftTimestampIndex <= argumentTypes[1].to(DBSPTypeRef.class).deref().to(DBSPTypeTuple.class).size();
68-
assert rightTimestampIndex >= 0 &&
69-
rightTimestampIndex <= argumentTypes[2].to(DBSPTypeRef.class).deref().to(DBSPTypeTuple.class).size();
65+
Utilities.enforce(argumentTypes.length == 3);
66+
Utilities.enforce(leftTimestampIndex >= 0 &&
67+
leftTimestampIndex <= argumentTypes[1].to(DBSPTypeRef.class).deref().to(DBSPTypeTuple.class).size());
68+
Utilities.enforce(rightTimestampIndex >= 0 &&
69+
rightTimestampIndex <= argumentTypes[2].to(DBSPTypeRef.class).deref().to(DBSPTypeTuple.class).size());
7070
}
7171

7272
@Override
@@ -95,7 +95,7 @@ public DBSPSimpleOperator withFunction(@Nullable DBSPExpression expression, DBSP
9595

9696
@Override
9797
public DBSPSimpleOperator withInputs(List<OutputPort> newInputs, boolean force) {
98-
assert newInputs.size() == 2;
98+
Utilities.enforce(newInputs.size() == 2);
9999
if (force || this.inputsDiffer(newInputs))
100100
return new DBSPAsofJoinOperator(
101101
this.getRelNode(), this.getOutputZSetType(),

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPChainAggregateOperator.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.dbsp.sqlCompiler.ir.expression.DBSPClosureExpression;
1212
import org.dbsp.sqlCompiler.ir.type.DBSPType;
1313
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeIndexedZSet;
14+
import org.dbsp.util.Utilities;
1415

1516
import java.util.List;
1617

@@ -23,12 +24,12 @@ public DBSPChainAggregateOperator(CalciteRelNode node, DBSPClosureExpression ini
2324
DBSPClosureExpression function, DBSPType outputType, OutputPort source) {
2425
super(node, "chain_aggregate", function, outputType, false, source, true);
2526
this.init = init;
26-
assert init.parameters.length == 2;
27-
assert function.parameters.length == 3;
28-
assert init.getResultType().sameType(function.getResultType());
29-
assert outputType.is(DBSPTypeIndexedZSet.class);
30-
assert source.outputType().is(DBSPTypeIndexedZSet.class);
31-
assert source.getOutputIndexedZSetType().keyType.sameType(this.getOutputIndexedZSetType().keyType);
27+
Utilities.enforce(init.parameters.length == 2);
28+
Utilities.enforce(function.parameters.length == 3);
29+
Utilities.enforce(init.getResultType().sameType(function.getResultType()));
30+
Utilities.enforce(outputType.is(DBSPTypeIndexedZSet.class));
31+
Utilities.enforce(source.outputType().is(DBSPTypeIndexedZSet.class));
32+
Utilities.enforce(source.getOutputIndexedZSetType().keyType.sameType(this.getOutputIndexedZSetType().keyType));
3233
this.checkResultType(function, this.getOutputIndexedZSetType().elementType);
3334
}
3435

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/circuit/operator/DBSPChainOperator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class DBSPChainOperator extends DBSPUnaryOperator {
4141
public DBSPChainOperator(CalciteRelNode node, ComputationChain chain, boolean isMultiset, OutputPort source) {
4242
super(node, "chain" + chain.summary(), null, chain.getOutputType(), isMultiset, source);
4343
this.chain = chain;
44-
assert this.chain.size() > 1;
44+
Utilities.enforce(this.chain.size() > 1);
4545
}
4646

4747
public enum ComputationKind {
@@ -52,7 +52,7 @@ public enum ComputationKind {
5252

5353
public record Computation(ComputationKind kind, DBSPClosureExpression closure) {
5454
public Computation {
55-
assert closure.parameters.length == 1;
55+
Utilities.enforce(closure.parameters.length == 1);
5656
}
5757

5858
void checkInputType(DBSPType inputType) {
@@ -62,7 +62,7 @@ void checkInputType(DBSPType inputType) {
6262
if (zSet != null) {
6363
argType = zSet.elementType.ref();
6464
} else {
65-
assert iZSet != null;
65+
Utilities.enforce(iZSet != null);
6666
argType = iZSet.getKVRefType();
6767
}
6868
DBSPType paramType = closure.parameters[0].getType();
@@ -136,7 +136,7 @@ DBSPExpression call(DBSPCompiler compiler, DBSPClosureExpression closure, DBSPEx
136136
}
137137

138138
public DBSPClosureExpression collapse(DBSPCompiler compiler) {
139-
assert this.computations.size() > 1;
139+
Utilities.enforce(this.computations.size() > 1);
140140
DBSPVariablePath inputVar;
141141
DBSPExpression currentArg;
142142
if (this.inputType.is(DBSPTypeZSet.class)) {

0 commit comments

Comments
 (0)