|
35 | 35 | import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.GEO; |
36 | 36 | import static org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier.TypedData.MULTI_ROW_NULL; |
37 | 37 | import static org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier.TypedData.NULL; |
| 38 | +import static org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvSliceTests.randomGrid; |
38 | 39 | import static org.hamcrest.Matchers.equalTo; |
39 | 40 |
|
40 | 41 | public class MvContainsTests extends AbstractScalarFunctionTestCase { |
@@ -100,56 +101,24 @@ private static void ints(List<TestCaseSupplier> suppliers) { |
100 | 101 | } |
101 | 102 |
|
102 | 103 | private static void longs(List<TestCaseSupplier> suppliers) { |
103 | | - suppliers.add(new TestCaseSupplier(List.of(DataType.LONG, DataType.LONG), () -> { |
104 | | - List<Long> field1 = randomList(1, 10, ESTestCase::randomLong); |
105 | | - List<Long> field2 = randomList(1, 10, ESTestCase::randomLong); |
106 | | - var result = field1.containsAll(field2); |
107 | | - return new TestCaseSupplier.TestCase( |
108 | | - List.of( |
109 | | - new TestCaseSupplier.TypedData(field1, DataType.LONG, "field1"), |
110 | | - new TestCaseSupplier.TypedData(field2, DataType.LONG, "field2") |
111 | | - ), |
112 | | - "MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]", |
113 | | - DataType.BOOLEAN, |
114 | | - equalTo(result) |
115 | | - ); |
116 | | - })); |
117 | | - suppliers.add(new TestCaseSupplier(List.of(DataType.UNSIGNED_LONG, DataType.UNSIGNED_LONG), () -> { |
118 | | - List<Long> field1 = randomList(1, 10, ESTestCase::randomLong); |
119 | | - List<Long> field2 = randomList(1, 10, ESTestCase::randomLong); |
120 | | - var result = field1.containsAll(field2); |
121 | | - return new TestCaseSupplier.TestCase( |
122 | | - List.of( |
123 | | - new TestCaseSupplier.TypedData(field1, DataType.UNSIGNED_LONG, "field1"), |
124 | | - new TestCaseSupplier.TypedData(field2, DataType.UNSIGNED_LONG, "field2") |
125 | | - ), |
126 | | - "MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]", |
127 | | - DataType.BOOLEAN, |
128 | | - equalTo(result) |
129 | | - ); |
130 | | - })); |
131 | | - suppliers.add(new TestCaseSupplier(List.of(DataType.DATETIME, DataType.DATETIME), () -> { |
132 | | - List<Long> field1 = randomList(1, 10, ESTestCase::randomLong); |
133 | | - List<Long> field2 = randomList(1, 10, ESTestCase::randomLong); |
134 | | - var result = field1.containsAll(field2); |
135 | | - return new TestCaseSupplier.TestCase( |
136 | | - List.of( |
137 | | - new TestCaseSupplier.TypedData(field1, DataType.DATETIME, "field1"), |
138 | | - new TestCaseSupplier.TypedData(field2, DataType.DATETIME, "field2") |
139 | | - ), |
140 | | - "MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]", |
141 | | - DataType.BOOLEAN, |
142 | | - equalTo(result) |
143 | | - ); |
144 | | - })); |
145 | | - suppliers.add(new TestCaseSupplier(List.of(DataType.DATE_NANOS, DataType.DATE_NANOS), () -> { |
146 | | - List<Long> field1 = randomList(1, 10, ESTestCase::randomNonNegativeLong); |
147 | | - List<Long> field2 = randomList(1, 10, ESTestCase::randomNonNegativeLong); |
| 104 | + addLongTestCase(suppliers, DataType.LONG, ESTestCase::randomLong); |
| 105 | + addLongTestCase(suppliers, DataType.UNSIGNED_LONG, ESTestCase::randomLong); |
| 106 | + addLongTestCase(suppliers, DataType.DATETIME, ESTestCase::randomLong); |
| 107 | + addLongTestCase(suppliers, DataType.DATE_NANOS, ESTestCase::randomNonNegativeLong); |
| 108 | + for (DataType gridType : new DataType[] { DataType.GEOHASH, DataType.GEOTILE, DataType.GEOHEX }) { |
| 109 | + addLongTestCase(suppliers, gridType, () -> randomGrid(gridType)); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + private static void addLongTestCase(List<TestCaseSupplier> suppliers, DataType dataType, Supplier<Long> longSupplier) { |
| 114 | + suppliers.add(new TestCaseSupplier(List.of(dataType, dataType), () -> { |
| 115 | + List<Long> field1 = randomList(1, 10, longSupplier); |
| 116 | + List<Long> field2 = randomList(1, 10, longSupplier); |
148 | 117 | var result = field1.containsAll(field2); |
149 | 118 | return new TestCaseSupplier.TestCase( |
150 | 119 | List.of( |
151 | | - new TestCaseSupplier.TypedData(field1, DataType.DATE_NANOS, "field1"), |
152 | | - new TestCaseSupplier.TypedData(field2, DataType.DATE_NANOS, "field2") |
| 120 | + new TestCaseSupplier.TypedData(field1, dataType, "field1"), |
| 121 | + new TestCaseSupplier.TypedData(field2, dataType, "field2") |
153 | 122 | ), |
154 | 123 | "MvContainsLongEvaluator[field1=Attribute[channel=0], field2=Attribute[channel=1]]", |
155 | 124 | DataType.BOOLEAN, |
|
0 commit comments