[ESQL] Remove Named Expcted Types map from testing infrastructure #111213
Conversation
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
| } | ||
|
|
||
| @FunctionalInterface | ||
| protected interface PositionalErrorMessageSupplier { |
There was a problem hiding this comment.
Probably wants javadoc given the number of places we're using it.
| boolean entirelyNullPreservesType, | ||
| List<TestCaseSupplier> suppliers | ||
| List<TestCaseSupplier> suppliers, | ||
| PositionalErrorMessageSupplier positionalErrorMessageSupplier |
| (v, p) -> switch (p) { | ||
| case 0 -> "string"; | ||
| case 1 -> "datetime"; | ||
| default -> ""; |
There was a problem hiding this comment.
so we get to the default if the code that figures out which position has the bad argument comes up with a number higher than the number of arguments. Like if it says "the fourth argument to + is bad". That should really never happen, and I didn't put a lot of thought into what to do if it did, I just made the switch expression happy.
There was a problem hiding this comment.
I tend to make them happy by throwing if I don't expect it. I suppose in this case it's not a big difference.
| geoShape(cases, "mv_first", "MvFirst", DataType.GEO_SHAPE, (size, values) -> equalTo(values.findFirst().get())); | ||
| cartesianShape(cases, "mv_first", "MvFirst", DataType.CARTESIAN_SHAPE, (size, values) -> equalTo(values.findFirst().get())); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases, (v, p) -> ""); |
There was a problem hiding this comment.
Should this throw? Maybe say something like all types are valid or something.
There was a problem hiding this comment.
I mean, this will fail if a type ends up not being valid. The function will generate an error message with the string "representable" here, which will not match the test's expected empty string. Throwing from here doesn't really make that any clearer in my opinion? But I'm open to discuss.
| unsignedLongs(cases, "mv_max", "MvMax", (size, values) -> equalTo(values.reduce(BigInteger::max).get())); | ||
| dateTimes(cases, "mv_max", "MvMax", (size, values) -> equalTo(values.max().getAsLong())); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases, (v, p) -> "representableNonSpatial"); |
| o, | ||
| v, | ||
| t, | ||
| (l, p) -> "datetime, double, integer, ip, keyword, long, text, unsigned_long or version" |
There was a problem hiding this comment.
This might be better off returning a closure. But not sure.
There was a problem hiding this comment.
I poked around at it a bit, I didn't think it looked all that much better. Please feel free to submit a follow up that cleans it up if you want.
ivancea
left a comment
There was a problem hiding this comment.
LGTM.
However, I feel like we're missing the possibility to standardize the error messages here. The current solution is far from ideal, but somehow guides you into using an specific format. I wonder if we could go towards some more strict generation, like using the @Param data to generate it.
Just speaking aloud. The only part I don't "like" here is that we're decentralizing the messages, which be make more tedious to undo later, if we want to do that
| unsignedLongs(cases, "mv_min", "MvMin", (size, values) -> equalTo(values.reduce(BigInteger::min).get())); | ||
| dateTimes(cases, "mv_min", "MvMin", (size, values) -> equalTo(values.min().getAsLong())); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases); | ||
| return parameterSuppliersFromTypedDataWithDefaultChecks(false, cases, (v, p) -> "representableNonSpatial"); |
There was a problem hiding this comment.
I think this message is wrong (?), shouldn't it be human-readable?
There was a problem hiding this comment.
It is wrong, but let's grab it in a follow up, I think.
There was a problem hiding this comment.
yes, it should. But again, this is just putting the string into the test, not changing the string that the function currently sends on type error. I do think it's worth spending some time to review our type errors and update them, but that's not the goal of this PR.
I think we can get that by making some "canned" error message suppliers or something like that. That way places that aren't standard can use this and that are can provide the closure with a named method call. But I think this is a step in the right direction. |
Just to be clear, the code that's being removed was never involved in generating the actual error messages. It was just being used to guess the error message for the test to validate. The error messages were always generated within the type checking infrastructure, on each function. See, for example, MvMax#resolveFieldType |
* main: (39 commits) Update README.asciidoc (elastic#111244) ESQL: INLINESTATS (elastic#109583) ESQL: Document a little of `DataType` (elastic#111250) Relax assertions in segment level field stats (elastic#111243) LogsDB data generator - support nested object field (elastic#111206) Validate `Authorization` header in Azure test fixture (elastic#111242) Fixing HistoryStoreTests.testPut() and testStoreWithHideSecrets() (elastic#111246) [ESQL] Remove Named Expcted Types map from testing infrastructure (elastic#111213) Change visibility of createWriter to allow tests from a different package to override it (elastic#111234) [ES|QL] Remove EsqlDataTypes (elastic#111089) Mute org.elasticsearch.repositories.azure.AzureBlobContainerRetriesTests testReadNonexistentBlobThrowsNoSuchFileException elastic#111233 Abstract codec lookup by name, to make CodecService extensible (elastic#111007) Add HTTPS support to `AzureHttpFixture` (elastic#111228) Unmuting tests related to free_context action being processed in ESSingleNodeTestCase (elastic#111224) Upgrade Azure SDK (elastic#111225) Collapse transport versions for 8.14.0 (elastic#111199) Make sure contender uses logs templates (elastic#111183) unmute HistogramPercentileAggregationTests.testBoxplotHistogram (elastic#111223) Refactor Quality Assurance test infrastructure (elastic#111195) Mute org.elasticsearch.xpack.restart.FullClusterRestartIT testDisableFieldNameField {cluster=UPGRADED} elastic#111222 ... # Conflicts: # server/src/main/java/org/elasticsearch/TransportVersions.java
This removes the
NAMED_EXPECTED_TYPESmap from the testing infrastructure. It had become difficult to maintain, and pushed error message text farther way from the code actually testing it. This PR introduces some small functional interfaces to enable scalar function tests to have more fine grained control over their expected error messages.We could do more here, but I think this is a good step in the right direction.