Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class AbstractAggregationTestCase extends AbstractFunctionTestCa
* Use if possible, as this method may get updated with new checks in the future.
* </p>
*/
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(
List<TestCaseSupplier> suppliers,
boolean entirelyNullPreservesType,
PositionalErrorMessageSupplier positionalErrorMessageSupplier
Expand All @@ -74,13 +74,24 @@ protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultCh
);
}

// TODO: Remove and migrate everything to the method with all the parameters
/**
* @deprecated Use {@link #parameterSuppliersFromTypedDataWithDefaultChecks(List, boolean, PositionalErrorMessageSupplier)} instead.
* This method doesn't add all the default checks.
* Converts a list of test cases into a list of parameter suppliers.
* Also, adds a default set of extra test cases.
* <p>
* Use if possible, as this method may get updated with new checks in the future.
* </p>
*
* @param entirelyNullPreservesType See {@link #anyNullIsNull(boolean, List)}
*/
@Deprecated
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(List<TestCaseSupplier> suppliers) {
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(
// TODO remove after removing parameterSuppliersFromTypedDataWithDefaultChecks rename this to that.
List<TestCaseSupplier> suppliers,
boolean entirelyNullPreservesType
) {
return parameterSuppliersFromTypedData(anyNullIsNull(entirelyNullPreservesType, randomizeBytesRefsOffset(suppliers)));
}

protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(List<TestCaseSupplier> suppliers) {
return parameterSuppliersFromTypedData(withNoRowsExpectingNull(randomizeBytesRefsOffset(suppliers)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,6 @@
* which can be automatically tested against several scenarios (null handling, concurrency, etc).
*/
public abstract class AbstractScalarFunctionTestCase extends AbstractFunctionTestCase {

/**
* Converts a list of test cases into a list of parameter suppliers.
* Also, adds a default set of extra test cases.
* <p>
* Use if possible, as this method may get updated with new checks in the future.
* </p>
*
* @param entirelyNullPreservesType See {@link #anyNullIsNull(boolean, List)}
* @deprecated use {@link #parameterSuppliersFromTypedDataWithDefaultChecksNoErrors}
* and make a subclass of {@link ErrorsForCasesWithoutExamplesTestCase}.
* It's a <strong>long</strong> faster.
*/
@Deprecated
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
boolean entirelyNullPreservesType,
List<TestCaseSupplier> suppliers,
PositionalErrorMessageSupplier positionalErrorMessageSupplier
) {
return parameterSuppliersFromTypedData(
errorsForCasesWithoutExamples(
anyNullIsNull(entirelyNullPreservesType, randomizeBytesRefsOffset(suppliers)),
positionalErrorMessageSupplier
)
);
}

/**
* Converts a list of test cases into a list of parameter suppliers.
* Also, adds a default set of extra test cases.
Expand Down Expand Up @@ -113,30 +86,6 @@ protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultCh
return parameterSuppliersFromTypedData(anyNullIsNull(randomizeBytesRefsOffset(suppliers), nullsExpectedType, evaluatorToString));
}

/**
* Converts a list of test cases into a list of parameter suppliers.
* Also, adds a default set of extra test cases.
* <p>
* Use if possible, as this method may get updated with new checks in the future.
* </p>
*
* @param nullsExpectedType See {@link #anyNullIsNull(List, ExpectedType, ExpectedEvaluatorToString)}
* @param evaluatorToString See {@link #anyNullIsNull(List, ExpectedType, ExpectedEvaluatorToString)}
*/
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
ExpectedType nullsExpectedType,
ExpectedEvaluatorToString evaluatorToString,
List<TestCaseSupplier> suppliers,
PositionalErrorMessageSupplier positionalErrorMessageSupplier
) {
return parameterSuppliersFromTypedData(
errorsForCasesWithoutExamples(
anyNullIsNull(randomizeBytesRefsOffset(suppliers), nullsExpectedType, evaluatorToString),
positionalErrorMessageSupplier
)
);
}

public final void testEvaluate() {
assumeTrue("Can't build evaluator", testCase.canBuildEvaluator());
boolean readFloating = randomBoolean();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.expression.function.aggregate;

import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
import org.hamcrest.Matcher;

import java.util.List;
import java.util.Set;

import static org.hamcrest.Matchers.equalTo;

public class AvgErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
@Override
protected List<TestCaseSupplier> cases() {
return paramsToSuppliers(AvgTests.parameters());
}

@Override
protected Expression build(Source source, List<Expression> args) {
return new Avg(source, args.get(0));
}

@Override
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
return equalTo(typeErrorMessage(false, validPerPosition, signature, (v, p) -> "numeric except unsigned_long or counter types"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers, true, (v, p) -> "numeric except unsigned_long or counter types");
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static Iterable<Object[]> parameters() {
}

// "No rows" expects 0 here instead of null
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public static Iterable<Object[]> parameters() {
}

// "No rows" expects 0 here instead of null
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.expression.function.aggregate;

import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
import org.hamcrest.Matcher;

import java.util.List;
import java.util.Set;

import static org.hamcrest.Matchers.equalTo;

public class MaxErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
@Override
protected List<TestCaseSupplier> cases() {
return paramsToSuppliers(MaxTests.parameters());
}

@Override
protected Expression build(Source source, List<Expression> args) {
return new Max(source, args.get(0));
}

@Override
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
return equalTo(
typeErrorMessage(false, validPerPosition, signature, (v, p) -> "representable except unsigned_long and spatial types")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(
suppliers,
false,
(v, p) -> "representable except unsigned_long and spatial types"
);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Iterable<Object[]> parameters() {
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true)
).flatMap(List::stream).map(MedianAbsoluteDeviationTests::makeSupplier).toList();

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.expression.function.aggregate;

import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
import org.hamcrest.Matcher;

import java.util.List;
import java.util.Set;

import static org.hamcrest.Matchers.equalTo;

public class MinErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
@Override
protected List<TestCaseSupplier> cases() {
return paramsToSuppliers(MinTests.parameters());
}

@Override
protected Expression build(Source source, List<Expression> args) {
return new Min(source, args.get(0));
}

@Override
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
return equalTo(
typeErrorMessage(false, validPerPosition, signature, (v, p) -> "representable except unsigned_long and spatial types")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(
suppliers,
false,
(v, p) -> "representable except unsigned_long and spatial types"
);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.expression.function.aggregate;

import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
import org.hamcrest.Matcher;

import java.util.List;
import java.util.Set;

import static org.hamcrest.Matchers.equalTo;

public class PercentileErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
@Override
protected List<TestCaseSupplier> cases() {
return paramsToSuppliers(PercentileTests.parameters());
}

@Override
protected Expression build(Source source, List<Expression> args) {
return new Percentile(source, args.get(0), args.get(1));
}

@Override
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
return equalTo(typeErrorMessage(true, validPerPosition, signature, (v, p) -> "numeric except unsigned_long"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Iterable<Object[]> parameters() {
}
}

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers, false, (v, p) -> "numeric except unsigned_long");
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static Iterable<Object[]> parameters() {
).flatMap(List::stream).map(SpatialCentroidTests::makeSupplier).toList();

// The withNoRowsExpectingNull() cases don't work here, as this aggregator doesn't return nulls.
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static Iterable<Object[]> parameters() {
).flatMap(List::stream).map(SpatialExtentTests::makeSupplier).toList();

// The withNoRowsExpectingNull() cases don't work here, as this aggregator doesn't return nulls.
// return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedData(randomizeBytesRefsOffset(suppliers));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Iterable<Object[]> parameters() {
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true)
).flatMap(List::stream).map(StdDevTests::makeSupplier).collect(Collectors.toCollection(() -> suppliers));

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public static Iterable<Object[]> parameters() {
)
);

return parameterSuppliersFromTypedDataWithDefaultChecks(suppliers);
return parameterSuppliersFromTypedDataWithDefaultChecksNoErrors(suppliers);
}

@Override
Expand Down
Loading