forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Esql - rework date diff tests (elastic#120328)
In preparation for adding nanosecond date support to date diff, this PR expands the test coverage and better integrates with the test generation framework. Using random data for date diff is extremely difficult, due to the vast range of units and the constraints of the integer return type. For example, nanosecond resolution differences of more than a couple of seconds will overflow the return value. So, instead of using a fully randomized dataset, I took the existing data set we were running against just the processing function, and formalized that to run against the whole test suite. It should be easy from here to add in cases for the same values as nanoseconds. I was able to integrate the overflow error case into the normal test framework, but the incorrect unit error doesn't play nicely with the framework (I believe this is because it fails in toEvaluator rather than in process, but I didn't dig in much). I've moved it to another test file so we don't run it for every case in the parameterized test file. --------- Co-authored-by: elasticsearchmachine <[email protected]>
- Loading branch information
1 parent
aea4853
commit f9ccb89
Showing
2 changed files
with
155 additions
and
122 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...a/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateDiffFunctionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.scalar.date; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
/** | ||
* Tests for {@link DateDiff} that should not run through the normal testing framework | ||
*/ | ||
public class DateDiffFunctionTests extends ESTestCase { | ||
|
||
public void testDateDiffFunctionErrorUnitNotValid() { | ||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> DateDiff.process(new BytesRef("sseconds"), 0, 0)); | ||
assertThat( | ||
e.getMessage(), | ||
containsString( | ||
"Received value [sseconds] is not valid date part to add; " | ||
+ "did you mean [seconds, second, nanoseconds, milliseconds, microseconds, nanosecond]?" | ||
) | ||
); | ||
|
||
e = expectThrows(IllegalArgumentException.class, () -> DateDiff.process(new BytesRef("not-valid-unit"), 0, 0)); | ||
assertThat( | ||
e.getMessage(), | ||
containsString( | ||
"A value of [YEAR, QUARTER, MONTH, DAYOFYEAR, DAY, WEEK, WEEKDAY, HOUR, MINUTE, SECOND, MILLISECOND, MICROSECOND, " | ||
+ "NANOSECOND] or their aliases is required; received [not-valid-unit]" | ||
) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters