|
22 | 22 | import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
|
23 | 23 | import org.apache.lucene.search.Query;
|
24 | 24 | import org.apache.lucene.store.Directory;
|
| 25 | +import org.elasticsearch.ElasticsearchParseException; |
25 | 26 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
26 | 27 | import org.elasticsearch.common.settings.Settings;
|
27 | 28 | import org.elasticsearch.common.time.DateFormatter;
|
@@ -143,6 +144,46 @@ private void doTestIsFieldWithinQuery(DateFieldType ft, DirectoryReader reader,
|
143 | 144 | assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(reader, "2015-10-12", "2016-04-03", false, false, zone, null, context));
|
144 | 145 | assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(reader, "2015-10-12", "2016-04-03", false, true, zone, null, context));
|
145 | 146 | assertEquals(Relation.INTERSECTS, ft.isFieldWithinQuery(reader, "2015-10-12", "2016-04-03", true, false, zone, null, context));
|
| 147 | + // Bad dates |
| 148 | + assertThrows( |
| 149 | + ElasticsearchParseException.class, |
| 150 | + () -> ft.isFieldWithinQuery(reader, "2015-00-01", "2016-04-03", randomBoolean(), randomBoolean(), zone, null, context) |
| 151 | + ); |
| 152 | + assertThrows( |
| 153 | + ElasticsearchParseException.class, |
| 154 | + () -> ft.isFieldWithinQuery(reader, "2015-01-01", "2016-04-00", randomBoolean(), randomBoolean(), zone, null, context) |
| 155 | + ); |
| 156 | + assertThrows( |
| 157 | + ElasticsearchParseException.class, |
| 158 | + () -> ft.isFieldWithinQuery(reader, "2015-22-01", "2016-04-00", randomBoolean(), randomBoolean(), zone, null, context) |
| 159 | + ); |
| 160 | + assertThrows( |
| 161 | + ElasticsearchParseException.class, |
| 162 | + () -> ft.isFieldWithinQuery(reader, "2015-01-01", "2016-04-45", randomBoolean(), randomBoolean(), zone, null, context) |
| 163 | + ); |
| 164 | + assertThrows( |
| 165 | + ElasticsearchParseException.class, |
| 166 | + () -> ft.isFieldWithinQuery(reader, "2015-01-01", "2016-04-01T25:00:00", randomBoolean(), randomBoolean(), zone, null, context) |
| 167 | + ); |
| 168 | + if (ft.resolution().equals(Resolution.NANOSECONDS)) { |
| 169 | + assertThrows( |
| 170 | + IllegalArgumentException.class, |
| 171 | + () -> ft.isFieldWithinQuery(reader, "-2016-04-01", "2016-04-01", randomBoolean(), randomBoolean(), zone, null, context) |
| 172 | + ); |
| 173 | + assertThrows( |
| 174 | + IllegalArgumentException.class, |
| 175 | + () -> ft.isFieldWithinQuery( |
| 176 | + reader, |
| 177 | + "9223372036854775807", |
| 178 | + "2016-04-01", |
| 179 | + randomBoolean(), |
| 180 | + randomBoolean(), |
| 181 | + zone, |
| 182 | + null, |
| 183 | + context |
| 184 | + ) |
| 185 | + ); |
| 186 | + } |
146 | 187 | }
|
147 | 188 |
|
148 | 189 | public void testValueFormat() {
|
|
0 commit comments