Fix how "all matches" extractor are handled#2568
Conversation
|
Commit 66e7c0b reproduces the problem raised by other users, it seems that when using "all matches" extractor (which should usually produce an array or arrays as result) is not working as expected when computing the corresponding label value. In contrast, the "label preview" seems working as expected resulting in different results between the preview and the actual label value. This seems to happen only if using JS function, in this case the input (array of arrays) is flattened when trying to compute the label value. |
|
Worth noting that the "label preview" is calling |
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
1829377 to
66e7c0b
Compare
|
Found that the issue is happening only when there is one single extractor, and that extractor is "all matches" one. |
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
|
Added some more tests covering first and all matches scenarios , especially when dealing with one single extractor. |
615d685 to
131e5ca
Compare
| FingerprintDAO.deleteById(datasetId); | ||
| Util.evaluateWithCombinationFunction(toCompute, | ||
| (row) -> (String) row[2], | ||
| (row) -> (row[3] instanceof ArrayNode ? flatten((ArrayNode) row[3]) : (JsonNode) row[3]), |
There was a problem hiding this comment.
Don't know why this flatten was introduced, it seems forcing to do the "first match" in case of array of arrays..
There was a problem hiding this comment.
Yes, idk if we have any data that would be affected if we remove it?
131e5ca to
530402e
Compare
horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/DatasetServiceTest.java
Outdated
Show resolved
Hide resolved
530402e to
5cb808f
Compare
| public void testDatasetLabelAsyncSingleWithReduceFunctionArray() { | ||
| withExampleSchemas((schemas) -> { | ||
| int labelReduce = addLabel(schemas[0], "sum", "async (value) => { return value.reduce((a,b) => a+b); }", | ||
| int labelReduce = addLabel(schemas[0], "sum", "async (value) => { return value[0].reduce((a,b) => a+b); }", |
There was a problem hiding this comment.
It seems this test testDatasetLabelAsyncSingleWithReduceFunctionArray and testDatasetLabelSingleWithReduceFunctionArray were created to test exactly that use case when using "All Matches" and reduce function.. but in my opinion the expectation was wrong and did not make sense as it would change the results/expectation a user will have when dealing with such arrays as input.
IMHO the proper way is to consider the input as an array of arrays which is exactly what it would be in all other use cases
There was a problem hiding this comment.
I created testDatasetLabelAsyncSingleWithReduceFunctionArray to test the use of async and based it off what already existed in testDatasetLabelSingleWithReduceFunctionArray so I cannot comment about the use of value[0] vs value.
5cb808f to
c34a943
Compare
| FingerprintDAO.deleteById(datasetId); | ||
| Util.evaluateWithCombinationFunction(toCompute, | ||
| (row) -> (String) row[2], | ||
| (row) -> (row[3] instanceof ArrayNode ? flatten((ArrayNode) row[3]) : (JsonNode) row[3]), |
There was a problem hiding this comment.
Yes, idk if we have any data that would be affected if we remove it?
| public void testDatasetLabelAsyncSingleWithReduceFunctionArray() { | ||
| withExampleSchemas((schemas) -> { | ||
| int labelReduce = addLabel(schemas[0], "sum", "async (value) => { return value.reduce((a,b) => a+b); }", | ||
| int labelReduce = addLabel(schemas[0], "sum", "async (value) => { return value[0].reduce((a,b) => a+b); }", |
horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/DatasetServiceTest.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/DatasetServiceTest.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/DatasetServiceTest.java
Outdated
Show resolved
Hide resolved
willr3
left a comment
There was a problem hiding this comment.
Only made minor comments about readability and the background on the async test I added
c34a943 to
6edcc0c
Compare
Applied your suggestions ✅ |
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
6edcc0c to
8c6579a
Compare
Fixes Issue
The expectation is that "previewing" a label execution and its actual label value computation return the same result, which is not true a the moment when one of the extractor is marked as "all matches".
Changes proposed
flatten((ArrayNode) row[3])Check List (Check all the applicable boxes)