Skip to content

Commit 9fc6e3d

Browse files
committed
Merge branch '7.7' of github.com:gchq/stroom into 7.8
2 parents 67c4d94 + 70f04c3 commit 9fc6e3d

20 files changed

+218
-78
lines changed

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/AbstractAggregateFunction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public Val eval(final StoredValues storedValues, final Supplier<ChildData> child
109109
Val value = ValNull.INSTANCE;
110110
for (final Generator gen : childGenerators) {
111111
final Val val = gen.eval(storedValues, childDataSupplier);
112-
if (!val.type().isValue()) {
113-
return val;
114-
}
112+
// if (!val.type().isValue()) {
113+
// return val;
114+
// }
115115
value = calculator.calc(value, val);
116116
}
117117
return value;

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/AbstractEqualityFunction.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
abstract class AbstractEqualityFunction extends AbstractManyChildFunction {
2525

2626
private static final ValErr CHILD_ERROR = ValErr.create("Error evaluating child generator");
27-
private static final ValErr MISSING_VALUE = ValErr.create("Both values must have a value to test equality");
2827

2928
private final boolean usingOperator;
3029

@@ -91,8 +90,8 @@ public Val eval(final StoredValues storedValues, final Supplier<ChildData> child
9190
return CHILD_ERROR;
9291
}
9392

94-
if (!val.type().isValue()) {
95-
return ValErr.wrap(val, MISSING_VALUE);
93+
if (val.type().isError()) {
94+
return val;
9695
}
9796

9897
values[i] = val;

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/Add.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
commonReturnType = ValDouble.class,
2929
commonReturnDescription = "The sum of all values",
3030
commonDescription = "Adds the value of all arguments together. Minimum of two arguments. Can be expressed as " +
31-
"'${field1}+${field2}'.",
31+
"'${field1}+${field2}'.",
3232
signatures = @FunctionSignature(
3333
args = @FunctionArg(
3434
name = "arg",
@@ -64,9 +64,13 @@ static class Calc extends Calculator {
6464
Val calc(final Val current, final Val value) {
6565
try {
6666
if (Type.DURATION.equals(value.type())) {
67-
if (!current.type().isValue() || value.type().isError()) {
67+
if (value.type().isError() ||
68+
current.type().isNull()) {
6869
return value;
70+
} else if (current.type().isError()) {
71+
return current;
6972
}
73+
7074
final long milliseconds = value.toLong();
7175
final long diff = current.toLong() + milliseconds;
7276
if (Type.DATE.equals(current.type())) {

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/Calculator.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ abstract class Calculator {
2121

2222
Val calc(final Val current, final Val value) {
2323
try {
24-
if (value.type().isError()) {
24+
if (value.type().isError() ||
25+
current.type().isNull()) {
2526
return value;
27+
} else if (current.type().isError()) {
28+
return current;
2629
}
2730

2831
final Double cur = current.toDouble();

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/Equals.java

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package stroom.query.language.functions;
1818

19+
import java.util.Objects;
20+
1921
@SuppressWarnings("unused") //Used by FunctionFactory
2022
@FunctionDef(
2123
name = Equals.NAME,
@@ -59,6 +61,9 @@ private static class EqualsEvaluator extends Evaluator {
5961

6062
@Override
6163
protected Val evaluate(final Val a, final Val b) {
64+
if (Objects.equals(a, b)) {
65+
return ValBoolean.TRUE;
66+
}
6267

6368
final int compareResult = ValComparators.GENERIC_CASE_SENSITIVE_COMPARATOR.compare(a, b);
6469
return compareResult == 0

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/GreaterThan.java

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ private static class GreaterThanEvaluator extends Evaluator {
5959

6060
@Override
6161
protected Val evaluate(final Val a, final Val b) {
62+
if (a.type().isNull() || b.type().isNull()) {
63+
return ValBoolean.FALSE;
64+
}
6265

6366
final int compareResult = ValComparators.GENERIC_CASE_SENSITIVE_COMPARATOR.compare(a, b);
6467
return compareResult > 0

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/GreaterThanOrEqualTo.java

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package stroom.query.language.functions;
1818

19+
import java.util.Objects;
20+
1921
@SuppressWarnings("unused") //Used by FunctionFactory
2022
@FunctionDef(
2123
name = GreaterThanOrEqualTo.NAME,
@@ -60,6 +62,13 @@ private static class GreaterThanEvaluator extends Evaluator {
6062

6163
@Override
6264
protected Val evaluate(final Val a, final Val b) {
65+
if (a.type().isNull() || b.type().isNull()) {
66+
if (Objects.equals(a, b)) {
67+
return ValBoolean.TRUE;
68+
}
69+
return ValBoolean.FALSE;
70+
}
71+
6372
final int compareResult = ValComparators.GENERIC_CASE_SENSITIVE_COMPARATOR.compare(a, b);
6473
return compareResult >= 0
6574
? ValBoolean.TRUE

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/LessThan.java

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ private static class LessThanEvaluator extends Evaluator {
5959

6060
@Override
6161
protected Val evaluate(final Val a, final Val b) {
62+
if (a.type().isNull() || b.type().isNull()) {
63+
return ValBoolean.FALSE;
64+
}
65+
6266
final int compareResult = ValComparators.GENERIC_CASE_SENSITIVE_COMPARATOR.compare(a, b);
6367
return compareResult < 0
6468
? ValBoolean.TRUE

Diff for: stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/LessThanOrEqualTo.java

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package stroom.query.language.functions;
1818

19+
import java.util.Objects;
20+
1921
@SuppressWarnings("unused") //Used by FunctionFactory
2022
@FunctionDef(
2123
name = LessThanOrEqualTo.NAME,
@@ -59,6 +61,12 @@ private static class LessThanOrEqualToEvaluator extends Evaluator {
5961

6062
@Override
6163
protected Val evaluate(final Val a, final Val b) {
64+
if (a.type().isNull() || b.type().isNull()) {
65+
if (Objects.equals(a, b)) {
66+
return ValBoolean.TRUE;
67+
}
68+
return ValBoolean.FALSE;
69+
}
6270

6371
final int compareResult = ValComparators.GENERIC_CASE_SENSITIVE_COMPARATOR.compare(a, b);
6472
return compareResult <= 0

Diff for: stroom-query/stroom-query-language/src/test/java/stroom/query/language/functions/AbstractEqualityFunctionTest.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ Stream<TestCase> getTestCases() {
2828
.flatMap(values -> {
2929
final Object param1 = values.param1;
3030
final Object param2 = values.param2;
31-
if (!addInverseTest()) {
31+
if (!addInverseTest() || param1 == null || param2 == null) {
3232
return Stream.of(values);
3333
} else if (ValComparators.haveType(param1, param2, String.class)
34-
&& String.CASE_INSENSITIVE_ORDER.compare(
34+
&& String.CASE_INSENSITIVE_ORDER.compare(
3535
param1.toString(),
3636
param1.toString()) == 0) {
3737
return Stream.of(values);
3838
} else if (Objects.equals(param1, param2)) {
3939
return Stream.of(values);
4040
} else if ((param1 instanceof Number
41-
&& DoubleMath.fuzzyEquals(
41+
&& DoubleMath.fuzzyEquals(
4242
((Number) param1).doubleValue(),
4343
((Number) param2).doubleValue(),
4444
Val.FLOATING_POINT_EQUALITY_TOLERANCE))) {
@@ -61,17 +61,24 @@ protected TestCase buildCase(final Object param1,
6161
final boolean expectedOutcome) {
6262
return TestCase.convert(
6363
param1
64-
+ " (" + param1.getClass().getSimpleName() + ") "
65-
+ getOperator() + " "
66-
+ param2
67-
+ " (" + param2.getClass().getSimpleName() + ")"
68-
+ " => "
69-
+ expectedOutcome,
64+
+ " (" + getParamType(param1) + ") "
65+
+ getOperator() + " "
66+
+ param2
67+
+ " (" + getParamType(param2) + ")"
68+
+ " => "
69+
+ expectedOutcome,
7070
expectedOutcome,
7171
param1,
7272
param2);
7373
}
7474

75+
private String getParamType(final Object param) {
76+
if (param == null) {
77+
return "null";
78+
}
79+
return param.getClass().getSimpleName();
80+
}
81+
7582

7683
// --------------------------------------------------------------------------------
7784

Diff for: stroom-query/stroom-query-language/src/test/java/stroom/query/language/functions/TestEquals.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Stream<Values> getTestCaseValues() {
3333
Values.of(2, 2.0D, true),
3434
Values.of(2, 2F, true),
3535
Values.of(2, 2.0F, true),
36+
Values.of(2, null, false),
3637

3738
Values.of(2L, 1L, false),
3839
Values.of(2L, 1, false),
@@ -44,6 +45,7 @@ Stream<Values> getTestCaseValues() {
4445
Values.of(2L, 2.0D, true),
4546
Values.of(2L, 2F, true),
4647
Values.of(2L, 2.0F, true),
48+
Values.of(2L, null, false),
4749

4850
Values.of(1.2D, 1.1D, false),
4951
Values.of(1.2D, 1, false),
@@ -54,6 +56,7 @@ Stream<Values> getTestCaseValues() {
5456
Values.of(1D, 1, true),
5557
Values.of(1D, 1L, true),
5658
Values.of(1.1D, 1.1F, true),
59+
Values.of(1.1D, null, false),
5760

5861
Values.of(1.2F, 1.1F, false),
5962
Values.of(1.2F, 1, false),
@@ -63,16 +66,20 @@ Stream<Values> getTestCaseValues() {
6366
Values.of(1F, 1, true),
6467
Values.of(1F, 1L, true),
6568
Values.of(1.1F, 1.1D, true),
69+
Values.of(1.1F, null, false),
6670

6771
Values.of(true, false, false),
6872
Values.of(true, true, true),
73+
Values.of(true, null, false),
6974

7075
Values.of("dog", "cat", false),
7176
Values.of("CAT", "cat", false),
7277
Values.of("cat", "cat", true),
78+
Values.of("cat", null, false),
7379

7480
Values.of("1", "1", true),
7581
Values.of("1", "2", false),
82+
Values.of("1", null, false),
7683

7784
Values.of(true, "true", true),
7885
Values.of(true, 1, true),
@@ -81,17 +88,21 @@ Stream<Values> getTestCaseValues() {
8188
Values.of(true, 1.0F, true),
8289
Values.of(true, 1D, true),
8390
Values.of(true, 1.0D, true),
91+
Values.of(true, null, false),
8492

8593
Values.of(false, "false", true),
8694
Values.of(false, 0, true),
8795
Values.of(false, 0L, true),
8896
Values.of(false, 0F, true),
8997
Values.of(false, 0.0F, true),
9098
Values.of(false, 0.0D, true),
99+
Values.of(false, null, false),
91100

92101
Values.of(Duration.ofSeconds(2), Duration.ofSeconds(1), false),
93102
Values.of(Duration.ofSeconds(1), Duration.ofSeconds(1), true),
94-
Values.of(Duration.ofSeconds(1), 1_000, true)
103+
Values.of(Duration.ofSeconds(1), 1_000, true),
104+
105+
Values.of(null, null, true)
95106
);
96107
}
97108
}

0 commit comments

Comments
 (0)