fix bug in …/groupBy/tag and …/groupBy/key endpoints when key/values do not exist in keytables #291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a bug/crash in
…/groupBy/tag
requests triggered when using non-existinggroupByKey
orgroupByValues
are used in a query.To Reproduce
This query is requesting results grouped by the tag
building
and valueDoesNotExist1
(which does not exits in the keytables). The result, however containsbuilding=yes
as thegroupByObject
. When performing a query with two non-existinggroupByValues
(e.g.DoesNotExist1,DoesNotExist2
), the results includes two entries withremainder
asgroupByObject
. When requesting three or more non-existinggroupByValues
, the query crashes and a 500 server error is returned.Similar bugs occur when performing a query with a non-existing tag key as the
groupByKey
.The Problem and Fix
The issue is caused by a mistake in the code, where consecutive negative tag numbers are used as
keyInt
/valuesInt
for OSM tags which do not exist in the keytables, but the hardcoded value-1
is also used to represent theremainder
portion of the result. This is causing the mixup between the valueDoesNotExist1
and the superfluousremainder
entry in the example result above. Further, the negative pseudo-indices started at 0 which is also the index of the most common tag value for the corresponding tag. This is causing the mixup between the valueDoesNotExist2
and the result entry for the valueyes
in the example above. The crashes for any additional non-existing values are caused by a null pointer exception where the (still) non-existing pseudo-indices are attempted to be converted back to strings using the tag translator.This is fixed by starting the negative pseudo-indices at position -2 where confusion with the -1 value for the
remainder
entry is possible and using the input values to resolve the pseudo-indices back to strings.Checklist
I have commented my codeI have written javadoc (required for public methods)I have made corresponding changes to the documentationI have adjusted the examples in the check-ohsome-api script or created an issue in the corresponding repository. More Information here.